Skip to content

Commit

Permalink
⚡ Improve test summary formatting (foundry-rs#5731)
Browse files Browse the repository at this point in the history
* chore: add colors to the test result

* chore: remove redundant summary

* chore: remove whitespace

* chore: change skipped test count color to yellow

* refactor: add test summary

* chore: update fixtures

* chore: update

---------

Co-authored-by: Enrique Ortiz <hi@enriqueortiz.dev>
  • Loading branch information
2 people authored and mikelodder7 committed Sep 12, 2023
1 parent e130073 commit 670791d
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 6 deletions.
16 changes: 10 additions & 6 deletions crates/forge/bin/cmd/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,13 @@ impl TestOutcome {
}
println!();
}

let successes = self.successes().count();
println!(
"Encountered a total of {} failing tests, {} tests succeeded",
Paint::red(failures.to_string()),
Paint::green(successes.to_string())
);

std::process::exit(1);
}

Expand All @@ -419,9 +419,9 @@ impl TestOutcome {
format!(
"Test result: {}. {} passed; {} failed; {} skipped; finished in {:.2?}",
result,
self.successes().count(),
failed,
self.skips().count(),
Paint::green(self.successes().count()),
Paint::red(failed),
Paint::yellow(self.skips().count()),
self.duration()
)
}
Expand Down Expand Up @@ -472,8 +472,12 @@ fn format_aggregated_summary(
) -> String {
let total_tests = total_passed + total_failed + total_skipped;
format!(
"Ran {} test suites: {} tests passed, {} failed, {} skipped ({} total tests)",
num_test_suites, total_passed, total_failed, total_skipped, total_tests
" \nRan {} test suites: {} tests passed, {} failed, {} skipped ({} total tests)",
num_test_suites,
Paint::green(total_passed),
Paint::red(total_failed),
Paint::yellow(total_skipped),
total_tests
)
}

Expand Down
1 change: 1 addition & 0 deletions crates/forge/tests/fixtures/can_check_snapshot.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ Compiler run successful!
Running 1 test for src/ATest.t.sol:ATest
[PASS] testExample() (gas: 168)
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 4.42ms

Ran 1 test suites: 1 tests passed, 0 failed, 0 skipped (1 total tests)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ Compiler run successful!
Running 1 test for src/nested/forge-tests/MyTest.t.sol:MyTest
[PASS] testTrue() (gas: 168)
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 2.93ms

Ran 1 test suites: 1 tests passed, 0 failed, 0 skipped (1 total tests)
1 change: 1 addition & 0 deletions crates/forge/tests/fixtures/can_test_repeatedly.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Running 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 26521, ~: 28387)
[PASS] test_Increment() (gas: 28357)
Test result: ok. 2 passed; 0 failed; 0 skipped; finished in 9.42ms

Ran 1 test suites: 2 tests passed, 0 failed, 0 skipped (2 total tests)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ Compiler run successful!
Running 1 test for test/Contract.t.sol:ContractTest
[PASS] test() (gas: 70373)
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 3.21s

Ran 1 test suites: 1 tests passed, 0 failed, 0 skipped (1 total tests)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ Compiler run successful!
Running 1 test for src/Contract.t.sol:ContractTest
[PASS] testExample() (gas: 190)
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.89ms

Ran 1 test suites: 1 tests passed, 0 failed, 0 skipped (1 total tests)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ Compiler run successful!
Running 1 test for src/Contract.t.sol:ContractTest
[PASS] testExample() (gas: 190)
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.89ms

Ran 1 test suites: 1 tests passed, 0 failed, 0 skipped (1 total tests)

0 comments on commit 670791d

Please sign in to comment.