From 420957e149256677046b2433135f53ab0dadab3c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 13 Jul 2022 14:09:35 +0200 Subject: [PATCH 1/9] Move flakes tests to a subdirectory --- tests/{ => flakes}/flakes.sh | 6 +++--- tests/{flakes-run.sh => flakes/run.sh} | 4 ++-- tests/local.mk | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) rename tests/{ => flakes}/flakes.sh (99%) rename tests/{flakes-run.sh => flakes/run.sh} (92%) diff --git a/tests/flakes.sh b/tests/flakes/flakes.sh similarity index 99% rename from tests/flakes.sh rename to tests/flakes/flakes.sh index 6574cabf1..b14c79358 100644 --- a/tests/flakes.sh +++ b/tests/flakes/flakes.sh @@ -1,4 +1,4 @@ -source common.sh +source ../common.sh if [[ -z $(type -p git) ]]; then echo "Git not installed; skipping flake tests" @@ -66,7 +66,7 @@ cat > $flake1Dir/flake.nix < $flake3Dir/flake.nix < flake.nix diff --git a/tests/local.mk b/tests/local.mk index ae15c70f9..021aae35e 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -1,6 +1,6 @@ nix_tests = \ - flakes.sh \ - flakes-run.sh \ + flakes/flakes.sh \ + flakes/run.sh \ ca/gc.sh \ gc.sh \ remote-store.sh \ From c591efafd3e967816964600722265b037872200a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 13 Jul 2022 14:40:39 +0200 Subject: [PATCH 2/9] Split off the Mercurial flake tests --- tests/flakes/common.sh | 36 +++++++++++++++++ tests/flakes/flakes.sh | 81 ++++++--------------------------------- tests/flakes/mercurial.sh | 46 ++++++++++++++++++++++ tests/local.mk | 1 + 4 files changed, 94 insertions(+), 70 deletions(-) create mode 100644 tests/flakes/common.sh create mode 100644 tests/flakes/mercurial.sh diff --git a/tests/flakes/common.sh b/tests/flakes/common.sh new file mode 100644 index 000000000..aa45dffa9 --- /dev/null +++ b/tests/flakes/common.sh @@ -0,0 +1,36 @@ +source ../common.sh + +registry=$TEST_ROOT/registry.json + +writeSimpleFlake() { + local flakeDir="$1" + cat > $flakeDir/flake.nix < $flakeDir/flake.nix < $flake1Dir/flake.nix < $templatesDir/flake.nix < $flake5Dir/flake.nix < Date: Wed, 13 Jul 2022 20:16:39 +0200 Subject: [PATCH 3/9] Split off the circular flake import tests --- tests/flakes/circular.sh | 49 +++++++++++++++++++++++++++++ tests/flakes/common.sh | 19 ++++++++++++ tests/flakes/flakes.sh | 66 +++------------------------------------- tests/local.mk | 1 + 4 files changed, 74 insertions(+), 61 deletions(-) create mode 100644 tests/flakes/circular.sh diff --git a/tests/flakes/circular.sh b/tests/flakes/circular.sh new file mode 100644 index 000000000..09cd02edf --- /dev/null +++ b/tests/flakes/circular.sh @@ -0,0 +1,49 @@ +# Test circular flake dependencies. +source ./common.sh + +requireGit + +flakeA=$TEST_ROOT/flakeA +flakeB=$TEST_ROOT/flakeB + +createGitRepo $flakeA +createGitRepo $flakeB + +cat > $flakeA/flake.nix < $flakeB/flake.nix < $flakeDir/flake.nix < $flake7Dir/a (cd $flake7Dir && nix flake init) # check idempotence # Test 'nix flake init' with conflicts -rm -rf $flake7Dir && mkdir $flake7Dir && initRepo "$flake7Dir" +createGitRepo "$flake7Dir" echo b > $flake7Dir/a pushd $flake7Dir (! nix flake init) |& grep "refusing to overwrite existing file '$flake7Dir/a'" @@ -641,45 +624,6 @@ nix flake lock $flake3Dir --update-input flake2/flake1 # Test 'nix flake metadata --json'. nix flake metadata $flake3Dir --json | jq . -# Test circular flake dependencies. -cat > $flakeA/flake.nix < $flakeB/flake.nix < Date: Wed, 13 Jul 2022 20:36:11 +0200 Subject: [PATCH 4/9] Split off 'nix flake init' tests --- tests/flakes/common.sh | 18 ++++++++ tests/flakes/flakes.sh | 99 ++++++------------------------------------ tests/flakes/init.sh | 87 +++++++++++++++++++++++++++++++++++++ tests/local.mk | 1 + 4 files changed, 119 insertions(+), 86 deletions(-) create mode 100644 tests/flakes/init.sh diff --git a/tests/flakes/common.sh b/tests/flakes/common.sh index 43a589507..c333733c2 100644 --- a/tests/flakes/common.sh +++ b/tests/flakes/common.sh @@ -30,6 +30,13 @@ EOF cp ../simple.nix ../simple.builder.sh ../config.nix $flakeDir/ } +createSimpleGitFlake() { + local flakeDir="$1" + writeSimpleFlake $flakeDir + git -C $flakeDir add flake.nix simple.nix simple.builder.sh config.nix + git -C $flakeDir commit -m 'Initial' +} + writeDependentFlake() { local flakeDir="$1" cat > $flakeDir/flake.nix < $flakeDir/flake.nix < $flake2Dir/flake.nix < $templatesDir/flake.nix < $templatesDir/trivial/flake.nix < $templatesDir/trivial/a -echo b > $templatesDir/trivial/b - -git -C $templatesDir add flake.nix trivial/ -git -C $templatesDir commit -m 'Initial' - -nix flake check templates -nix flake show templates -nix flake show templates --json | jq - -(cd $flake7Dir && nix flake init) -(cd $flake7Dir && nix flake init) # check idempotence -git -C $flake7Dir add flake.nix -nix flake check $flake7Dir -nix flake show $flake7Dir -nix flake show $flake7Dir --json | jq -git -C $flake7Dir commit -a -m 'Initial' - -# Test 'nix flake init' with benign conflicts -createGitRepo "$flake7Dir" -echo a > $flake7Dir/a -(cd $flake7Dir && nix flake init) # check idempotence - -# Test 'nix flake init' with conflicts -createGitRepo "$flake7Dir" -echo b > $flake7Dir/a -pushd $flake7Dir -(! nix flake init) |& grep "refusing to overwrite existing file '$flake7Dir/a'" -popd -git -C $flake7Dir commit -a -m 'Changed' - -# Test 'nix flake new'. -rm -rf $flake6Dir -nix flake new -t templates#trivial $flake6Dir -nix flake new -t templates#trivial $flake6Dir # check idempotence -nix flake check $flake6Dir +nix registry pin flake1 +[[ $(nix registry list | wc -l) == 6 ]] +nix registry pin flake1 flake3 +[[ $(nix registry list | wc -l) == 6 ]] +nix registry remove flake1 +[[ $(nix registry list | wc -l) == 5 ]] # Test 'nix flake clone'. rm -rf $TEST_ROOT/flake1-v2 @@ -550,6 +473,10 @@ nix flake lock $flake3Dir [[ $(jq -c .nodes.root.inputs.bar $flake3Dir/flake.lock) = '["flake2"]' ]] # Test overriding inputs of inputs. +writeTrivialFlake $flake7Dir +git -C $flake7Dir add flake.nix +git -C $flake7Dir commit -m 'Initial' + cat > $flake3Dir/flake.nix < $templatesDir/flake.nix < $templatesDir/trivial/flake.nix < $templatesDir/trivial/a +echo b > $templatesDir/trivial/b + +git -C $templatesDir add flake.nix trivial/ +git -C $templatesDir commit -m 'Initial' + +nix flake check templates +nix flake show templates +nix flake show templates --json | jq + +createGitRepo $flakeDir +(cd $flakeDir && nix flake init) +(cd $flakeDir && nix flake init) # check idempotence +git -C $flakeDir add flake.nix +nix flake check $flakeDir +nix flake show $flakeDir +nix flake show $flakeDir --json | jq +git -C $flakeDir commit -a -m 'Initial' + +# Test 'nix flake init' with benign conflicts +createGitRepo "$flakeDir" +echo a > $flakeDir/a +(cd $flakeDir && nix flake init) # check idempotence + +# Test 'nix flake init' with conflicts +createGitRepo "$flakeDir" +echo b > $flakeDir/a +pushd $flakeDir +(! nix flake init) |& grep "refusing to overwrite existing file '$flakeDir/a'" +popd +git -C $flakeDir commit -a -m 'Changed' + +# Test 'nix flake new'. +rm -rf $flakeDir +nix flake new -t templates#trivial $flakeDir +nix flake new -t templates#trivial $flakeDir # check idempotence +nix flake check $flakeDir diff --git a/tests/local.mk b/tests/local.mk index 8f266a330..9e372094f 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -3,6 +3,7 @@ nix_tests = \ flakes/run.sh \ flakes/mercurial.sh \ flakes/circular.sh \ + flakes/init.sh \ ca/gc.sh \ gc.sh \ remote-store.sh \ From d16f1070f42be987093e2252c1e7bbebe0565ae0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 13 Jul 2022 20:46:22 +0200 Subject: [PATCH 5/9] Split off following paths tests --- tests/flakes/flakes.sh | 148 +--------------------------------- tests/flakes/follow-paths.sh | 150 +++++++++++++++++++++++++++++++++++ tests/local.mk | 1 + 3 files changed, 152 insertions(+), 147 deletions(-) create mode 100644 tests/flakes/follow-paths.sh diff --git a/tests/flakes/flakes.sh b/tests/flakes/flakes.sh index c99e828f3..67f00a3e5 100644 --- a/tests/flakes/flakes.sh +++ b/tests/flakes/flakes.sh @@ -13,13 +13,8 @@ flake7Dir=$TEST_ROOT/flake7 nonFlakeDir=$TEST_ROOT/nonFlake badFlakeDir=$TEST_ROOT/badFlake flakeGitBare=$TEST_ROOT/flakeGitBare -flakeFollowsA=$TEST_ROOT/follows/flakeA -flakeFollowsB=$TEST_ROOT/follows/flakeA/flakeB -flakeFollowsC=$TEST_ROOT/follows/flakeA/flakeB/flakeC -flakeFollowsD=$TEST_ROOT/follows/flakeA/flakeD -flakeFollowsE=$TEST_ROOT/follows/flakeA/flakeE -for repo in $flake1Dir $flake2Dir $flake3Dir $flake7Dir $nonFlakeDir $flakeFollowsA; do +for repo in $flake1Dir $flake2Dir $flake3Dir $flake7Dir $nonFlakeDir; do # Give one repo a non-main initial branch. extraArgs= if [[ $repo == $flake2Dir ]]; then @@ -551,127 +546,6 @@ nix flake lock $flake3Dir --update-input flake2/flake1 # Test 'nix flake metadata --json'. nix flake metadata $flake3Dir --json | jq . -# Test flake follow paths -mkdir -p $flakeFollowsB -mkdir -p $flakeFollowsC -mkdir -p $flakeFollowsD -mkdir -p $flakeFollowsE - -cat > $flakeFollowsA/flake.nix < $flakeFollowsB/flake.nix < $flakeFollowsC/flake.nix < $flakeFollowsD/flake.nix < $flakeFollowsE/flake.nix < $flakeFollowsA/flake.nix < $flakeFollowsA/flake.nix <&1 | grep 'points outside' - # Test flake in store does not evaluate rm -rf $badFlakeDir mkdir $badFlakeDir @@ -680,23 +554,3 @@ nix store delete $(nix store add-path $badFlakeDir) [[ $(nix path-info $(nix store add-path $flake1Dir)) =~ flake1 ]] [[ $(nix path-info path:$(nix store add-path $flake1Dir)) =~ simple ]] - -# Non-existant follows causes an error - -cat >$flakeFollowsA/flake.nix <&1 | grep "warning: input 'B' has an override for a non-existent input 'invalid'" -nix flake lock $flakeFollowsA 2>&1 | grep "warning: input 'B' has an override for a non-existent input 'invalid2'" diff --git a/tests/flakes/follow-paths.sh b/tests/flakes/follow-paths.sh new file mode 100644 index 000000000..19cc1bafa --- /dev/null +++ b/tests/flakes/follow-paths.sh @@ -0,0 +1,150 @@ +source ./common.sh + +requireGit + +flakeFollowsA=$TEST_ROOT/follows/flakeA +flakeFollowsB=$TEST_ROOT/follows/flakeA/flakeB +flakeFollowsC=$TEST_ROOT/follows/flakeA/flakeB/flakeC +flakeFollowsD=$TEST_ROOT/follows/flakeA/flakeD +flakeFollowsE=$TEST_ROOT/follows/flakeA/flakeE + +# Test following path flakerefs. +createGitRepo $flakeFollowsA +mkdir -p $flakeFollowsB +mkdir -p $flakeFollowsC +mkdir -p $flakeFollowsD +mkdir -p $flakeFollowsE + +cat > $flakeFollowsA/flake.nix < $flakeFollowsB/flake.nix < $flakeFollowsC/flake.nix < $flakeFollowsD/flake.nix < $flakeFollowsE/flake.nix < $flakeFollowsA/flake.nix < $flakeFollowsA/flake.nix <&1 | grep 'points outside' + +# Non-existant follows should print a warning. +cat >$flakeFollowsA/flake.nix <&1 | grep "warning: input 'B' has an override for a non-existent input 'invalid'" +nix flake lock $flakeFollowsA 2>&1 | grep "warning: input 'B' has an override for a non-existent input 'invalid2'" diff --git a/tests/local.mk b/tests/local.mk index 9e372094f..1540a1c8c 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -4,6 +4,7 @@ nix_tests = \ flakes/mercurial.sh \ flakes/circular.sh \ flakes/init.sh \ + flakes/follow-paths.sh \ ca/gc.sh \ gc.sh \ remote-store.sh \ From 7abcafcfeacad587ccf1a7e58334958e25cef5b8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 13 Jul 2022 20:49:07 +0200 Subject: [PATCH 6/9] Move the 'nix bundle' tests Note: these were previously not actually called. --- tests/{flake-bundler.sh => flakes/bundle.sh} | 9 ++------- tests/local.mk | 1 + 2 files changed, 3 insertions(+), 7 deletions(-) rename tests/{flake-bundler.sh => flakes/bundle.sh} (84%) diff --git a/tests/flake-bundler.sh b/tests/flakes/bundle.sh similarity index 84% rename from tests/flake-bundler.sh rename to tests/flakes/bundle.sh index 9496b8f92..67bbb05ac 100644 --- a/tests/flake-bundler.sh +++ b/tests/flakes/bundle.sh @@ -1,9 +1,6 @@ source common.sh -clearStore -rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local - -cp ./simple.nix ./simple.builder.sh ./config.nix $TEST_HOME +cp ../simple.nix ../simple.builder.sh ../config.nix $TEST_HOME cd $TEST_HOME @@ -25,6 +22,7 @@ cat < flake.nix }; } EOF + nix build .# nix bundle --bundler .# .# nix bundle --bundler .#bundlers.$system.default .#packages.$system.default @@ -32,6 +30,3 @@ nix bundle --bundler .#bundlers.$system.simple .#packages.$system.default nix bundle --bundler .#bundlers.$system.default .#apps.$system.default nix bundle --bundler .#bundlers.$system.simple .#apps.$system.default - -clearStore - diff --git a/tests/local.mk b/tests/local.mk index 1540a1c8c..23eb92039 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -5,6 +5,7 @@ nix_tests = \ flakes/circular.sh \ flakes/init.sh \ flakes/follow-paths.sh \ + flakes/bundle.sh \ ca/gc.sh \ gc.sh \ remote-store.sh \ From 6ba45f81a8a8fcf404f899b9f6879dd6af7d8ac4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 13 Jul 2022 20:51:28 +0200 Subject: [PATCH 7/9] Move flake-local-settings.sh --- tests/{flake-local-settings.sh => flakes/config.sh} | 5 +---- tests/local.mk | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) rename tests/{flake-local-settings.sh => flakes/config.sh} (88%) diff --git a/tests/flake-local-settings.sh b/tests/flakes/config.sh similarity index 88% rename from tests/flake-local-settings.sh rename to tests/flakes/config.sh index e92c16f87..d1941a6be 100644 --- a/tests/flake-local-settings.sh +++ b/tests/flakes/config.sh @@ -1,9 +1,6 @@ source common.sh -clearStore -rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local - -cp ./simple.nix ./simple.builder.sh ./config.nix $TEST_HOME +cp ../simple.nix ../simple.builder.sh ../config.nix $TEST_HOME cd $TEST_HOME diff --git a/tests/local.mk b/tests/local.mk index 23eb92039..2b5b6858e 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -85,7 +85,7 @@ nix_tests = \ nix-copy-ssh.sh \ post-hook.sh \ function-trace.sh \ - flake-local-settings.sh \ + flakes/config.sh \ fmt.sh \ eval-store.sh \ why-depends.sh \ From 752158a8efb7a027e5020d3c9c03aa5d70002b56 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 13 Jul 2022 20:55:08 +0200 Subject: [PATCH 8/9] Move flake-searching.sh and make it less dependent on git --- .../search-root.sh} | 24 +++++++++---------- tests/local.mk | 2 +- 2 files changed, 12 insertions(+), 14 deletions(-) rename tests/{flake-searching.sh => flakes/search-root.sh} (72%) diff --git a/tests/flake-searching.sh b/tests/flakes/search-root.sh similarity index 72% rename from tests/flake-searching.sh rename to tests/flakes/search-root.sh index db241f6d2..d8586dc8a 100644 --- a/tests/flake-searching.sh +++ b/tests/flakes/search-root.sh @@ -1,15 +1,11 @@ source common.sh -if [[ -z $(type -p git) ]]; then - echo "Git not installed; skipping flake search tests" - exit 99 -fi - clearStore -cp ./simple.nix ./simple.builder.sh ./config.nix $TEST_HOME +writeSimpleFlake $TEST_HOME cd $TEST_HOME mkdir -p foo/subdir + echo '{ outputs = _: {}; }' > foo/flake.nix cat < flake.nix { @@ -43,10 +39,12 @@ nix build --override-input foo . || fail "flake should search up directories whe sed "s,$PWD/foo,$PWD/foo/subdir,g" -i flake.nix ! nix build || fail "flake should not search upwards when part of inputs" -pushd subdir -git init -for i in "${success[@]}" "${failure[@]}"; do - ! nix build $i || fail "flake should not search past a git repository" -done -rm -rf .git -popd +if [[ -n $(type -p git) ]]; then + pushd subdir + git init + for i in "${success[@]}" "${failure[@]}"; do + ! nix build $i || fail "flake should not search past a git repository" + done + rm -rf .git + popd +fi diff --git a/tests/local.mk b/tests/local.mk index 2b5b6858e..25d23a2fc 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -49,7 +49,7 @@ nix_tests = \ secure-drv-outputs.sh \ restricted.sh \ fetchGitSubmodules.sh \ - flake-searching.sh \ + flakes/search-root.sh \ ca/duplicate-realisation-in-closure.sh \ readfile-context.sh \ nix-channel.sh \ From b15c4fdbde738310188be035807de7d5b2036a28 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 13 Jul 2022 21:01:16 +0200 Subject: [PATCH 9/9] Split off 'nix flake check' tests --- tests/flakes/check.sh | 89 ++++++++++++++++++++++++++++++++++++++++++ tests/flakes/flakes.sh | 86 ---------------------------------------- tests/local.mk | 1 + 3 files changed, 90 insertions(+), 86 deletions(-) create mode 100644 tests/flakes/check.sh diff --git a/tests/flakes/check.sh b/tests/flakes/check.sh new file mode 100644 index 000000000..f572aa75c --- /dev/null +++ b/tests/flakes/check.sh @@ -0,0 +1,89 @@ +source common.sh + +flakeDir=$TEST_ROOT/flake3 +mkdir -p $flakeDir + +cat > $flakeDir/flake.nix < $flakeDir/flake.nix < $flakeDir/flake.nix < $flakeDir/flake.nix < $flakeDir/flake.nix < $flakeDir/flake.nix < $flakeDir/flake.nix <&1 && fail "nix flake check should have failed" || true) +echo "$checkRes" | grep -q "packages.system-1.default" +echo "$checkRes" | grep -q "packages.system-2.default" diff --git a/tests/flakes/flakes.sh b/tests/flakes/flakes.sh index 67f00a3e5..267e2cd6f 100644 --- a/tests/flakes/flakes.sh +++ b/tests/flakes/flakes.sh @@ -340,92 +340,6 @@ rm -rf $TEST_ROOT/flake1-v2 nix flake clone flake1 --dest $TEST_ROOT/flake1-v2 [ -e $TEST_ROOT/flake1-v2/flake.nix ] -# More 'nix flake check' tests. -cat > $flake3Dir/flake.nix < $flake3Dir/flake.nix < $flake3Dir/flake.nix < $flake3Dir/flake.nix < $flake3Dir/flake.nix < $flake3Dir/flake.nix < $flake3Dir/flake.nix <&1 && fail "nix flake check should have failed" || true) -echo "$checkRes" | grep -q "packages.system-1.default" -echo "$checkRes" | grep -q "packages.system-2.default" - # Test 'follows' inputs. cat > $flake3Dir/flake.nix <