changeset 3:09cdb220b85c

Add crate documentation.
author Lewin Bormann <lbo@spheniscida.de>
date Sun, 03 Sep 2017 11:56:12 +0200
parents c21d8b7b61cb
children 051fea58a3c5
files Cargo.toml README.md src/lib.rs
diffstat 3 files changed, 50 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Cargo.toml	Sat Sep 02 19:52:31 2017 +0200
+++ b/Cargo.toml	Sun Sep 03 11:56:12 2017 +0200
@@ -1,6 +1,6 @@
 [package]
 name = "time-test"
-version = "0.2.0"
+version = "0.2.1"
 authors = ["Lewin Bormann <lewin@lewin-bormann.info>"]
 license = "MIT"
 description = "Measure how long your test cases take with one simple macro."
--- a/README.md	Sat Sep 02 19:52:31 2017 +0200
+++ b/README.md	Sun Sep 03 11:56:12 2017 +0200
@@ -15,7 +15,11 @@
         time_test!();
 
         println!("hello world");
-        assert!(true);
+
+        {
+            time_test!("sub-assert 1");
+            assert!(true);
+        }
         assert_eq!(1, 1);
     }
 }
@@ -33,6 +37,6 @@
      Running target/debug/deps/example-a84426a5de188514
 
 running 1 test
-test example::tests::my_test ... (took PT0.000004178S) ok
+test example::tests::my_test ... (sub-assert 1 took PT0.000002421S) (took PT0.000004178S) ok
 ```
 
--- a/src/lib.rs	Sat Sep 02 19:52:31 2017 +0200
+++ b/src/lib.rs	Sun Sep 03 11:56:12 2017 +0200
@@ -1,8 +1,50 @@
+//! `time_test` is a super simple crate that you can use to easily obtain how long
+//! your tests took to run. Using it is simple (see `example/` for an example use
+//! case):
+//!
+//! ```rust
+//! #[macro_use]
+//! extern crate time_test;
+//!
+//! #[cfg(test)]
+//! mod tests {
+//!     #[test]
+//!     fn my_test() {
+//!         time_test!();
+//!
+//!         println!("hello world");
+//!
+//!         {
+//!             time_test!("sub-assert 1");
+//!             assert!(true);
+//!         }
+//!         assert_eq!(1, 1);
+//!     }
+//! }
+//! ```
+//!
+//! Adding the `time_test!()` macro to the line in your test from which you want to
+//! measure the test duration will result in the duration that the test has taken
+//! being shown in the test result line:
+//!
+//! ```
+//! $ # 1 test thread so that the output is not garbled.
+//! $ cargo test -- --test-threads=1
+//!
+//!     Finished dev [unoptimized + debuginfo] target(s) in 0.78 secs
+//!      Running target/debug/deps/example-a84426a5de188514
+//!
+//! running 1 test
+//! test example::tests::my_test ... (sub-assert 1 took PT0.000002421S) (took PT0.000004178S) ok
+//! ```
+
+
 use std::io::{self, Write};
 
 extern crate time;
 
-/// TestTimer allows to easily time tests. It's recommended to use the time_test!() macro.
+/// TestTimer allows to easily time tests. It's recommended to use the time_test!() macro instead
+/// of invoking this type directly.
 pub struct TestTimer(time::Timespec, String);
 
 impl TestTimer {