Skip to content

Commit 556fda0

Browse files
tekknolagik0kubun
authored andcommitted
Use expect-test for HIR tests
This makes it easier to update cascading test failures while still making output reviewable in the PR.
1 parent d9720ea commit 556fda0

File tree

5 files changed

+121
-112
lines changed

5 files changed

+121
-112
lines changed

doc/zjit.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ You can also run a single test case by specifying the function name:
5050
make zjit-test ZJIT_TESTS=test_putobject
5151
```
5252

53+
If you expect that your changes cause tests to fail and they do, you can have
54+
`expect-test` fix the expected value for you by putting `UPDATE_EXPECT=1`
55+
before your test command, like so:
56+
57+
```
58+
UPDATE_EXPECT=1 make zjit-test ZJIT_TESTS=test_putobject
59+
```
60+
61+
Test changes will be reviewed alongside code changes.
62+
5363
<details>
5464

5565
<summary>Setting up zjit-test</summary>

zjit/Cargo.lock

Lines changed: 24 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zjit/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ lto = "thin"
2525
# written rationale. Optional For development and testing purposes
2626
capstone = { version = "0.13.0", optional = true }
2727

28+
[dev-dependencies]
29+
expect-test = "1.5.1"
30+
2831
# NOTE: Development builds select a set of these via configure.ac
2932
# For debugging, `make V=1` shows exact cargo invocation.
3033
[features]

zjit/src/cruby.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,34 +1001,6 @@ pub mod test_utils {
10011001
unsafe { rb_iseqw_to_iseq(wrapped_iseq) }
10021002
}
10031003

1004-
/// Return a diff-like format describing the differences between the two strings. Not very
1005-
/// advanced (does not try to do any anchoring); best for subtle line-local differences.
1006-
pub fn diff_text(expected: &str, actual: &str) -> String {
1007-
let expected_lines: Vec<&str> = expected.lines().collect();
1008-
let actual_lines: Vec<&str> = actual.lines().collect();
1009-
let mut result: String = "Differences found (-expected, +actual):\n---\n".into();
1010-
let max_lines = expected_lines.len().max(actual_lines.len());
1011-
for i in 0..max_lines {
1012-
match (expected_lines.get(i), actual_lines.get(i)) {
1013-
(Some(exp), Some(act)) if exp == act => {
1014-
result.push_str(format!(" {exp}\n").as_ref());
1015-
}
1016-
(Some(exp), Some(act)) => {
1017-
result.push_str(format!("-{exp}\n+{act}\n").as_ref());
1018-
}
1019-
(Some(exp), None) => {
1020-
result.push_str(format!("-{exp}\n").as_ref());
1021-
}
1022-
(None, Some(act)) => {
1023-
result.push_str(format!("+{act}\n").as_ref());
1024-
}
1025-
(None, None) => unreachable!(),
1026-
}
1027-
}
1028-
result.push_str("---\n");
1029-
result
1030-
}
1031-
10321004
/// Remove the minimum indent from every line, skipping the first and last lines if `trim_lines`.
10331005
pub fn unindent(string: &str, trim_lines: bool) -> String {
10341006
// Break up a string into multiple lines

0 commit comments

Comments
 (0)