Skip to content

Commit beb6c71

Browse files
committed
---
yaml --- r: 82946 b: refs/heads/auto c: d5e5d22 h: refs/heads/master v: v3
1 parent f96f3d9 commit beb6c71

File tree

4 files changed

+73
-23
lines changed

4 files changed

+73
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: d7b2c70a1335b866a26b63bcf13da67328b0cf3c
16+
refs/heads/auto: d5e5d22bdb0299950d38c24d2c1503addf4f898d
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/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/auto/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/auto/src/librustpkg/util.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ use context::{in_target, StopBefore, Link, Assemble, BuildContext};
2727
use package_id::PkgId;
2828
use package_source::PkgSrc;
2929
use workspace::pkg_parent_workspaces;
30-
use path_util::{installed_library_in_workspace, U_RWX, system_library, target_build_dir};
31-
use path_util::default_workspace;
30+
use path_util::{installed_library_in_workspace, U_RWX, rust_path, system_library, target_build_dir};
31+
use messages::error;
32+
use conditions::nonexistent_package::cond;
33+
3234
pub use target::{OutputType, Main, Lib, Bench, Test, JustOne, lib_name_of, lib_crate_filename};
3335
use workcache_support::{digest_file_with_date, digest_only_date};
3436

@@ -430,26 +432,26 @@ impl<'self> Visitor<()> for ViewItemVisitor<'self> {
430432
lib_name.to_str());
431433
// Try to install it
432434
let pkg_id = PkgId::new(lib_name);
433-
// Find all the workspaces in the RUST_PATH that contain this package.
434435
let workspaces = pkg_parent_workspaces(&self.context.context,
435436
&pkg_id);
436-
// Two cases:
437-
// (a) `workspaces` is empty. That means there's no local source
438-
// for this package. In that case, we pass the default workspace
439-
// into `PkgSrc::new`, so that if it exists as a remote repository,
440-
// its sources will be fetched into it.
441-
// (b) `workspaces` is non-empty -- we found a local source for this
442-
// package.
443-
let dest_workspace = if workspaces.is_empty() {
444-
default_workspace()
445-
} else { workspaces[0] };
446-
let pkg_src = PkgSrc::new(dest_workspace,
447-
// Use the rust_path_hack to search for dependencies iff
448-
// we were already using it
449-
self.context.context.use_rust_path_hack,
450-
pkg_id);
437+
let source_workspace = if workspaces.is_empty() {
438+
error(format!("Couldn't find package {} \
439+
in any of the workspaces in the RUST_PATH ({})",
440+
lib_name,
441+
rust_path().map(|s| s.to_str()).connect(":")));
442+
cond.raise((pkg_id.clone(), ~"Dependency not found"))
443+
}
444+
else {
445+
workspaces[0]
446+
};
451447
let (outputs_disc, inputs_disc) =
452-
self.context.install(pkg_src, &JustOne(Path(lib_crate_filename)));
448+
self.context.install(PkgSrc::new(source_workspace.clone(),
449+
// Use the rust_path_hack to search for dependencies iff
450+
// we were already using it
451+
self.context.context.use_rust_path_hack,
452+
pkg_id),
453+
&JustOne(Path(
454+
lib_crate_filename)));
453455
debug2!("Installed {}, returned {:?} dependencies and \
454456
{:?} transitive dependencies",
455457
lib_name, outputs_disc.len(), inputs_disc.len());

0 commit comments

Comments
 (0)