Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 36 additions & 42 deletions tests/by-util/test_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,59 +595,53 @@ fn directory_name_matching() {
// Among names differing only by case, the one that is the same on both sides
// is the counterpart, whichever sorts first.
#[test]
fn ignore_file_name_case_prefers_exact_match() -> Result<(), Box<dyn std::error::Error>> {
let tmp_dir = tempdir()?;
let dir = tmp_dir.path();
std::fs::create_dir(dir.join("one"))?;
std::fs::create_dir(dir.join("two"))?;
std::fs::write(dir.join("one/f"), "same\n")?;
std::fs::write(dir.join("two/f"), "same\n")?;
std::fs::write(dir.join("two/F"), "other\n")?;
if std::fs::read_dir(dir.join("two"))?.count() != 2 {
fn ignore_file_name_case_prefers_exact_match() {
let (at, ts) = at_and_ts!();
at.mkdir("one");
at.mkdir("two");
at.write("one/f", "same\n");
at.write("two/f", "same\n");
at.write("two/F", "other\n");
if std::fs::read_dir(at.plus("two")).unwrap().count() != 2 {
// The file system is not case-sensitive.
return Ok(());
return;
}

for (from, to, only_in) in [("one", "two", "two"), ("two", "one", "two")] {
let mut cmd = cargo_bin_cmd!("diffutils");
cmd.current_dir(dir).arg("diff").arg("-r");
cmd.arg("--ignore-file-name-case").arg(from).arg(to);
cmd.assert()
.code(predicate::eq(1))
.stdout(format!("Only in {only_in}: F\n"));
ts.ucmd()
.args(&["-r", "--ignore-file-name-case", from, to])
.fails_with_code(1)
.stdout_only(format!("Only in {only_in}: F\n"));
}
Ok(())
}

#[test]
fn ignore_file_name_case_reports_unpaired_after_pairs() -> Result<(), Box<dyn std::error::Error>> {
let tmp_dir = tempdir()?;
let dir = tmp_dir.path();
std::fs::create_dir(dir.join("one"))?;
std::fs::create_dir(dir.join("two"))?;
std::fs::write(dir.join("one/B"), "1\n")?;
std::fs::write(dir.join("one/b"), "1\n")?;
std::fs::write(dir.join("two/b"), "2\n")?;
std::fs::write(dir.join("one/c"), "1\n")?;
std::fs::write(dir.join("two/C"), "2\n")?;
std::fs::write(dir.join("two/c"), "2\n")?;
if std::fs::read_dir(dir.join("one"))?.count() != 3 {
fn ignore_file_name_case_reports_unpaired_after_pairs() {
let (at, ts) = at_and_ts!();
at.mkdir("one");
at.mkdir("two");
at.write("one/B", "1\n");
at.write("one/b", "1\n");
at.write("two/b", "2\n");
at.write("one/c", "1\n");
at.write("two/C", "2\n");
at.write("two/c", "2\n");
if std::fs::read_dir(at.plus("one")).unwrap().count() != 3 {
// The file system is not case-sensitive.
return Ok(());
return;
}

let mut cmd = cargo_bin_cmd!("diffutils");
cmd.current_dir(dir).arg("diff").arg("-r");
cmd.arg("--ignore-file-name-case").arg("one").arg("two");
cmd.assert().code(predicate::eq(1)).stdout(concat!(
"diff -r --ignore-file-name-case one/b two/b\n",
"1c1\n< 1\n---\n> 2\n",
"Only in one: B\n",
"diff -r --ignore-file-name-case one/c two/c\n",
"1c1\n< 1\n---\n> 2\n",
"Only in two: C\n",
));
Ok(())
ts.ucmd()
.args(&["-r", "--ignore-file-name-case", "one", "two"])
.fails_with_code(1)
.stdout_only(concat!(
"diff -r --ignore-file-name-case one/b two/b\n",
"1c1\n< 1\n---\n> 2\n",
"Only in one: B\n",
"diff -r --ignore-file-name-case one/c two/c\n",
"1c1\n< 1\n---\n> 2\n",
"Only in two: C\n",
));
}

#[cfg(unix)]
Expand Down
Loading