diff --git a/tests/functional/case-hack.sh b/tests/functional/case-hack.sh deleted file mode 100644 index 61bf9b94b..000000000 --- a/tests/functional/case-hack.sh +++ /dev/null @@ -1,19 +0,0 @@ -source common.sh - -clearStore - -rm -rf $TEST_ROOT/case - -opts="--option use-case-hack true" - -# Check whether restoring and dumping a NAR that contains case -# collisions is round-tripping, even on a case-insensitive system. -nix-store $opts --restore $TEST_ROOT/case < case.nar -nix-store $opts --dump $TEST_ROOT/case > $TEST_ROOT/case.nar -cmp case.nar $TEST_ROOT/case.nar -[ "$(nix-hash $opts --type sha256 $TEST_ROOT/case)" = "$(nix-hash --flat --type sha256 case.nar)" ] - -# Check whether we detect true collisions (e.g. those remaining after -# removal of the suffix). -touch "$TEST_ROOT/case/xt_CONNMARK.h~nix~case~hack~3" -(! nix-store $opts --dump $TEST_ROOT/case > /dev/null) diff --git a/tests/functional/meson.build b/tests/functional/meson.build index c46843fe1..2296070a9 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -100,7 +100,6 @@ functional_tests_scripts = [ 'eval-store.sh', 'derivation-json.sh', 'import-derivation.sh', - 'case-hack.sh', 'placeholders.sh', 'ssh-relay.sh', 'build.sh', diff --git a/tests/functional/case.nar b/tests/functional2/store/assets/case.nar similarity index 100% rename from tests/functional/case.nar rename to tests/functional2/store/assets/case.nar diff --git a/tests/functional2/store/test_case_hack.py b/tests/functional2/store/test_case_hack.py new file mode 100644 index 000000000..f66dfc291 --- /dev/null +++ b/tests/functional2/store/test_case_hack.py @@ -0,0 +1,51 @@ +from testlib.fixtures.nix import Nix +from testlib.fixtures.file_helper import CopyFile, with_files + +files = {"case.nar": CopyFile("assets/case.nar")} + +opts = ["--option", "use-case-hack", "true"] + +expected = { + "x", + "x/FOO", + "x/Foo~nix~case~hack~1", + "x/foo~nix~case~hack~2", + "x/foo~nix~case~hack~2/A", + "x/foo~nix~case~hack~2/A/foo", + "x/foo~nix~case~hack~2/a~nix~case~hack~1", + "x/foo~nix~case~hack~2/a~nix~case~hack~1/foo", + "x/foo-1", + "x/foo0", + "xt_CONNMARK.h", + "xt_CONNmark.h~nix~case~hack~1", + "xt_connmark.h~nix~case~hack~2", +} + + +@with_files(files) +def test_case_hack(nix: Nix): + nar_path = nix.env.dirs.home / "case.nar" + nar = nar_path.read_bytes() + out = nix.env.dirs.home / "case" + + # Check whether restoring and dumping a NAR that contains case + # collisions is round-tripping, even on a case-insensitive system. + nix.nix_store([*opts, "--restore", out]).with_stdin(nar).run().ok() + assert set({str(p.relative_to(out)) for p in out.rglob("*")}) == expected + + dumped = nix.nix_store([*opts, "--dump", out]).run().ok().stdout + assert dumped == nar + + out_hash = nix.nix([*opts, "--type", "sha256", out], nix_exe="nix-hash").run().ok().stdout_plain + nar_hash = ( + nix.nix(["--flat", "--type", "sha256", nar_path], nix_exe="nix-hash") + .run() + .ok() + .stdout_plain + ) + assert out_hash == nar_hash + + # Check whether we detect true collisions (e.g. those remaining after + # removal of the suffix). + (out / "xt_CONNMARK.h~nix~case~hack~3").write_text("") + assert "file name collision" in nix.nix_store([*opts, "--dump", out]).run().expect(1).stderr_s