From bcc9350bfe7e496b5aa5701f61b4e125ab40c7e4 Mon Sep 17 00:00:00 2001 From: rootile Date: Mon, 2 Feb 2026 19:18:32 +0100 Subject: [PATCH] tests/functional2: migrate simple.sh Change-Id: I4366ce7d877935df98e35d733650c60f59478ace --- tests/functional/meson.build | 1 - tests/functional/simple.sh | 33 --------- .../test_simple}/big-derivation-attr.nix | 0 .../store/assets/test_simple}/hash-check.nix | 0 tests/functional2/store/test_simple.py | 72 +++++++++++++++++++ 5 files changed, 72 insertions(+), 34 deletions(-) delete mode 100644 tests/functional/simple.sh rename tests/{functional => functional2/store/assets/test_simple}/big-derivation-attr.nix (100%) rename tests/{functional => functional2/store/assets/test_simple}/hash-check.nix (100%) create mode 100644 tests/functional2/store/test_simple.py diff --git a/tests/functional/meson.build b/tests/functional/meson.build index 87e195a83..f521510ec 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -57,7 +57,6 @@ functional_tests_scripts = [ 'fetchurl.sh', 'fetchPath.sh', 'fetchTree-file.sh', - 'simple.sh', 'referrers.sh', 'substitute-with-invalid-ca.sh', 'signing.sh', diff --git a/tests/functional/simple.sh b/tests/functional/simple.sh deleted file mode 100644 index 50d44f93f..000000000 --- a/tests/functional/simple.sh +++ /dev/null @@ -1,33 +0,0 @@ -source common.sh - -drvPath=$(nix-instantiate simple.nix) - -test "$(nix-store -q --binding system "$drvPath")" = "$system" - -echo "derivation is $drvPath" - -outPath=$(nix-store -rvv "$drvPath") - -echo "output path is $outPath" - -(! [ -w $outPath ]) - -text=$(cat "$outPath"/hello) -if test "$text" != "Hello World!"; then exit 1; fi - -# Directed delete: $outPath is not reachable from a root, so it should -# be deleteable. -nix-store --delete $outPath -(! [ -e $outPath/hello ]) - -outPath="$(NIX_REMOTE=local?store=/foo\&real=$TEST_ROOT/real-store nix-instantiate --readonly-mode hash-check.nix)" -if test "$outPath" != "/foo/lfy1s6ca46rm5r6w4gg9hc0axiakjcnm-dependencies.drv"; then - echo "hashDerivationModulo appears broken, got $outPath" - exit 1 -fi - -outPath="$(NIX_REMOTE=local?store=/foo\&real=$TEST_ROOT/real-store nix-instantiate --readonly-mode big-derivation-attr.nix)" -if test "$outPath" != "/foo/xxiwa5zlaajv6xdjynf9yym9g319d6mn-big-derivation-attr.drv"; then - echo "big-derivation-attr.nix hash appears broken, got $outPath. Memory corruption in large drv attr?" - exit 1 -fi diff --git a/tests/functional/big-derivation-attr.nix b/tests/functional2/store/assets/test_simple/big-derivation-attr.nix similarity index 100% rename from tests/functional/big-derivation-attr.nix rename to tests/functional2/store/assets/test_simple/big-derivation-attr.nix diff --git a/tests/functional/hash-check.nix b/tests/functional2/store/assets/test_simple/hash-check.nix similarity index 100% rename from tests/functional/hash-check.nix rename to tests/functional2/store/assets/test_simple/hash-check.nix diff --git a/tests/functional2/store/test_simple.py b/tests/functional2/store/test_simple.py new file mode 100644 index 000000000..9ca6ab944 --- /dev/null +++ b/tests/functional2/store/test_simple.py @@ -0,0 +1,72 @@ +from pathlib import Path + +import pytest + +from testlib.fixtures.file_helper import with_files, CopyFile, File +from testlib.fixtures.nix import Nix +from testlib.utils import get_global_asset_pack +from testlib.environ import environ + +_files = get_global_asset_pack("simple-drv") | { + "hash-check.nix": CopyFile("assets/test_simple/hash-check.nix"), + "big-derivation-attr.nix": CopyFile("assets/test_simple/big-derivation-attr.nix"), + "dummy": File("Hello World\n"), +} + + +@pytest.fixture +def drv(nix: Nix) -> str: + res = nix.nix_instantiate(["simple.nix"]).run().ok() + return res.stdout_plain + + +@with_files(_files) +def test_store_system(nix: Nix, drv: str): + res = nix.nix_store(["-q", "--binding", "system", drv]).run().ok() + assert res.stdout_plain == environ.get("system") + + +@with_files(_files) +def test_out_path(nix: Nix, drv: str): + res = nix.nix_store(["-rvv", drv]).run().ok() + out_path = Path(res.stdout_plain) + + assert out_path.exists() + text_path = out_path / "hello" + assert text_path.read_text() == "Hello World!\n" + + # Directed delete: $outPath is not reachable from a root, so it should + # be deleteable. + nix.nix_store(["--delete", str(out_path)]).run().ok() + assert not text_path.exists() + + res = ( + nix.nix( + [ + "eval", + "--store", + f"local?store=/foo&real={nix.env.dirs.real_store_dir}", + "--read-only", + "-f", + "hash-check.nix", + ], + flake=True, + ) + .run() + .ok() + ) + assert ( + res.stdout_plain == "«derivation /foo/lfy1s6ca46rm5r6w4gg9hc0axiakjcnm-dependencies.drv»" + ), "hashDerivationModulo appears broken" + + nix.env.set_env("NIX_REMOTE", f"local?store=/foo&real={nix.env.dirs.real_store_dir}") + nix.settings.store = None + res = nix.nix_instantiate(["--readonly-mode", "hash-check.nix"]).run().ok() + assert res.stdout_plain == "/foo/lfy1s6ca46rm5r6w4gg9hc0axiakjcnm-dependencies.drv", ( + "hashDerivationModulo appears broken" + ) + + res = nix.nix_instantiate(["--readonly-mode", "big-derivation-attr.nix"]).run().ok() + assert res.stdout_plain == "/foo/xxiwa5zlaajv6xdjynf9yym9g319d6mn-big-derivation-attr.drv", ( + "big-derivation-attr.nix hash appears broken. Memory corruption in large drv attr?" + )