shellcheck

This commit is contained in:
Eelco Dolstra 2024-11-20 20:42:13 +01:00
parent 6832ee5d6f
commit 671df02bf7
2 changed files with 22 additions and 24 deletions

View File

@ -71,7 +71,7 @@ nix build -o "$TEST_ROOT/result" "$flake3Dir#sth" --commit-lock-file
nix registry add --registry "$registry" flake3 "git+file://$flake3Dir" nix registry add --registry "$registry" flake3 "git+file://$flake3Dir"
nix build -o "$TEST_ROOT/result" flake3#fnord nix build -o "$TEST_ROOT/result" flake3#fnord
[[ $(cat $TEST_ROOT/result) = FNORD ]] [[ $(cat "$TEST_ROOT/result") = FNORD ]]
# Check whether flake input fetching is lazy: flake3#sth does not # Check whether flake input fetching is lazy: flake3#sth does not
# depend on flake2, so this shouldn't fail. # depend on flake2, so this shouldn't fail.

View File

@ -6,7 +6,7 @@ TODO_NixOS
createFlake1 createFlake1
scriptDir=$TEST_ROOT/nonFlake scriptDir="$TEST_ROOT/nonFlake"
mkdir -p "$scriptDir" mkdir -p "$scriptDir"
cat > "$scriptDir/shebang.sh" <<EOF cat > "$scriptDir/shebang.sh" <<EOF
@ -20,10 +20,8 @@ echo "\$@"
EOF EOF
chmod +x "$scriptDir/shebang.sh" chmod +x "$scriptDir/shebang.sh"
#git -C "$scriptDir" add shebang.sh
# this also tests a fairly trivial double backtick quoted string, ``--command`` # this also tests a fairly trivial double backtick quoted string, ``--command``
cat > $scriptDir/shebang-comments.sh <<EOF cat > "$scriptDir/shebang-comments.sh" <<EOF
#! $(type -P env) nix #! $(type -P env) nix
# some comments # some comments
# some comments # some comments
@ -33,9 +31,9 @@ cat > $scriptDir/shebang-comments.sh <<EOF
#! nix --no-write-lock-file ``--command`` bash #! nix --no-write-lock-file ``--command`` bash
foo foo
EOF EOF
chmod +x $scriptDir/shebang-comments.sh chmod +x "$scriptDir/shebang-comments.sh"
cat > $scriptDir/shebang-different-comments.sh <<EOF cat > "$scriptDir/shebang-different-comments.sh" <<EOF
#! $(type -P env) nix #! $(type -P env) nix
# some comments # some comments
// some comments // some comments
@ -51,9 +49,9 @@ cat > $scriptDir/shebang-different-comments.sh <<EOF
#! nix --no-write-lock-file --command cat #! nix --no-write-lock-file --command cat
foo foo
EOF EOF
chmod +x $scriptDir/shebang-different-comments.sh chmod +x "$scriptDir/shebang-different-comments.sh"
cat > $scriptDir/shebang-reject.sh <<EOF cat > "$scriptDir/shebang-reject.sh" <<EOF
#! $(type -P env) nix #! $(type -P env) nix
# some comments # some comments
# some comments # some comments
@ -63,12 +61,12 @@ cat > $scriptDir/shebang-reject.sh <<EOF
#! nix --no-write-lock-file --command bash #! nix --no-write-lock-file --command bash
foo foo
EOF EOF
chmod +x $scriptDir/shebang-reject.sh chmod +x "$scriptDir/shebang-reject.sh"
cat > $scriptDir/shebang-inline-expr.sh <<EOF cat > "$scriptDir/shebang-inline-expr.sh" <<EOF
#! $(type -P env) nix #! $(type -P env) nix
EOF EOF
cat >> $scriptDir/shebang-inline-expr.sh <<"EOF" cat >> "$scriptDir/shebang-inline-expr.sh" <<"EOF"
#! nix --offline shell #! nix --offline shell
#! nix --impure --expr `` #! nix --impure --expr ``
#! nix let flake = (builtins.getFlake (toString ../flake1)).packages; #! nix let flake = (builtins.getFlake (toString ../flake1)).packages;
@ -81,18 +79,18 @@ set -ex
foo foo
echo "$@" echo "$@"
EOF EOF
chmod +x $scriptDir/shebang-inline-expr.sh chmod +x "$scriptDir/shebang-inline-expr.sh"
cat > $scriptDir/fooScript.nix <<"EOF" cat > "$scriptDir/fooScript.nix" <<"EOF"
let flake = (builtins.getFlake (toString ../flake1)).packages; let flake = (builtins.getFlake (toString ../flake1)).packages;
fooScript = flake.${builtins.currentSystem}.fooScript; fooScript = flake.${builtins.currentSystem}.fooScript;
in fooScript in fooScript
EOF EOF
cat > $scriptDir/shebang-file.sh <<EOF cat > "$scriptDir/shebang-file.sh" <<EOF
#! $(type -P env) nix #! $(type -P env) nix
EOF EOF
cat >> $scriptDir/shebang-file.sh <<"EOF" cat >> "$scriptDir/shebang-file.sh" <<"EOF"
#! nix --offline shell #! nix --offline shell
#! nix --impure --file ./fooScript.nix #! nix --impure --file ./fooScript.nix
#! nix --no-write-lock-file --command bash #! nix --no-write-lock-file --command bash
@ -100,12 +98,12 @@ set -ex
foo foo
echo "$@" echo "$@"
EOF EOF
chmod +x $scriptDir/shebang-file.sh chmod +x "$scriptDir/shebang-file.sh"
[[ $($scriptDir/shebang.sh) = "foo" ]] [[ $("$scriptDir/shebang.sh") = "foo" ]]
[[ $($scriptDir/shebang.sh "bar") = "foo"$'\n'"bar" ]] [[ $("$scriptDir/shebang.sh" "bar") = "foo"$'\n'"bar" ]]
[[ $($scriptDir/shebang-comments.sh ) = "foo" ]] [[ $("$scriptDir/shebang-comments.sh" ) = "foo" ]]
[[ "$($scriptDir/shebang-different-comments.sh)" = "$(cat $scriptDir/shebang-different-comments.sh)" ]] [[ "$("$scriptDir/shebang-different-comments.sh")" = "$(cat "$scriptDir/shebang-different-comments.sh")" ]]
[[ $($scriptDir/shebang-inline-expr.sh baz) = "foo"$'\n'"baz" ]] [[ $("$scriptDir/shebang-inline-expr.sh" baz) = "foo"$'\n'"baz" ]]
[[ $($scriptDir/shebang-file.sh baz) = "foo"$'\n'"baz" ]] [[ $("$scriptDir/shebang-file.sh" baz) = "foo"$'\n'"baz" ]]
expect 1 $scriptDir/shebang-reject.sh 2>&1 | grepQuiet -F 'error: unsupported unquoted character in nix shebang: *. Use double backticks to escape?' expect 1 "$scriptDir/shebang-reject.sh" 2>&1 | grepQuiet -F 'error: unsupported unquoted character in nix shebang: *. Use double backticks to escape?'