tests: migrate check-reqs.sh

Change-Id: Icc22331f6f7e1be0919a74155cd93514c5d70a65
This commit is contained in:
rootile
2026-06-14 20:19:58 +02:00
parent 9614f12908
commit fe79d62b73
4 changed files with 57 additions and 25 deletions
-24
View File
@@ -1,24 +0,0 @@
source common.sh
clearStore
RESULT=$TEST_ROOT/result
nix-build -o $RESULT check-reqs.nix -A test1
(! nix-build -o "$RESULT" check-reqs.nix -A test2)
(! nix-build -o "$RESULT" check-reqs.nix -A test3)
(! nix-build -o "$RESULT" check-reqs.nix -A test4) 2>&1 | grepQuiet 'check-reqs-dep1'
(! nix-build -o "$RESULT" check-reqs.nix -A test4) 2>&1 | grepQuiet 'check-reqs-dep2'
(! nix-build -o "$RESULT" check-reqs.nix -A test5)
(! nix-build -o "$RESULT" check-reqs.nix -A test6)
(! nix-build -o "$RESULT" check-reqs.nix -A test6) 2>&1 | grepQuiet '└───.*/.*-check-reqs-deps'
(! nix-build -o "$RESULT" check-reqs.nix -A test6) 2>&1 | grepQuiet 'check-reqs-dep1'
(! nix-build -o "$RESULT" check-reqs.nix -A test6) 2>&1 | grepQuiet 'check-reqs-dep2'
nix-build -o $RESULT check-reqs.nix -A test7
# ignoreSelfRefs is only true for drvs using structuredAttrs.
(! nix-build -o $RESULT check-reqs.nix -A test8)
nix-build -o $RESULT check-reqs.nix -A test9
-1
View File
@@ -71,7 +71,6 @@ functional_tests_scripts = [
'readfile-context.sh',
'nix-channel.sh',
'dependencies.sh',
'check-reqs.sh',
'build-remote-content-addressed-fixed.sh',
'nar-access.sh',
'repl.sh',
@@ -0,0 +1,57 @@
import pytest
from pathlib import Path
from testlib.fixtures.nix import Nix
from testlib.fixtures.file_helper import CopyFile
from testlib.utils import get_global_asset
from testlib.fixtures.file_helper import with_files
import re
check_req_files = {
"check-reqs.nix": CopyFile("assets/check-reqs.nix"),
"config.nix": get_global_asset("config.nix"),
}
@with_files(check_req_files)
@pytest.mark.parametrize("attr", ["test1", "test7", "test9"])
def test_good(nix: Nix, files: Path, attr: str):
result = files / "result"
nix.nix_build(["-o", result, "check-reqs.nix", "-A", attr]).run().ok()
assert result.exists()
@with_files(check_req_files)
@pytest.mark.parametrize(
"attr",
[
"test2",
"test3",
"test5",
"test8", # ignoreSelfRefs is only true for drvs using structuredAttrs.
],
)
def test_bad(nix: Nix, files: Path, attr: str):
res = nix.nix_build(["-o", files / "result", "check-reqs.nix", "-A", attr]).run().expect(1)
assert "Shown below are chains that lead to the forbidden path(s)." in res.stderr_plain
assert "is not allowed to refer to the following paths:" in res.stderr_plain
@with_files(check_req_files)
@pytest.mark.parametrize(
("attr", "bad_refs"),
[
("test4", ["check-reqs-dep1", "check-reqs-dep2"]),
("test6", ["check-reqs-dep1", "check-reqs-dep2", "└───.*/.*-check-reqs-deps"]),
],
)
def test_bad_deps(nix: Nix, files: Path, attr: str, bad_refs: list[str]):
res = nix.nix_build(["-o", files / "result", "check-reqs.nix", "-A", attr]).run().expect(1)
err = res.stderr_plain
assert "Shown below are chains that lead to the forbidden path(s)." in err
assert "is not allowed to refer to the following paths:" in err
for bad_ref in bad_refs:
assert re.search(bad_ref, err)