Move --commit-lock-file-summary tests into a separate file

This commit is contained in:
Eelco Dolstra 2024-11-20 18:42:33 +01:00
parent fd2df5f02f
commit e1cb905aca
3 changed files with 52 additions and 39 deletions

View File

@ -0,0 +1,50 @@
#!/usr/bin/env bash
source ./common.sh
TODO_NixOS
requireGit
flake1Dir=$TEST_ROOT/flake1
lockfileSummaryFlake=$TEST_ROOT/lockfileSummaryFlake
createGitRepo "$flake1Dir" ""
createSimpleGitFlake "$flake1Dir"
nix registry add --registry "$registry" flake1 "git+file://$flake1Dir"
createGitRepo "$lockfileSummaryFlake" "--initial-branch=main"
# Test that the --commit-lock-file-summary flag and its alias work
cat > "$lockfileSummaryFlake/flake.nix" <<EOF
{
inputs = {
flake1.url = "git+file://$flake1Dir";
};
description = "lockfileSummaryFlake";
outputs = inputs: rec {
packages.$system.default = inputs.flake1.packages.$system.foo;
};
}
EOF
git -C "$lockfileSummaryFlake" add flake.nix
git -C "$lockfileSummaryFlake" commit -m 'Add lockfileSummaryFlake'
testSummary="test summary 1"
nix flake lock "$lockfileSummaryFlake" --commit-lock-file --commit-lock-file-summary "$testSummary"
[[ -e "$lockfileSummaryFlake/flake.lock" ]]
[[ -z $(git -C "$lockfileSummaryFlake" diff main || echo failed) ]]
[[ "$(git -C "$lockfileSummaryFlake" log --format=%s -n 1)" = "$testSummary" ]]
git -C "$lockfileSummaryFlake" rm :/:flake.lock
git -C "$lockfileSummaryFlake" commit -m "remove flake.lock"
testSummary="test summary 2"
# NOTE(cole-h): We use `--option` here because Nix settings do not currently support flag-ifying the
# alias of a setting: https://github.com/NixOS/nix/issues/10989
nix flake lock "$lockfileSummaryFlake" --commit-lock-file --option commit-lockfile-summary "$testSummary"
[[ -e "$lockfileSummaryFlake/flake.lock" ]]
[[ -z $(git -C "$lockfileSummaryFlake" diff main || echo failed) ]]
[[ "$(git -C "$lockfileSummaryFlake" log --format=%s -n 1)" = "$testSummary" ]]

View File

@ -19,17 +19,13 @@ flake7Dir=$TEST_ROOT/flake7
nonFlakeDir=$TEST_ROOT/nonFlake nonFlakeDir=$TEST_ROOT/nonFlake
badFlakeDir=$TEST_ROOT/badFlake badFlakeDir=$TEST_ROOT/badFlake
flakeGitBare=$TEST_ROOT/flakeGitBare flakeGitBare=$TEST_ROOT/flakeGitBare
lockfileSummaryFlake=$TEST_ROOT/lockfileSummaryFlake
for repo in "$flake1Dir" "$flake2Dir" "$flake3Dir" "$flake7Dir" "$nonFlakeDir" "$lockfileSummaryFlake"; do for repo in "$flake1Dir" "$flake2Dir" "$flake3Dir" "$flake7Dir" "$nonFlakeDir"; do
# Give one repo a non-main initial branch. # Give one repo a non-main initial branch.
extraArgs= extraArgs=
if [[ "$repo" == "$flake2Dir" ]]; then if [[ "$repo" == "$flake2Dir" ]]; then
extraArgs="--initial-branch=main" extraArgs="--initial-branch=main"
fi fi
if [[ "$repo" == "$lockfileSummaryFlake" ]]; then
extraArgs="--initial-branch=main"
fi
createGitRepo "$repo" "$extraArgs" createGitRepo "$repo" "$extraArgs"
done done
@ -552,37 +548,3 @@ nix flake metadata "$flake2Dir" --reference-lock-file $TEST_ROOT/flake2-overridd
# reference-lock-file can only be used if allow-dirty is set. # reference-lock-file can only be used if allow-dirty is set.
expectStderr 1 nix flake metadata "$flake2Dir" --no-allow-dirty --reference-lock-file $TEST_ROOT/flake2-overridden.lock expectStderr 1 nix flake metadata "$flake2Dir" --no-allow-dirty --reference-lock-file $TEST_ROOT/flake2-overridden.lock
# Test that the --commit-lock-file-summary flag and its alias work
cat > "$lockfileSummaryFlake/flake.nix" <<EOF
{
inputs = {
flake1.url = "git+file://$flake1Dir";
};
description = "lockfileSummaryFlake";
outputs = inputs: rec {
packages.$system.default = inputs.flake1.packages.$system.foo;
};
}
EOF
git -C "$lockfileSummaryFlake" add flake.nix
git -C "$lockfileSummaryFlake" commit -m 'Add lockfileSummaryFlake'
testSummary="test summary 1"
nix flake lock "$lockfileSummaryFlake" --commit-lock-file --commit-lock-file-summary "$testSummary"
[[ -e "$lockfileSummaryFlake/flake.lock" ]]
[[ -z $(git -C "$lockfileSummaryFlake" diff main || echo failed) ]]
[[ "$(git -C "$lockfileSummaryFlake" log --format=%s -n 1)" = "$testSummary" ]]
git -C "$lockfileSummaryFlake" rm :/:flake.lock
git -C "$lockfileSummaryFlake" commit -m "remove flake.lock"
testSummary="test summary 2"
# NOTE(cole-h): We use `--option` here because Nix settings do not currently support flag-ifying the
# alias of a setting: https://github.com/NixOS/nix/issues/10989
nix flake lock "$lockfileSummaryFlake" --commit-lock-file --option commit-lockfile-summary "$testSummary"
[[ -e "$lockfileSummaryFlake/flake.lock" ]]
[[ -z $(git -C "$lockfileSummaryFlake" diff main || echo failed) ]]
[[ "$(git -C "$lockfileSummaryFlake" log --format=%s -n 1)" = "$testSummary" ]]

View File

@ -25,6 +25,7 @@ suites += {
'show.sh', 'show.sh',
'dubious-query.sh', 'dubious-query.sh',
'shebang.sh', 'shebang.sh',
'commit-lock-file-summary.sh',
], ],
'workdir': meson.current_source_dir(), 'workdir': meson.current_source_dir(),
} }