Skip to content

Commit 975471c

Browse files
committed
Fall back to diff if delta isn't installed
1 parent acd6ce2 commit 975471c

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,20 +2388,26 @@ impl<'test> TestCx<'test> {
23882388
self.fatal("failed to run tidy");
23892389
}
23902390

2391-
let diff_pid = Command::new("diff")
2392-
.args(&["-u", "-r"])
2393-
.args(&[out_dir, &compare_dir])
2394-
.stdout(Stdio::piped())
2395-
.spawn()
2396-
.expect("failed to run `diff`");
2397-
let status = Command::new("delta")
2398-
.arg("--paging=never")
2399-
.stdin(diff_pid.stdout.unwrap())
2400-
.spawn()
2401-
.expect("delta not found")
2402-
.wait()
2403-
.unwrap();
2404-
assert!(status.success());
2391+
let has_delta = Command::new("delta")
2392+
.arg("--version")
2393+
.status()
2394+
.map_or(false, |status| status.success());
2395+
let mut diff = Command::new("diff");
2396+
diff.args(&["-u", "-r"]).args(&[out_dir, &compare_dir]);
2397+
2398+
if has_delta {
2399+
let diff_pid = diff.stdout(Stdio::piped()).spawn().expect("failed to run `diff`");
2400+
let status = Command::new("delta")
2401+
.arg("--paging=never")
2402+
.stdin(diff_pid.stdout.unwrap())
2403+
.status()
2404+
.unwrap();
2405+
assert!(status.success());
2406+
} else {
2407+
eprintln!("warning: `delta` not installed, falling back to `diff --color`");
2408+
diff.arg("--color").spawn().expect("failed to run `diff`").wait().unwrap();
2409+
assert!(status.success() || status.code() == Some(1));
2410+
}
24052411
}
24062412

24072413
fn get_lines<P: AsRef<Path>>(

0 commit comments

Comments
 (0)