]> git.lizzy.rs Git - rust.git/commitdiff
docs / rustpkg: Document `rustpkg test` more
authorTim Chevalier <chevalier@alum.wellesley.edu>
Tue, 1 Oct 2013 19:05:57 +0000 (12:05 -0700)
committerTim Chevalier <chevalier@alum.wellesley.edu>
Sun, 6 Oct 2013 03:17:23 +0000 (23:17 -0400)
Talk about `rustpkg test` in the tutorial, and update its usage message.

doc/tutorial-rustpkg.md
src/librustpkg/usage.rs

index 156613cef4d75d3beb0b913378ed894e40ec8900..fb15e0c0cf298e6785e4b6c474f26adf7f4d740c 100644 (file)
@@ -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.
index a8126b49716f81be33ab4abd23e9307a44e8a1d5..4b10451c81363dbee8596fdbc22163184ad03109 100644 (file)
@@ -141,9 +141,9 @@ pub fn unprefer() {
 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");