Skip to content

Commit 19a9c2a

Browse files
committed
Fix the tests on Rust nightly.
A recent change in Rust caused minor formatting changes when displaying fully qualified enum variants. Namely: * The spaces around the `::` which were previously present were removed. * The space between `vec!` and the vector content was removed. This breaks tests which assert descriptions, match explanations, and failure messages. These rely on the `Debug` representation of actual and expected values. This fixes the tests so that they pass again in nightly while continuing to pass in the other versions. It removes text from the assertion where it is not crucial to what is being tested. In cases where it is crucial, either the critical part is extracted to a variable which is set according to the Rust version, or the test itself is duplicated and adjusted according to the Rust version.
1 parent 281b6b8 commit 19a9c2a

File tree

5 files changed

+45
-20
lines changed

5 files changed

+45
-20
lines changed

googletest/src/matchers/each_matcher.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ mod tests {
238238
result,
239239
err(displays_as(contains_substring(indoc!(
240240
"
241-
Value of: vec![vec! [1, 2], vec! [1]]
242241
Expected: only contains elements that only contains elements that is equal to 1
243242
Actual: [[1, 2], [1]],
244243
whose element #0 is [1, 2], whose element #1 is 2, which isn't equal to 1"

googletest/tests/elements_are_matcher_test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ fn elements_are_produces_correct_failure_message_nested() -> Result<()> {
8282
result,
8383
err(displays_as(contains_substring(indoc!(
8484
"
85-
Value of: vec![vec! [0, 1], vec! [1, 2]]
8685
Expected: has elements:
8786
0. has elements:
8887
0. is equal to 1

googletest/tests/matches_pattern_test.rs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ fn has_meaningful_assertion_failure_message_when_wrong_enum_variant_is_used() ->
202202
verify_that!(
203203
result,
204204
err(displays_as(contains_substring(indoc! {"
205-
Value of: actual
206-
Expected: is AnEnum :: B which has field `0`, which is equal to 123
207205
Actual: A(123),
208206
which has the wrong enum variant `A`
209207
"
@@ -411,7 +409,7 @@ fn generates_correct_failure_output_when_enum_variant_without_field_is_not_match
411409

412410
let result = verify_that!(actual, matches_pattern!(AnEnum::A));
413411

414-
verify_that!(result, err(displays_as(contains_substring("is not AnEnum :: A"))))
412+
verify_that!(result, err(displays_as(contains_substring(format!("is not {ANENUM_A_REPR}")))))
415413
}
416414

417415
#[test]
@@ -424,7 +422,7 @@ fn generates_correct_failure_output_when_enum_variant_without_field_is_matched()
424422

425423
let result = verify_that!(actual, not(matches_pattern!(AnEnum::A)));
426424

427-
verify_that!(result, err(displays_as(contains_substring("is AnEnum :: A"))))
425+
verify_that!(result, err(displays_as(contains_substring(format!("is {ANENUM_A_REPR}")))))
428426
}
429427

430428
#[test]
@@ -451,6 +449,11 @@ fn does_not_match_wrong_enum_value() -> Result<()> {
451449
verify_that!(actual, not(matches_pattern!(AnEnum::A(eq(123)))))
452450
}
453451

452+
#[rustversion::all(not(nightly), before(1.76))]
453+
const ANENUM_A_REPR: &str = "AnEnum :: A";
454+
#[rustversion::any(nightly, since(1.76))]
455+
const ANENUM_A_REPR: &str = "AnEnum::A";
456+
454457
#[test]
455458
fn includes_enum_variant_in_description_with_field() -> Result<()> {
456459
#[derive(Debug)]
@@ -463,7 +466,9 @@ fn includes_enum_variant_in_description_with_field() -> Result<()> {
463466

464467
verify_that!(
465468
result,
466-
err(displays_as(contains_substring("Expected: is AnEnum :: A which has field `0`")))
469+
err(displays_as(contains_substring(format!(
470+
"Expected: is {ANENUM_A_REPR} which has field `0`"
471+
))))
467472
)
468473
}
469474

@@ -479,9 +484,9 @@ fn includes_enum_variant_in_negative_description_with_field() -> Result<()> {
479484

480485
verify_that!(
481486
result,
482-
err(displays_as(contains_substring(
483-
"Expected: is not AnEnum :: A which has field `0`, which is equal to"
484-
)))
487+
err(displays_as(contains_substring(format!(
488+
"Expected: is not {ANENUM_A_REPR} which has field `0`, which is equal to"
489+
))))
485490
)
486491
}
487492

@@ -497,9 +502,9 @@ fn includes_enum_variant_in_description_with_two_fields() -> Result<()> {
497502

498503
verify_that!(
499504
result,
500-
err(displays_as(contains_substring(
501-
"Expected: is AnEnum :: A which has all the following properties"
502-
)))
505+
err(displays_as(contains_substring(format!(
506+
"Expected: is {ANENUM_A_REPR} which has all the following properties"
507+
))))
503508
)
504509
}
505510

@@ -515,9 +520,9 @@ fn includes_enum_variant_in_description_with_three_fields() -> Result<()> {
515520

516521
verify_that!(
517522
result,
518-
err(displays_as(contains_substring(
519-
"Expected: is AnEnum :: A which has all the following properties"
520-
)))
523+
err(displays_as(contains_substring(format!(
524+
"Expected: is {ANENUM_A_REPR} which has all the following properties"
525+
))))
521526
)
522527
}
523528

@@ -533,7 +538,9 @@ fn includes_enum_variant_in_description_with_named_field() -> Result<()> {
533538

534539
verify_that!(
535540
result,
536-
err(displays_as(contains_substring("Expected: is AnEnum :: A which has field `field`")))
541+
err(displays_as(contains_substring(format!(
542+
"Expected: is {ANENUM_A_REPR} which has field `field`"
543+
))))
537544
)
538545
}
539546

@@ -552,9 +559,9 @@ fn includes_enum_variant_in_description_with_two_named_fields() -> Result<()> {
552559

553560
verify_that!(
554561
result,
555-
err(displays_as(contains_substring(
556-
"Expected: is AnEnum :: A which has all the following properties"
557-
)))
562+
err(displays_as(contains_substring(format!(
563+
"Expected: is {ANENUM_A_REPR} which has all the following properties"
564+
))))
558565
)
559566
}
560567

integration_tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ googletest = { path = "../googletest", version = "0.10.0", features = ["anyhow"]
3232
anyhow = "1"
3333
indoc = "2"
3434
rstest = "0.18"
35+
rustversion = "1.0.14"
3536
tokio = { version = "1.34", features = ["time", "macros", "rt"] }
3637

3738
[[bin]]

integration_tests/src/integration_tests.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ mod tests {
474474
}
475475

476476
#[test]
477+
#[rustversion::all(not(nightly), before(1.76))]
477478
fn verify_pred_should_show_correct_qualified_function_name_in_test_failure_output() -> Result<()>
478479
{
479480
let output = run_external_process_in_tests_directory(
@@ -490,6 +491,24 @@ mod tests {
490491
)
491492
}
492493

494+
#[test]
495+
#[rustversion::any(nightly, since(1.76))]
496+
fn verify_pred_should_show_correct_qualified_function_name_in_test_failure_output() -> Result<()>
497+
{
498+
let output = run_external_process_in_tests_directory(
499+
"verify_predicate_with_failure_as_method_in_submodule",
500+
)?;
501+
502+
verify_that!(
503+
output,
504+
contains_substring(indoc! {"
505+
a_submodule::A_STRUCT_IN_SUBMODULE.eq_predicate_as_method(a, b) was false with
506+
a = 1,
507+
b = 2
508+
"})
509+
)
510+
}
511+
493512
#[test]
494513
fn fail_macro_causes_test_failure() -> Result<()> {
495514
let status = run_external_process("failure_due_to_fail_macro").status()?;

0 commit comments

Comments
 (0)