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.

fix: include crate paths in guidance (#1487)

Badri Vishal Pandey62cb8d2dc04a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0f888664..f18ea469 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,10 @@
- A missing argument under `--json` names every missing argument in the error's message, as in
`the following required arguments were not provided: <REPO>, <UNIT>`, where it stopped at the
colon. Other usage errors keep their message (#1459, #1493 by @P-r-e-m-i-u-m).
+- `enable`'s refusal when recorded cases differ names the crate in the command it points at
+ (`` `rust-anything diff <crate>` shows them ``), and `gate`'s fix for a failed `ported` check
+ names the crate's `src/port.rs` and `rust-anything gate <crate>`. Before, both left the crate
+ out, so the command failed when run from the repository root (#1485, #1487 by @badrisatyam1-ctrl).
- `analyze` maps `laravel/framework` to Laravel Rust (`laravel-rust`, beta), with fit `partial`.
Units that import `Illuminate\...` are no longer Blocked with "`laravel/framework` has no Rust
equivalent". `analyze --whole-app` on an app whose `composer.json` requires `laravel/framework`
diff --git a/src/gate.rs b/src/gate.rs
index bee04ff1..76072eed 100644
--- a/src/gate.rs
+++ b/src/gate.rs
@@ -94,10 +94,9 @@ fn fix_for(check: &Check, crate_dir: &Path) -> Option<String> {
}
"cargo test" => format!("cargo test {manifest}"),
"unsafe" => "add a `// SAFETY:` comment above each listed `unsafe`, or remove it".into(),
- "ported" => {
- "port the functions still stubbed in src/port.rs, then `rust-anything gate` again"
- .into()
- }
+ "ported" => format!(
+ "port the functions still stubbed in {c}/src/port.rs, then `rust-anything gate {q}` again"
+ ),
"size" => "use the crates `rust-anything analyze` lists and fold repeated code".into(),
"literals" => "compute these values the way the original does; a constant the original \
takes from a library can stay with a `// recorded-literal: <reason>` \
@@ -3415,6 +3414,12 @@ mod tests {
fix_for(&check("behavior", "no recorded cases: run"), dir).as_deref(),
Some("rust-anything record port")
);
+ assert_eq!(
+ fix_for(&check("ported", "stub"), dir).as_deref(),
+ Some(
+ "port the functions still stubbed in port/src/port.rs, then `rust-anything gate port` again"
+ )
+ );
assert!(fix_for(&check("fmt", ""), dir).is_some_and(|f| f.starts_with("cargo fmt")));
assert!(
fix_for(
diff --git a/src/main.rs b/src/main.rs
index 99fb6514..174377be 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2084,10 +2084,11 @@ fn run() -> Result<ExitCode> {
let d = harness::diff(&diff_opts)?;
if d.failed > 0 || d.batches.iter().any(|b| !b.ok()) || !d.missing.is_empty() {
anyhow::bail!(
- "{}/{} recorded cases match{}; switch it on once they all do (`rust-anything diff` shows them), or pass --partial / --only / --force",
+ "{}/{} recorded cases match{}; switch it on once they all do (`rust-anything diff {}` shows them), or pass --partial / --only / --force",
d.passed,
d.total,
- rust_anything::batch_check::failure_summary_suffix(&d.batches)
+ rust_anything::batch_check::failure_summary_suffix(&d.batches),
+ rust_anything::app::cli_path(&crate_dir)
);
}
rust_anything::enable::guard_cases(
diff --git a/tests/switch.rs b/tests/switch.rs
index fa4d77cb..1206f963 100644
--- a/tests/switch.rs
+++ b/tests/switch.rs
@@ -1083,6 +1083,32 @@ fn enable_cli(crate_dir: &Path, extra: &[&str]) -> std::process::Output {
.unwrap()
}
+#[test]
+fn enable_names_the_crate_in_the_diff_it_points_at() {
+ if common::python().is_none() {
+ return;
+ }
+ let (root, crate_dir) = recorded_unit("enable-diff-hint");
+ let original = std::fs::read(root.join("fuzzy.py")).unwrap();
+
+ let out = enable_cli(&crate_dir, &[]);
+ let stderr = String::from_utf8_lossy(&out.stderr).into_owned();
+ assert!(!out.status.success(), "{stderr}");
+ assert!(
+ stderr.contains("recorded cases match; switch it on once they all do"),
+ "{stderr}"
+ );
+ assert!(
+ stderr.contains(&format!(
+ "(`rust-anything diff {}` shows them)",
+ rust_anything::app::cli_path(&crate_dir)
+ )),
+ "{stderr}"
+ );
+ assert_eq!(std::fs::read(root.join("fuzzy.py")).unwrap(), original);
+ std::fs::remove_dir_all(root).unwrap();
+}
+
#[test]
fn enable_checks_the_recording_before_it_edits_a_source_file() {
if common::python().is_none() {