Skip to content

Commit 9106e7a

Browse files
committed
tests: re-enable comparisons of the loan_live_at relation
Also, add a descriptive message if the `assert_equal` helper fails its assertions.
1 parent ffd02f8 commit 9106e7a

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed

src/test.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ use std::path::Path;
1717
fn test_facts(all_facts: &AllFacts, algorithms: &[Algorithm]) {
1818
let naive = Output::compute(all_facts, Algorithm::Naive, true);
1919

20-
// Check that the "naive errors" are a subset of the "insensitive
21-
// ones".
20+
// Check that the "naive errors" are a subset of the "insensitive ones".
2221
let insensitive = Output::compute(all_facts, Algorithm::LocationInsensitive, false);
2322
for (naive_point, naive_loans) in &naive.errors {
2423
match insensitive.errors.get(&naive_point) {
@@ -77,18 +76,37 @@ fn test_facts(all_facts: &AllFacts, algorithms: &[Algorithm]) {
7776
for &optimized_algorithm in algorithms {
7877
println!("Algorithm {:?}", optimized_algorithm);
7978
let opt = Output::compute(all_facts, optimized_algorithm, true);
80-
// TMP: until we reach our correctness goals, deactivate some comparisons between variants
81-
// assert_equal(&naive.loan_live_at, &opt.loan_live_at);
82-
assert_equal(&naive.errors, &opt.errors);
83-
assert_equal(&naive.subset_errors, &opt.subset_errors);
84-
assert_equal(&naive.move_errors, &opt.move_errors);
79+
assert_equal(
80+
&naive.loan_live_at,
81+
&opt.loan_live_at,
82+
"naive vs opt loan_live_at",
83+
);
84+
assert_equal(&naive.errors, &opt.errors, "naive vs opt errors");
85+
assert_equal(
86+
&naive.subset_errors,
87+
&opt.subset_errors,
88+
"naive vs opt subset_errors",
89+
);
90+
assert_equal(
91+
&naive.move_errors,
92+
&opt.move_errors,
93+
"naive vs opt move_errors",
94+
);
8595
}
8696

8797
// The hybrid algorithm gets the same errors as the naive version
8898
let opt = Output::compute(all_facts, Algorithm::Hybrid, true);
89-
assert_equal(&naive.errors, &opt.errors);
90-
assert_equal(&naive.subset_errors, &opt.subset_errors);
91-
assert_equal(&naive.move_errors, &opt.move_errors);
99+
assert_equal(&naive.errors, &opt.errors, "naive vs hybrid errors");
100+
assert_equal(
101+
&naive.subset_errors,
102+
&opt.subset_errors,
103+
"naive vs hybrid subset_errors",
104+
);
105+
assert_equal(
106+
&naive.move_errors,
107+
&opt.move_errors,
108+
"naive vs hybrid move_errors",
109+
);
92110
}
93111

94112
fn test_fn(dir_name: &str, fn_name: &str, algorithm: Algorithm) -> Result<(), Box<dyn Error>> {
@@ -155,7 +173,7 @@ fn test_insensitive_errors() -> Result<(), Box<dyn Error>> {
155173
expected.insert(Point::from(24), vec![Loan::from(1)]);
156174
expected.insert(Point::from(50), vec![Loan::from(2)]);
157175

158-
assert_equal(&insensitive.errors, &expected);
176+
assert_equal(&insensitive.errors, &expected, "insensitive errors");
159177
Ok(())
160178
}
161179

src/test_util.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ use crate::intern::InternerTables;
88
use crate::program::parse_from_program;
99

1010
/// Test that two values are equal, with a better error than `assert_eq`
11-
pub fn assert_equal<A>(expected_value: &A, actual_value: &A)
11+
pub fn assert_equal<A>(expected_value: &A, actual_value: &A, message: &str)
1212
where
1313
A: ?Sized + Debug + Eq,
1414
{
1515
// First check that they have the same debug text. This produces a better error.
1616
let expected_text = format!("{:#?}", expected_value);
17-
assert_expected_debug(&expected_text, actual_value);
17+
assert_expected_debug(&expected_text, actual_value, message);
1818

1919
// Then check that they are `eq` too, for good measure.
2020
assert_eq!(expected_value, actual_value);
2121
}
2222

2323
/// Test that the debug output of `actual_value` is as expected. Gives
2424
/// a nice diff if things fail.
25-
pub fn assert_expected_debug<A>(expected_text: &str, actual_value: &A)
25+
pub fn assert_expected_debug<A>(expected_text: &str, actual_value: &A, message: &str)
2626
where
2727
A: ?Sized + Debug,
2828
{
@@ -47,7 +47,7 @@ where
4747
}
4848
}
4949

50-
panic!("debug comparison failed");
50+
panic!("debug comparison failed: {}", message);
5151
}
5252

5353
/// Builder for fact checking assertions
@@ -92,9 +92,13 @@ pub(crate) fn assert_checkers_match(checker_a: &FactChecker, checker_b: &FactChe
9292
}
9393

9494
pub(crate) fn assert_outputs_match(output_a: &Output<LocalFacts>, output_b: &Output<LocalFacts>) {
95-
assert_equal(&output_a.errors, &output_b.errors);
96-
assert_equal(&output_a.subset_errors, &output_b.subset_errors);
97-
assert_equal(&output_a.move_errors, &output_b.move_errors);
95+
assert_equal(&output_a.errors, &output_b.errors, "errors");
96+
assert_equal(
97+
&output_a.subset_errors,
98+
&output_b.subset_errors,
99+
"subset_errors",
100+
);
101+
assert_equal(&output_a.move_errors, &output_b.move_errors, "move_errors");
98102
}
99103

100104
impl FactChecker {

0 commit comments

Comments
 (0)