Skip to content

Commit

Permalink
docs / rustpkg: Document rustpkg test more
Browse files Browse the repository at this point in the history
Talk about `rustpkg test` in the tutorial, and update its usage message.
  • Loading branch information
catamorphism committed Oct 6, 2013
1 parent acf9783 commit 8ba148b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
48 changes: 48 additions & 0 deletions doc/tutorial-rustpkg.md
Expand Up @@ -206,6 +206,54 @@ note: Installed package github.com/YOUR_USERNAME/hello-0.1 to /home/yourusername
That's it!
# Testing your Package
Testing your package is simple as well. First, let's change `src/hello/lib.rs` to contain
a function that can be sensibly tested:
~~~
#[desc = "A Rust package for determining whether unsigned integers are even."];
#[license = "MIT"];
pub fn is_even(i: uint) -> bool {
i % 2 == 0
}
~~~
Once you've edited `lib.rs`, you can create a second crate file, `src/hello/test.rs`,
to put tests in:
~~~
#[license = "MIT"];
extern mod hello;
use hello::is_even;
#[test]
fn test_is_even() {
assert!(is_even(0));
assert!(!is_even(1));
assert!(is_even(2));
}
~~~
Note that you have to import the crate you just created in `lib.rs` with the
`extern mod hello` directive. That's because you're putting the tests in a different
crate from the main library that you created.
Now, you can use the `rustpkg test` command to build this test crate (and anything else
it depends on) and run the tests, all in one step:
~~~ {.notrust}
$ rustpkg test hello
WARNING: The Rust package manager is experimental and may be unstable
note: Installed package hello-0.1 to /Users/tjc/.rust
running 1 test
test test_is_even ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
~~~
# More resources
There's a lot more going on with `rustpkg`, this is just to get you started.
Expand Down
6 changes: 3 additions & 3 deletions src/librustpkg/usage.rs
Expand Up @@ -141,9 +141,9 @@ information.");
pub fn test() {
io::println("rustpkg [options..] test
Build all targets described in the package script in the current directory
with the test flag. The test bootstraps will be run afterwards and the output
and exit code will be redirected.
Build all test crates in the current directory with the test flag.
Then, run all the resulting test executables, redirecting the output
and exit code.
Options:
-c, --cfg Pass a cfg flag to the package script");
Expand Down

5 comments on commit 8ba148b

@bors
Copy link
Contributor

@bors bors commented on 8ba148b Oct 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at catamorphism@8ba148b

@bors
Copy link
Contributor

@bors bors commented on 8ba148b Oct 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging catamorphism/rust/rustpkg-test-docs-need-to-submit = 8ba148b into auto

@bors
Copy link
Contributor

@bors bors commented on 8ba148b Oct 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catamorphism/rust/rustpkg-test-docs-need-to-submit = 8ba148b merged ok, testing candidate = d5e5d22

@bors
Copy link
Contributor

@bors bors commented on 8ba148b Oct 6, 2013

@bors
Copy link
Contributor

@bors bors commented on 8ba148b Oct 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = d5e5d22

Please sign in to comment.