diff --git a/tests/functional/flakes/flakes.sh b/tests/functional/flakes/flakes.sh index 5c3863865..708c26127 100644 --- a/tests/functional/flakes/flakes.sh +++ b/tests/functional/flakes/flakes.sh @@ -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 ]] diff --git a/tests/functional2/flakes/test_cli.py b/tests/functional2/flakes/test_cli.py index 0eceb19dd..fd19e2744 100644 --- a/tests/functional2/flakes/test_cli.py +++ b/tests/functional2/flakes/test_cli.py @@ -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):