testing: migrate flakes/flakes.sh (part 6)

flake attr matching

Change-Id: If5a1f01f9939740636482d2755eb836e2166ce97
This commit is contained in:
eldritch horrors
2026-02-25 12:47:08 +00:00
parent 5d11ed07f5
commit b4846d4e51
2 changed files with 41 additions and 8 deletions
-8
View File
@@ -77,10 +77,6 @@ nix registry add --registry $registry nixpkgs flake1
nix registry list | grep '^global'
nix registry list | grepInverse '^user' # nothing in user registry
# Test fuzzy and exact flake attribute syntax.
expectStderr 1 nix eval flake1#ERROR | grepQuiet "error:.*does not provide attribute.*or 'ERROR'$"
expectStderr 1 nix eval flake1#.ERROR | grepQuiet "error:.*does not provide attribute 'ERROR'$"
json=$(nix flake metadata flake1 --json | jq .)
hash1=$(echo "$json" | jq -r .revision)
@@ -336,10 +332,6 @@ git -C $flake3Dir add flake.nix flake.lock
git -C $flake3Dir commit -m 'Remove packages.xyzzy'
git -C $flake3Dir checkout master
# Test whether fuzzy-matching works for registry entries.
(! nix build -o $TEST_ROOT/result flake4/removeXyzzy#xyzzy)
nix build -o $TEST_ROOT/result flake4/removeXyzzy#sth
# Testing the nix CLI
nix registry add flake1 flake3
[[ $(nix registry list | wc -l) == 6 ]]
+41
View File
@@ -125,6 +125,47 @@ def registry(nix: Nix, flake1: Path, flake2: Path, flake3: Path) -> Path:
return registry
@pytest.mark.usefixtures("registry")
class TestAttrMatch:
def test_fuzzy_plain(self, nix: Nix):
logs = nix.nix(["eval", "flake1#ERROR"]).run().expect(1).stderr_s
assert re.search(r"error:.*does not provide attribute.*or 'ERROR'$", logs)
def test_exact_plain(self, nix: Nix):
logs = nix.nix(["eval", "flake1#.ERROR"]).run().expect(1).stderr_s
assert re.search(r"error:.*does not provide attribute 'ERROR'$", logs)
def test_fuzzy_branch(self, nix: Nix):
path = nix.nix(["eval", "flake1/main#foo"]).run().ok().stdout_s
assert "-simple.drv" in path
class TestRegistryBranch:
@pytest.fixture(autouse=True)
def create_other_branch(self, flake1: Path, git: Git):
git(flake1, "checkout", "-b", "other")
(flake1 / "flake.nix").write_text(
(flake1 / "flake.nix").read_text().replace("foo", "bar")
)
git(flake1, "commit", "-a", "-mrename foo -> bar")
git(flake1, "checkout", "main")
def test_fuzzy_main_branch(self, nix: Nix):
assert (
"flake 'flake:flake1/main' does not provide attribute"
in nix.nix(["eval", "flake1/main#bar"]).run().expect(1).stderr_s
)
path = nix.nix(["eval", "flake1/main#foo"]).run().ok().stdout_s
assert "-simple.drv" in path
def test_fuzzy_other_branch(self, nix: Nix):
assert (
"flake 'flake:flake1/other' does not provide attribute"
in nix.nix(["eval", "flake1/other#foo"]).run().expect(1).stderr_s
)
path = nix.nix(["eval", "flake1/other#bar"]).run().ok().stdout_s
assert "-simple.drv" in path
@pytest.mark.usefixtures("registry")
class TestBuild:
def test_bare_repo(self, nix: Nix, flake1: Path, git: Git):