Skip to content

Commit

Permalink
#158 Now we shows 'TEST START' only
Browse files Browse the repository at this point in the history
when we trace some arguments.
  • Loading branch information
la10736 committed Oct 23, 2022
1 parent c326292 commit 8628732
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,8 +5,12 @@

### Changed

- Now we show `TEST START` banner only when trace some argument: See #158 for details.

### Fixed

- Updated test fixtures to 1.64.0 compiler's error messages.

## [0.15.0] 2022/06/27

### Fixed
Expand Down
21 changes: 21 additions & 0 deletions rstest/tests/resources/rstest/dump_debug.rs
Expand Up @@ -22,6 +22,11 @@ fn single_fail(fu32: u32, fstring: String, ftuple: (A, String, i32)) {
assert!(false);
}

#[rstest]
fn no_trace_single_fail(fu32: u32, fstring: String, ftuple: (A, String, i32)) {
assert!(false);
}

#[rstest]
#[case(42, "str", ("ss", -12))]
#[case(24, "trs", ("tt", -24))]
Expand All @@ -30,6 +35,13 @@ fn cases_fail(#[case] u: u32, #[case] s: &str, #[case] t: (&str, i32)) {
assert!(false);
}

#[rstest]
#[case(42, "str", ("ss", -12))]
#[case(24, "trs", ("tt", -24))]
fn no_trace_cases_fail(#[case] u: u32, #[case] s: &str, #[case] t: (&str, i32)) {
assert!(false);
}

#[rstest]
#[trace]
fn matrix_fail(
Expand All @@ -39,3 +51,12 @@ fn matrix_fail(
) {
assert!(false);
}

#[rstest]
fn no_trace_matrix_fail(
#[values(1, 3)] u: u32,
#[values("rst", "srt")] s: &str,
#[values(("SS", -12), ("TT", -24))] t: (&str, i32),
) {
assert!(false);
}
34 changes: 31 additions & 3 deletions rstest/tests/resources/rstest/dump_debug_compact.rs
Expand Up @@ -4,17 +4,28 @@ use rstest::*;
struct A {}

#[fixture]
fn fu32() -> u32 { 42 }
fn fu32() -> u32 {
42
}
#[fixture]
fn fstring() -> String { "A String".to_string() }
fn fstring() -> String {
"A String".to_string()
}
#[fixture]
fn ftuple() -> (A, String, i32) { (A{}, "A String".to_string(), -12) }
fn ftuple() -> (A, String, i32) {
(A {}, "A String".to_string(), -12)
}

#[rstest(::trace)]
fn single_fail(fu32: u32, fstring: String, ftuple: (A, String, i32)) {
assert!(false);
}

#[rstest]
fn no_trace_single_fail(fu32: u32, fstring: String, ftuple: (A, String, i32)) {
assert!(false);
}

#[rstest(u, s, t,
case(42, "str", ("ss", -12)),
case(24, "trs", ("tt", -24))
Expand All @@ -24,6 +35,14 @@ fn cases_fail(u: u32, s: &str, t: (&str, i32)) {
assert!(false);
}

#[rstest(u, s, t,
case(42, "str", ("ss", -12)),
case(24, "trs", ("tt", -24))
)]
fn no_trace_cases_fail(u: u32, s: &str, t: (&str, i32)) {
assert!(false);
}

#[rstest(
u => [1, 2],
s => ["rst", "srt"],
Expand All @@ -33,3 +52,12 @@ fn cases_fail(u: u32, s: &str, t: (&str, i32)) {
fn matrix_fail(u: u32, s: &str, t: (&str, i32)) {
assert!(false);
}

#[rstest(
u => [1, 2],
s => ["rst", "srt"],
t => [("SS", -12), ("TT", -24)]
)]
fn no_trace_matrix_fail(u: u32, s: &str, t: (&str, i32)) {
assert!(false);
}
25 changes: 23 additions & 2 deletions rstest/tests/rstest/mod.rs
Expand Up @@ -166,8 +166,11 @@ mod dump_input_values {

TestResults::new()
.fail("single_fail")
.fail("no_trace_single_fail")
.fail("cases_fail::case_1")
.fail("cases_fail::case_2")
.fail("no_trace_cases_fail::case_1")
.fail("no_trace_cases_fail::case_2")
.fail("matrix_fail::u_1::s_1::t_1")
.fail("matrix_fail::u_1::s_1::t_2")
.fail("matrix_fail::u_1::s_2::t_1")
Expand All @@ -176,6 +179,14 @@ mod dump_input_values {
.fail("matrix_fail::u_2::s_1::t_2")
.fail("matrix_fail::u_1::s_2::t_1")
.fail("matrix_fail::u_2::s_2::t_2")
.fail("no_trace_matrix_fail::u_1::s_1::t_1")
.fail("no_trace_matrix_fail::u_1::s_1::t_2")
.fail("no_trace_matrix_fail::u_1::s_2::t_1")
.fail("no_trace_matrix_fail::u_1::s_2::t_2")
.fail("no_trace_matrix_fail::u_2::s_1::t_1")
.fail("no_trace_matrix_fail::u_2::s_1::t_2")
.fail("no_trace_matrix_fail::u_1::s_2::t_1")
.fail("no_trace_matrix_fail::u_2::s_2::t_2")
.assert(output);

assert_in!(out, "fu32 = 42");
Expand All @@ -197,6 +208,15 @@ mod dump_input_values {
assert_in!(out, "u = 2");
assert_in!(out, r#"s = "srt""#);
assert_in!(out, r#"t = ("TT", -24)"#);

let expected = 11;
for marker in ["TEST START", "TEST ARGUMENTS"] {
let n_found = out.lines().filter(|l| l.contains(marker)).count();
assert_eq!(
n_found, expected,
"Should contain {expected} '{marker}' but found {n_found}. [Should not enclose output if no trace]"
);
}
}

#[rstest]
Expand Down Expand Up @@ -259,10 +279,11 @@ mod dump_input_values {
.take_while(|l| !l.contains("TEST START"))
.collect::<Vec<_>>();

let expected = 4;
assert_eq!(
4,
expected,
lines.len(),
"Not contains 3 lines but {}: '{}'",
"Not contains {expected} lines but {}: '{}'",
lines.len(),
lines.join("\n")
);
Expand Down
2 changes: 1 addition & 1 deletion rstest_macros/src/render/mod.rs
Expand Up @@ -265,7 +265,6 @@ fn single_test_case<'a>(
#test_impl
#inject
#trace_args
println!("{:-^40}", " TEST START ");
#execute
}
}
Expand All @@ -288,6 +287,7 @@ fn trace_arguments<'a>(
Some(quote! {
println!("{:-^40}", " TEST ARGUMENTS ");
#(#statements)*
println!("{:-^40}", " TEST START ");
})
} else {
None
Expand Down
2 changes: 0 additions & 2 deletions rstest_reuse/README.md
Expand Up @@ -65,11 +65,9 @@ test it_works::case_2 ... ok
test it_fail::case_2 ... FAILED
failures:
---- it_fail::case_1 stdout ----
-------------- TEST START --------------
thread 'it_fail::case_1' panicked at 'assertion failed: a != b', src/main.rs:34:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
---- it_fail::case_2 stdout ----
-------------- TEST START --------------
thread 'it_fail::case_2' panicked at 'assertion failed: a != b', src/main.rs:34:5
failures:
it_fail::case_1
Expand Down
2 changes: 0 additions & 2 deletions rstest_reuse/src/lib.rs
Expand Up @@ -65,12 +65,10 @@
//! failures:
//!
//! ---- it_fail::case_1 stdout ----
//! -------------- TEST START --------------
//! thread 'it_fail::case_1' panicked at 'assertion failed: a != b', src/main.rs:34:5
//! note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
//!
//! ---- it_fail::case_2 stdout ----
//! -------------- TEST START --------------
//! thread 'it_fail::case_2' panicked at 'assertion failed: a != b', src/main.rs:34:5
//!
//!
Expand Down

0 comments on commit 8628732

Please sign in to comment.