diff options
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/fixtures.sh | 69 | ||||
| -rw-r--r-- | tests/scenarios.nix | 34 |
2 files changed, 103 insertions, 0 deletions
diff --git a/tests/fixtures.sh b/tests/fixtures.sh index 9608fcd..9813c8f 100755 --- a/tests/fixtures.sh +++ b/tests/fixtures.sh @@ -147,6 +147,75 @@ cat > /fixtures/uselocal/flake.nix <<'NIX' NIX (cd /fixtures/uselocal && nix flake lock) +# follow: a flake whose input dep draws its input inner from the flake's own +# input inner, which is inner2, so the lock file records a follows path, and +# dep's own lock file pins another inner than the flake's. +mkdir /fixtures/www/src/inner2 +cat > /fixtures/www/src/inner2/flake.nix <<'NIX' +{ outputs = _: { who = "inner2"; }; } +NIX +tarball inner2 +mkdir /fixtures/follow +cat > /fixtures/follow/flake.nix <<NIX +{ + inputs.inner.url = "$url/inner2.tar.gz"; + inputs.dep.url = "$url/dep.tar.gz"; + inputs.dep.inputs.inner.follows = "inner"; + outputs = { dep, ... }: { msg = "follow:\${dep.greeting}"; }; +} +NIX +(cd /fixtures/follow && nix flake lock) + +# nofollow: a flake that removes an input of its input, so the lock file +# records an empty follows path. +mkdir /fixtures/nofollow +cat > /fixtures/nofollow/flake.nix <<NIX +{ + inputs.dep.url = "$url/dep.tar.gz"; + inputs.dep.inputs.inner.follows = ""; + outputs = _: { msg = "nofollow"; }; +} +NIX +(cd /fixtures/nofollow && nix flake lock) + +# cyc: a flake whose inputs cyca and cycb follow each other. +for name in cyca cycb; do + other=$(test $name = cyca && echo cycb || echo cyca) + mkdir /fixtures/www/src/$name + cat > /fixtures/www/src/$name/flake.nix <<NIX +{ + inputs.other.url = "$url/$other.tar.gz"; + outputs = _: { who = "$name"; }; +} +NIX + tarball $name +done +mkdir /fixtures/cyc +cat > /fixtures/cyc/flake.nix <<NIX +{ + inputs.a.url = "$url/cyca.tar.gz"; + inputs.b.url = "$url/cycb.tar.gz"; + inputs.a.inputs.other.follows = "b"; + inputs.b.inputs.other.follows = "a"; + outputs = { a, b, ... }: { msg = "cyc:\${a.who},\${b.who}"; }; +} +NIX +(cd /fixtures/cyc && nix flake lock) + +# rel: a flake in a Git work tree with an input in a subdirectory, referred +# to by a relative path. +mkdir -p /fixtures/rel/lib +cat > /fixtures/rel/lib/flake.nix <<'NIX' +{ outputs = _: { who = "lib"; }; } +NIX +cat > /fixtures/rel/flake.nix <<'NIX' +{ + inputs.lib.url = "path:./lib"; + outputs = { lib, ... }: { msg = "rel:${lib.who}"; }; +} +NIX +(cd /fixtures/rel && nix flake lock && git init -q && commit rel) + # noflake: a directory without flake.nix. mkdir /fixtures/noflake echo noflake > /fixtures/noflake/README diff --git a/tests/scenarios.nix b/tests/scenarios.nix index ef80d05..a738eca 100644 --- a/tests/scenarios.nix +++ b/tests/scenarios.nix @@ -774,6 +774,40 @@ assert !(krops.isLocalTarget (targets.remote "/")); ''; }; }) + (s "follows-empty" { + phases = twice { + sources.x.flake = { flake = "/fixtures/nofollow"; fetchOnTarget = true; }; + check = checkFlake { attr = "msg"; expected = "nofollow"; }; + }; + }) + (s "follows-cycle" { + phases = twice { + sources.x.flake = { flake = "/fixtures/cyc"; fetchOnTarget = true; }; + check = checkFlake { attr = "msg"; expected = "cyc:cyca,cycb"; }; + }; + }) + # Names resolve through the parent's lock file, so dep/inner is the + # parent's inner, which dep's inner follows. + (s "follows-name" { + phases = twice { + sources.x.flake-input = { flake = "/fixtures/follow"; name = "dep/inner"; inherit fetchOnTarget; }; + check = checkFlake { attr = "who"; expected = "inner2"; }; + }; + }) + # The delivered input comes with the inputs its own lock file pins, which + # evaluating it needs, not with the parent's inner, which it follows there. + (s "follows-closure" { + phases = twice { + sources.x.flake-input = { flake = "/fixtures/follow"; name = "dep"; inherit fetchOnTarget; }; + check = checkFlake { attr = "greeting"; expected = "dep+inner"; } + roots 1; + }; + }) + (s "relative-input" { + phases = twice { + sources.x.flake = { flake = "/fixtures/rel"; fetchOnTarget = true; }; + check = checkFlake { attr = "msg"; expected = "rel:lib"; }; + }; + }) ] ++ lib.optional (targetKind == "local") # The target has the path the input is locked to. (s "uselocal" { |
