From a094259d3511c3be48986768efdb1ec3d82de5f4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 13 Jul 2022 20:36:11 +0200 Subject: [PATCH] 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 \