Rename nonFlakeDir -> scriptDir

This commit is contained in:
Eelco Dolstra 2024-11-20 18:23:20 +01:00
parent 5533b0c735
commit fd2df5f02f

View File

@ -7,15 +7,15 @@ TODO_NixOS
requireGit requireGit
flake1Dir=$TEST_ROOT/flake1 flake1Dir=$TEST_ROOT/flake1
nonFlakeDir=$TEST_ROOT/nonFlake scriptDir=$TEST_ROOT/nonFlake
createGitRepo "$flake1Dir" "" createGitRepo "$flake1Dir" ""
createSimpleGitFlake "$flake1Dir" createSimpleGitFlake "$flake1Dir"
nix registry add --registry "$registry" flake1 "git+file://$flake1Dir" nix registry add --registry "$registry" flake1 "git+file://$flake1Dir"
mkdir -p "$nonFlakeDir" mkdir -p "$scriptDir"
cat > "$nonFlakeDir/shebang.sh" <<EOF cat > "$scriptDir/shebang.sh" <<EOF
#! $(type -P env) nix #! $(type -P env) nix
#! nix --offline shell #! nix --offline shell
#! nix flake1#fooScript #! nix flake1#fooScript
@ -24,12 +24,12 @@ set -ex
foo foo
echo "\$@" echo "\$@"
EOF EOF
chmod +x "$nonFlakeDir/shebang.sh" chmod +x "$scriptDir/shebang.sh"
#git -C "$nonFlakeDir" add 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 > $nonFlakeDir/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
@ -39,9 +39,9 @@ cat > $nonFlakeDir/shebang-comments.sh <<EOF
#! nix --no-write-lock-file ``--command`` bash #! nix --no-write-lock-file ``--command`` bash
foo foo
EOF EOF
chmod +x $nonFlakeDir/shebang-comments.sh chmod +x $scriptDir/shebang-comments.sh
cat > $nonFlakeDir/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
@ -57,9 +57,9 @@ cat > $nonFlakeDir/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 $nonFlakeDir/shebang-different-comments.sh chmod +x $scriptDir/shebang-different-comments.sh
cat > $nonFlakeDir/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
@ -69,12 +69,12 @@ cat > $nonFlakeDir/shebang-reject.sh <<EOF
#! nix --no-write-lock-file --command bash #! nix --no-write-lock-file --command bash
foo foo
EOF EOF
chmod +x $nonFlakeDir/shebang-reject.sh chmod +x $scriptDir/shebang-reject.sh
cat > $nonFlakeDir/shebang-inline-expr.sh <<EOF cat > $scriptDir/shebang-inline-expr.sh <<EOF
#! $(type -P env) nix #! $(type -P env) nix
EOF EOF
cat >> $nonFlakeDir/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;
@ -87,18 +87,18 @@ set -ex
foo foo
echo "$@" echo "$@"
EOF EOF
chmod +x $nonFlakeDir/shebang-inline-expr.sh chmod +x $scriptDir/shebang-inline-expr.sh
cat > $nonFlakeDir/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 > $nonFlakeDir/shebang-file.sh <<EOF cat > $scriptDir/shebang-file.sh <<EOF
#! $(type -P env) nix #! $(type -P env) nix
EOF EOF
cat >> $nonFlakeDir/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
@ -106,12 +106,12 @@ set -ex
foo foo
echo "$@" echo "$@"
EOF EOF
chmod +x $nonFlakeDir/shebang-file.sh chmod +x $scriptDir/shebang-file.sh
[[ $($nonFlakeDir/shebang.sh) = "foo" ]] [[ $($scriptDir/shebang.sh) = "foo" ]]
[[ $($nonFlakeDir/shebang.sh "bar") = "foo"$'\n'"bar" ]] [[ $($scriptDir/shebang.sh "bar") = "foo"$'\n'"bar" ]]
[[ $($nonFlakeDir/shebang-comments.sh ) = "foo" ]] [[ $($scriptDir/shebang-comments.sh ) = "foo" ]]
[[ "$($nonFlakeDir/shebang-different-comments.sh)" = "$(cat $nonFlakeDir/shebang-different-comments.sh)" ]] [[ "$($scriptDir/shebang-different-comments.sh)" = "$(cat $scriptDir/shebang-different-comments.sh)" ]]
[[ $($nonFlakeDir/shebang-inline-expr.sh baz) = "foo"$'\n'"baz" ]] [[ $($scriptDir/shebang-inline-expr.sh baz) = "foo"$'\n'"baz" ]]
[[ $($nonFlakeDir/shebang-file.sh baz) = "foo"$'\n'"baz" ]] [[ $($scriptDir/shebang-file.sh baz) = "foo"$'\n'"baz" ]]
expect 1 $nonFlakeDir/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?'