Skip to content

Commit

Permalink
Move some printing logic into Display impls.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinlatimer committed May 2, 2015
1 parent 7f76199 commit d25c51e
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/lib.rs
Expand Up @@ -25,6 +25,17 @@ pub trait Runnable {
fn run(&self) -> TestResult;
}

struct TestTimings {
time_s: f64,
runs_per_s: f64
}

impl fmt::Display for TestTimings {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Finished in {}s, {} runs/s.", self.time_s, self.runs_per_s)
}
}

struct TestStats {
runs: usize,
failures: usize,
Expand Down Expand Up @@ -61,6 +72,12 @@ impl TestStats {
}
}

impl fmt::Display for TestStats {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} runs, {} failures, {} errors, {} skips.", self.runs, self.failures, self.errors, self.skips)
}
}

pub struct TestRunner;

impl TestRunner {
Expand Down Expand Up @@ -96,17 +113,19 @@ impl TestRunner {
let end_time = time::precise_time_ns();
let time_ms = end_time.wrapping_sub(start_time) as i64 / 1000000;
let time_s = time_ms as f64 / 1000f64;
let runs_f = results.len() as f64;
let runs_per_s = runs_f / time_s;
let timings = TestTimings {
time_s: time_s,
runs_per_s: results.len() as f64 / time_s
};

println!("\n\nFinished in {}s, {} runs/s.", time_s, runs_per_s);
println!("\n\n{}", timings);

let stats = results
.iter()
.map(TestStats::create)
.fold(TestStats::new(), TestStats::combine);

println!("\n{} runs, {} failures, {} errors, {} skips.", stats.runs, stats.failures, stats.errors, stats.skips);
println!("\n{}", stats);

if stats.skips > 0 {
println!("\nYou have skipped tests. Run with --verbose for details.");
Expand Down

0 comments on commit d25c51e

Please sign in to comment.