Skip to content

Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.

app replay: say "1 case is not" and name the cases missing from the case list (#1442)

Hashem Alkhanaizi4ec749c64b60
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b1ddcd63..ce8a5f93 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,9 @@
## Unreleased
+- `app replay`'s note about cases missing from `rust-anything.cases.json` says `1 case is not` and
+ `its` for one case, and names the cases (up to five, then `and N more`), where it said
+ `1 cases are not` and gave nothing to find them by (#1312).
- `gate`'s `coverage` check says `1 of the unit's exports has no recorded case` when a single
export has none, instead of `have`; two or more keep `have` (#1302, #1441 by @MannXo).
- `bridge` on a C function named like a Rust keyword (`mod`, `match`, `where`) writes `r#mod` in
diff --git a/src/app.rs b/src/app.rs
index 5879518d..3b23d4a4 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -4545,7 +4545,7 @@ fn replay_cases(opts: &ReplayOptions) -> Result<ReplayOutcome> {
// What `app record` wrote: which cases were edited since, which fields hold its wildcards.
let meta = CaseMeta::load(&dir)?;
let mut edited: BTreeMap<String, &str> = BTreeMap::new();
- let mut legacy = 0;
+ let mut legacy: Vec<&str> = Vec::new();
for spec in &specs {
match meta.as_ref().and_then(|m| m.cases.get(&spec.name)) {
Some(entry) => {
@@ -4568,7 +4568,7 @@ fn replay_cases(opts: &ReplayOptions) -> Result<ReplayOutcome> {
.values()
.any(|t| has_wildcard_text(&String::from_utf8_lossy(t)))
{
- legacy += 1;
+ legacy.push(&spec.name);
}
}
}
@@ -4579,9 +4579,24 @@ fn replay_cases(opts: &ReplayOptions) -> Result<ReplayOutcome> {
note_once(
"note: legacy recording: it has no rust-anything.cases.json, so edited, skipped or removed cases cannot be told from the recording and `[..]` / `...` lines are read as wildcards. Record again to fix both.",
);
- } else if legacy > 0 {
+ } else if !legacy.is_empty() {
+ let (verb, their) = if legacy.len() == 1 {
+ ("is", "its")
+ } else {
+ ("are", "their")
+ };
+ let mut names = legacy
+ .iter()
+ .take(5)
+ .copied()
+ .collect::<Vec<_>>()
+ .join(", ");
+ if legacy.len() > 5 {
+ names.push_str(&format!(" and {} more", legacy.len() - 5));
+ }
note_once(&format!(
- "note: {legacy} cases are not in rust-anything.cases.json (written by hand or by an older recording); their `[..]` and `...` lines are read as wildcards."
+ "note: {} {verb} not in rust-anything.cases.json (written by hand or by an older recording): {names}; {their} `[..]` and `...` lines are read as wildcards.",
+ crate::report::count(legacy.len(), "case")
));
}
let check_one = |spec: &Spec| {
diff --git a/tests/app.rs b/tests/app.rs
index 7c892bdf..6dcb1658 100644
--- a/tests/app.rs
+++ b/tests/app.rs
@@ -1304,6 +1304,27 @@ fn replay_fails_on_every_planted_difference() {
std::fs::write(case.with_extension("stdout"), &stdout).unwrap();
passes("python3 same.py");
+ // A case added by hand is not in the case list: the note counts it in the singular and names it.
+ let hand = repo.join("rust/app-cases/handwritten");
+ for ext in ["toml", "stderr"] {
+ std::fs::copy(case.with_extension(ext), hand.with_extension(ext)).unwrap();
+ }
+ std::fs::write(
+ hand.with_extension("stdout"),
+ "Loading\n[..]\nDone\npattern: src/[..]/x\n",
+ )
+ .unwrap();
+ let noted = replay("python3 same.py");
+ assert!(noted.starts_with("2/2 cases passed"), "{noted}");
+ assert!(
+ noted.contains("note: 1 case is not in rust-anything.cases.json"),
+ "{noted}"
+ );
+ assert!(noted.contains(": handwritten; its `[..]`"), "{noted}");
+ for ext in ["toml", "stdout", "stderr"] {
+ std::fs::remove_file(hand.with_extension(ext)).unwrap();
+ }
+
// A recording from before the case list is read as it always was, with a note.
std::fs::remove_file(repo.join("rust/app-cases/rust-anything.cases.json")).unwrap();
let legacy = replay("python3 garbage.py");