Skip to content

Commit 9abaa3a

Browse files
committed
---
yaml --- r: 95230 b: refs/heads/dist-snap c: 4db6eba h: refs/heads/master v: v3
1 parent dc0e294 commit 9abaa3a

File tree

8 files changed

+398
-231
lines changed

8 files changed

+398
-231
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: d7b2c70a1335b866a26b63bcf13da67328b0cf3c
9+
refs/heads/dist-snap: 4db6eba3a24778bd64260e5fcae24a41575c4d7b
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/doc/tutorial-rustpkg.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,54 @@ note: Installed package github.com/YOUR_USERNAME/hello-0.1 to /home/yourusername
206206

207207
That's it!
208208

209+
# Testing your Package
210+
211+
Testing your package is simple as well. First, let's change `src/hello/lib.rs` to contain
212+
a function that can be sensibly tested:
213+
214+
~~~
215+
#[desc = "A Rust package for determining whether unsigned integers are even."];
216+
#[license = "MIT"];
217+
218+
pub fn is_even(i: uint) -> bool {
219+
i % 2 == 0
220+
}
221+
~~~
222+
223+
Once you've edited `lib.rs`, you can create a second crate file, `src/hello/test.rs`,
224+
to put tests in:
225+
226+
~~~
227+
#[license = "MIT"];
228+
extern mod hello;
229+
use hello::is_even;
230+
231+
#[test]
232+
fn test_is_even() {
233+
assert!(is_even(0));
234+
assert!(!is_even(1));
235+
assert!(is_even(2));
236+
}
237+
~~~
238+
239+
Note that you have to import the crate you just created in `lib.rs` with the
240+
`extern mod hello` directive. That's because you're putting the tests in a different
241+
crate from the main library that you created.
242+
243+
Now, you can use the `rustpkg test` command to build this test crate (and anything else
244+
it depends on) and run the tests, all in one step:
245+
246+
~~~ {.notrust}
247+
$ rustpkg test hello
248+
WARNING: The Rust package manager is experimental and may be unstable
249+
note: Installed package hello-0.1 to /Users/tjc/.rust
250+
251+
running 1 test
252+
test test_is_even ... ok
253+
254+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
255+
~~~
256+
209257
# More resources
210258

211259
There's a lot more going on with `rustpkg`, this is just to get you started.

branches/dist-snap/src/librustc/middle/trans/base.rs

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use middle::trans::glue;
5454
use middle::trans::inline;
5555
use middle::trans::llrepr::LlvmRepr;
5656
use middle::trans::machine;
57-
use middle::trans::machine::{llalign_of_min, llsize_of};
57+
use middle::trans::machine::{llalign_of_min, llsize_of, llsize_of_alloc};
5858
use middle::trans::meth;
5959
use middle::trans::monomorphize;
6060
use middle::trans::tvec;
@@ -2911,9 +2911,10 @@ pub fn decl_gc_metadata(ccx: &mut CrateContext, llmod_id: &str) {
29112911
}
29122912
}
29132913

2914-
pub fn create_module_map(ccx: &mut CrateContext) -> ValueRef {
2915-
let elttype = Type::struct_([ccx.int_type, ccx.int_type], false);
2916-
let maptype = Type::array(&elttype, (ccx.module_data.len() + 1) as u64);
2914+
pub fn create_module_map(ccx: &mut CrateContext) -> (ValueRef, uint, uint) {
2915+
let str_slice_type = Type::struct_([Type::i8p(), ccx.int_type], false);
2916+
let elttype = Type::struct_([str_slice_type, ccx.int_type], false);
2917+
let maptype = Type::array(&elttype, ccx.module_data.len() as u64);
29172918
let map = do "_rust_mod_map".with_c_str |buf| {
29182919
unsafe {
29192920
llvm::LLVMAddGlobal(ccx.llmod, maptype.to_ref(), buf)
@@ -2931,19 +2932,18 @@ pub fn create_module_map(ccx: &mut CrateContext) -> ValueRef {
29312932
}
29322933

29332934
for key in keys.iter() {
2934-
let val = *ccx.module_data.find_equiv(key).unwrap();
2935-
let s_const = C_cstr(ccx, *key);
2936-
let s_ptr = p2i(ccx, s_const);
2937-
let v_ptr = p2i(ccx, val);
2938-
let elt = C_struct([s_ptr, v_ptr]);
2939-
elts.push(elt);
2940-
}
2941-
let term = C_struct([C_int(ccx, 0), C_int(ccx, 0)]);
2942-
elts.push(term);
2935+
let val = *ccx.module_data.find_equiv(key).unwrap();
2936+
let v_ptr = p2i(ccx, val);
2937+
let elt = C_struct([
2938+
C_estr_slice(ccx, *key),
2939+
v_ptr
2940+
]);
2941+
elts.push(elt);
2942+
}
29432943
unsafe {
29442944
llvm::LLVMSetInitializer(map, C_array(elttype, elts));
29452945
}
2946-
return map;
2946+
return (map, keys.len(), llsize_of_alloc(ccx, elttype));
29472947
}
29482948

29492949

@@ -2959,9 +2959,10 @@ pub fn decl_crate_map(sess: session::Session, mapmeta: LinkMeta,
29592959
} else {
29602960
~"toplevel"
29612961
};
2962+
29622963
let sym_name = ~"_rust_crate_map_" + mapname;
2963-
let arrtype = Type::array(&int_type, n_subcrates as u64);
2964-
let maptype = Type::struct_([Type::i32(), int_type, arrtype], false);
2964+
let slicetype = Type::struct_([int_type, int_type], false);
2965+
let maptype = Type::struct_([Type::i32(), slicetype, slicetype], false);
29652966
let map = do sym_name.with_c_str |buf| {
29662967
unsafe {
29672968
llvm::LLVMAddGlobal(llmod, maptype.to_ref(), buf)
@@ -2996,14 +2997,29 @@ pub fn fill_crate_map(ccx: &mut CrateContext, map: ValueRef) {
29962997
subcrates.push(p2i(ccx, cr));
29972998
i += 1;
29982999
}
2999-
subcrates.push(C_int(ccx, 0));
3000-
30013000
unsafe {
3002-
let mod_map = create_module_map(ccx);
3001+
let maptype = Type::array(&ccx.int_type, subcrates.len() as u64);
3002+
let vec_elements = do "_crate_map_child_vectors".with_c_str |buf| {
3003+
llvm::LLVMAddGlobal(ccx.llmod, maptype.to_ref(), buf)
3004+
};
3005+
lib::llvm::SetLinkage(vec_elements, lib::llvm::InternalLinkage);
3006+
3007+
llvm::LLVMSetInitializer(vec_elements, C_array(ccx.int_type, subcrates));
3008+
let (mod_map, mod_count, mod_struct_size) = create_module_map(ccx);
3009+
30033010
llvm::LLVMSetInitializer(map, C_struct(
3004-
[C_i32(1),
3005-
p2i(ccx, mod_map),
3006-
C_array(ccx.int_type, subcrates)]));
3011+
[C_i32(2),
3012+
C_struct([
3013+
p2i(ccx, mod_map),
3014+
// byte size of the module map array, an entry consists of two integers
3015+
C_int(ccx, ((mod_count * mod_struct_size) as int))
3016+
]),
3017+
C_struct([
3018+
p2i(ccx, vec_elements),
3019+
// byte size of the subcrates array, an entry consists of an integer
3020+
C_int(ccx, (subcrates.len() * llsize_of_alloc(ccx, ccx.int_type)) as int)
3021+
])
3022+
]));
30073023
}
30083024
}
30093025

branches/dist-snap/src/librustc/middle/typeck/coherence.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ impl visit::Visitor<()> for PrivilegedScopeVisitor {
216216
if trait_def_id.crate != LOCAL_CRATE {
217217
let session = self.cc.crate_context.tcx.sess;
218218
session.span_err(item.span,
219-
"cannot provide an extension implementation \
220-
for a trait not defined in this crate");
219+
"cannot provide an extension implementation \
220+
where both trait and type are not defined in this crate");
221221
}
222222
}
223223

branches/dist-snap/src/librustpkg/usage.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ information.");
141141
pub fn test() {
142142
io::println("rustpkg [options..] test
143143
144-
Build all targets described in the package script in the current directory
145-
with the test flag. The test bootstraps will be run afterwards and the output
146-
and exit code will be redirected.
144+
Build all test crates in the current directory with the test flag.
145+
Then, run all the resulting test executables, redirecting the output
146+
and exit code.
147147
148148
Options:
149149
-c, --cfg Pass a cfg flag to the package script");

branches/dist-snap/src/libstd/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/*!
1515
*
1616
* Traits for the built-in operators. Implementing these traits allows you to get
17-
* an effect similar to oveloading operators.
17+
* an effect similar to overloading operators.
1818
*
1919
* The values for the right hand side of an operator are automatically
2020
* borrowed, so `a + b` is sugar for `a.add(&b)`.

0 commit comments

Comments
 (0)