mirror of
https://github.com/NixOS/nix
synced 2025-07-07 22:33:57 +02:00
Merge pull request #11058 from hercules-ci/more-nix-shell
Make `#!nix-shell` arguments and options relative to script
This commit is contained in:
commit
1e1a8e8ad1
9 changed files with 133 additions and 3 deletions
|
@ -65,6 +65,25 @@ chmod a+rx $TEST_ROOT/shell.shebang.sh
|
|||
output=$($TEST_ROOT/shell.shebang.sh abc def)
|
||||
[ "$output" = "foo bar abc def" ]
|
||||
|
||||
# Test nix-shell shebang mode with an alternate working directory
|
||||
sed -e "s|@ENV_PROG@|$(type -P env)|" shell.shebang.expr > $TEST_ROOT/shell.shebang.expr
|
||||
chmod a+rx $TEST_ROOT/shell.shebang.expr
|
||||
# Should fail due to expressions using relative path
|
||||
! $TEST_ROOT/shell.shebang.expr bar
|
||||
cp shell.nix config.nix $TEST_ROOT
|
||||
# Should succeed
|
||||
echo "cwd: $PWD"
|
||||
output=$($TEST_ROOT/shell.shebang.expr bar)
|
||||
[ "$output" = foo ]
|
||||
|
||||
# Test nix-shell shebang mode with an alternate working directory
|
||||
sed -e "s|@ENV_PROG@|$(type -P env)|" shell.shebang.legacy.expr > $TEST_ROOT/shell.shebang.legacy.expr
|
||||
chmod a+rx $TEST_ROOT/shell.shebang.legacy.expr
|
||||
# Should fail due to expressions using relative path
|
||||
mkdir -p "$TEST_ROOT/somewhere-unrelated"
|
||||
output="$(cd "$TEST_ROOT/somewhere-unrelated"; $TEST_ROOT/shell.shebang.legacy.expr bar;)"
|
||||
[[ $(realpath "$output") = $(realpath "$TEST_ROOT/somewhere-unrelated") ]]
|
||||
|
||||
# Test nix-shell shebang mode again with metacharacters in the filename.
|
||||
# First word of filename is chosen to not match any file in the test root.
|
||||
sed -e "s|@ENV_PROG@|$(type -P env)|" shell.shebang.sh > $TEST_ROOT/spaced\ \\\'\"shell.shebang.sh
|
||||
|
|
|
@ -46,6 +46,7 @@ let pkgs = rec {
|
|||
ASCII_PERCENT = "%";
|
||||
ASCII_AT = "@";
|
||||
TEST_inNixShell = if inNixShell then "true" else "false";
|
||||
FOO = fooContents;
|
||||
inherit stdenv;
|
||||
outputs = ["dev" "out"];
|
||||
} // {
|
||||
|
|
9
tests/functional/shell.shebang.expr
Executable file
9
tests/functional/shell.shebang.expr
Executable file
|
@ -0,0 +1,9 @@
|
|||
#! @ENV_PROG@ nix-shell
|
||||
#! nix-shell "{ script, path, ... }: assert path == ./shell.nix; script { }"
|
||||
#! nix-shell --no-substitute
|
||||
#! nix-shell --expr
|
||||
#! nix-shell --arg script "import ./shell.nix"
|
||||
#! nix-shell --arg path "./shell.nix"
|
||||
#! nix-shell -A shellDrv
|
||||
#! nix-shell -i bash
|
||||
echo "$FOO"
|
10
tests/functional/shell.shebang.legacy.expr
Executable file
10
tests/functional/shell.shebang.legacy.expr
Executable file
|
@ -0,0 +1,10 @@
|
|||
#! @ENV_PROG@ nix-shell
|
||||
#! nix-shell "{ script, path, ... }: assert path == ./shell.nix; script { fooContents = toString ./.; }"
|
||||
#! nix-shell --no-substitute
|
||||
#! nix-shell --expr
|
||||
#! nix-shell --arg script "import ((builtins.getEnv ''TEST_ROOT'')+''/shell.nix'')"
|
||||
#! nix-shell --arg path "./shell.nix"
|
||||
#! nix-shell -A shellDrv
|
||||
#! nix-shell -i bash
|
||||
#! nix-shell --option nix-shell-shebang-arguments-relative-to-script false
|
||||
echo "$FOO"
|
Loading…
Add table
Add a link
Reference in a new issue