1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

shellcheck fix: tests/functional/flakes/check.sh

This commit is contained in:
Farid Zakaria 2025-09-25 13:23:02 -07:00
parent 9bf8e7b730
commit 26a10453c3
2 changed files with 33 additions and 29 deletions

View file

@ -106,7 +106,6 @@
enable = true; enable = true;
excludes = [ excludes = [
# We haven't linted these files yet # We haven't linted these files yet
''^tests/functional/flakes/check\.sh$''
''^tests/functional/flakes/config\.sh$'' ''^tests/functional/flakes/config\.sh$''
''^tests/functional/flakes/flakes\.sh$'' ''^tests/functional/flakes/flakes\.sh$''
''^tests/functional/flakes/follow-paths\.sh$'' ''^tests/functional/flakes/follow-paths\.sh$''

View file

@ -3,9 +3,9 @@
source common.sh source common.sh
flakeDir=$TEST_ROOT/flake3 flakeDir=$TEST_ROOT/flake3
mkdir -p $flakeDir mkdir -p "$flakeDir"
cat > $flakeDir/flake.nix <<EOF cat > "$flakeDir"/flake.nix <<EOF
{ {
outputs = { self }: { outputs = { self }: {
overlay = final: prev: { overlay = final: prev: {
@ -14,9 +14,9 @@ cat > $flakeDir/flake.nix <<EOF
} }
EOF EOF
nix flake check $flakeDir nix flake check "$flakeDir"
cat > $flakeDir/flake.nix <<EOF cat > "$flakeDir"/flake.nix <<EOF
{ {
outputs = { self }: { outputs = { self }: {
overlay = finalll: prev: { overlay = finalll: prev: {
@ -25,9 +25,9 @@ cat > $flakeDir/flake.nix <<EOF
} }
EOF EOF
(! nix flake check $flakeDir) (! nix flake check "$flakeDir")
cat > $flakeDir/flake.nix <<EOF cat > "$flakeDir"/flake.nix <<EOF
{ {
outputs = { self, ... }: { outputs = { self, ... }: {
overlays.x86_64-linux.foo = final: prev: { overlays.x86_64-linux.foo = final: prev: {
@ -36,10 +36,11 @@ cat > $flakeDir/flake.nix <<EOF
} }
EOF EOF
checkRes=$(nix flake check $flakeDir 2>&1 && fail "nix flake check --all-systems should have failed" || true) # shellcheck disable=SC2015
checkRes=$(nix flake check "$flakeDir" 2>&1 && fail "nix flake check --all-systems should have failed" || true)
echo "$checkRes" | grepQuiet "error: overlay is not a function, but a set instead" echo "$checkRes" | grepQuiet "error: overlay is not a function, but a set instead"
cat > $flakeDir/flake.nix <<EOF cat > "$flakeDir"/flake.nix <<EOF
{ {
outputs = { self }: { outputs = { self }: {
nixosModules.foo = { nixosModules.foo = {
@ -50,9 +51,9 @@ cat > $flakeDir/flake.nix <<EOF
} }
EOF EOF
nix flake check $flakeDir nix flake check "$flakeDir"
cat > $flakeDir/flake.nix <<EOF cat > "$flakeDir"/flake.nix <<EOF
{ {
outputs = { self }: { outputs = { self }: {
nixosModules.foo = assert false; { nixosModules.foo = assert false; {
@ -63,9 +64,9 @@ cat > $flakeDir/flake.nix <<EOF
} }
EOF EOF
(! nix flake check $flakeDir) (! nix flake check "$flakeDir")
cat > $flakeDir/flake.nix <<EOF cat > "$flakeDir"/flake.nix <<EOF
{ {
outputs = { self }: { outputs = { self }: {
nixosModule = { config, pkgs, ... }: { nixosModule = { config, pkgs, ... }: {
@ -75,9 +76,9 @@ cat > $flakeDir/flake.nix <<EOF
} }
EOF EOF
nix flake check $flakeDir nix flake check "$flakeDir"
cat > $flakeDir/flake.nix <<EOF cat > "$flakeDir"/flake.nix <<EOF
{ {
outputs = { self }: { outputs = { self }: {
packages.system-1.default = "foo"; packages.system-1.default = "foo";
@ -86,13 +87,14 @@ cat > $flakeDir/flake.nix <<EOF
} }
EOF EOF
nix flake check $flakeDir nix flake check "$flakeDir"
checkRes=$(nix flake check --all-systems --keep-going $flakeDir 2>&1 && fail "nix flake check --all-systems should have failed" || true) # shellcheck disable=SC2015
checkRes=$(nix flake check --all-systems --keep-going "$flakeDir" 2>&1 && fail "nix flake check --all-systems should have failed" || true)
echo "$checkRes" | grepQuiet "packages.system-1.default" echo "$checkRes" | grepQuiet "packages.system-1.default"
echo "$checkRes" | grepQuiet "packages.system-2.default" echo "$checkRes" | grepQuiet "packages.system-2.default"
cat > $flakeDir/flake.nix <<EOF cat > "$flakeDir"/flake.nix <<EOF
{ {
outputs = { self }: { outputs = { self }: {
apps.system-1.default = { apps.system-1.default = {
@ -108,9 +110,9 @@ cat > $flakeDir/flake.nix <<EOF
} }
EOF EOF
nix flake check --all-systems $flakeDir nix flake check --all-systems "$flakeDir"
cat > $flakeDir/flake.nix <<EOF cat > "$flakeDir"/flake.nix <<EOF
{ {
outputs = { self }: { outputs = { self }: {
apps.system-1.default = { apps.system-1.default = {
@ -122,10 +124,11 @@ cat > $flakeDir/flake.nix <<EOF
} }
EOF EOF
checkRes=$(nix flake check --all-systems $flakeDir 2>&1 && fail "nix flake check --all-systems should have failed" || true) # shellcheck disable=SC2015
checkRes=$(nix flake check --all-systems "$flakeDir" 2>&1 && fail "nix flake check --all-systems should have failed" || true)
echo "$checkRes" | grepQuiet "unknown-attr" echo "$checkRes" | grepQuiet "unknown-attr"
cat > $flakeDir/flake.nix <<EOF cat > "$flakeDir"/flake.nix <<EOF
{ {
outputs = { self }: { outputs = { self }: {
formatter.system-1 = "foo"; formatter.system-1 = "foo";
@ -133,11 +136,12 @@ cat > $flakeDir/flake.nix <<EOF
} }
EOF EOF
checkRes=$(nix flake check --all-systems $flakeDir 2>&1 && fail "nix flake check --all-systems should have failed" || true) # shellcheck disable=SC2015
checkRes=$(nix flake check --all-systems "$flakeDir" 2>&1 && fail "nix flake check --all-systems should have failed" || true)
echo "$checkRes" | grepQuiet "formatter.system-1" echo "$checkRes" | grepQuiet "formatter.system-1"
# Test whether `nix flake check` builds checks. # Test whether `nix flake check` builds checks.
cat > $flakeDir/flake.nix <<EOF cat > "$flakeDir"/flake.nix <<EOF
{ {
outputs = { self }: { outputs = { self }: {
checks.$system.foo = with import ./config.nix; mkDerivation { checks.$system.foo = with import ./config.nix; mkDerivation {
@ -152,7 +156,7 @@ cp "${config_nix}" "$flakeDir/"
expectStderr 0 nix flake check "$flakeDir" | grepQuiet 'running 1 flake check' expectStderr 0 nix flake check "$flakeDir" | grepQuiet 'running 1 flake check'
cat > $flakeDir/flake.nix <<EOF cat > "$flakeDir"/flake.nix <<EOF
{ {
outputs = { self }: { outputs = { self }: {
checks.$system.foo = with import ./config.nix; mkDerivation { checks.$system.foo = with import ./config.nix; mkDerivation {
@ -164,14 +168,14 @@ cat > $flakeDir/flake.nix <<EOF
EOF EOF
# FIXME: error code 100 doesn't get propagated from the daemon. # FIXME: error code 100 doesn't get propagated from the daemon.
if !isTestOnNixOS && $NIX_REMOTE != daemon; then if ! isTestOnNixOS && $NIX_REMOTE != daemon; then
expectStderr 100 nix flake check "$flakeDir" | grepQuiet 'builder failed with exit code 1' expectStderr 100 nix flake check "$flakeDir" | grepQuiet 'builder failed with exit code 1'
fi fi
# Ensure non-substitutable (read: usually failed) checks are actually run # Ensure non-substitutable (read: usually failed) checks are actually run
# https://github.com/NixOS/nix/pull/13574 # https://github.com/NixOS/nix/pull/13574
cp "$config_nix" $flakeDir/ cp "$config_nix" "$flakeDir"/
cat > $flakeDir/flake.nix <<EOF cat > "$flakeDir"/flake.nix <<EOF
{ {
outputs = { self }: with import ./config.nix; { outputs = { self }: with import ./config.nix; {
checks.${system}.expectedToFail = derivation { checks.${system}.expectedToFail = derivation {
@ -185,5 +189,6 @@ EOF
# NOTE: Regex pattern is used for compatibility with older daemon versions # NOTE: Regex pattern is used for compatibility with older daemon versions
# We also can't expect a specific status code. Earlier daemons return 1, but as of 2.31, we return 100 # We also can't expect a specific status code. Earlier daemons return 1, but as of 2.31, we return 100
checkRes=$(nix flake check $flakeDir 2>&1 && fail "nix flake check should have failed" || true) # shellcheck disable=SC2015
checkRes=$(nix flake check "$flakeDir" 2>&1 && fail "nix flake check should have failed" || true)
echo "$checkRes" | grepQuiet -E "builder( for .*)? failed with exit code 1" echo "$checkRes" | grepQuiet -E "builder( for .*)? failed with exit code 1"