Skip to content

Commit

Permalink
tests: test nix-shell shebang quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
ncfavier authored and roberth committed Oct 23, 2023
1 parent 595010b commit e053eeb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/functional/nix-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ chmod a+rx $TEST_ROOT/spaced\ \\\'\"shell.shebang.rb
output=$($TEST_ROOT/spaced\ \\\'\"shell.shebang.rb abc ruby)
[ "$output" = '-e load(ARGV.shift) -- '"$TEST_ROOT"'/spaced \'\''"shell.shebang.rb abc ruby' ]

# Test nix-shell shebang quoting
sed -e "s|@ENV_PROG@|$(type -P env)|" shell.shebang.nix > $TEST_ROOT/shell.shebang.nix
chmod a+rx $TEST_ROOT/shell.shebang.nix
$TEST_ROOT/shell.shebang.nix

# Test 'nix develop'.
nix develop -f "$shellDotNix" shellDrv -c bash -c '[[ -n $stdenv ]]'

Expand Down
10 changes: 10 additions & 0 deletions tests/functional/shell.shebang.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! @ENV_PROG@ nix-shell
#! nix-shell -I nixpkgs=shell.nix --no-substitute
#! nix-shell --argstr s1 'foo "bar" \baz'"'"'qux' --argstr s2 "foo 'bar' \"\baz" --argstr s3 \foo\ bar\'baz --argstr s4 ''
#! nix-shell shell.shebang.nix --command true
{ s1, s2, s3, s4 }:
assert s1 == ''foo "bar" \baz'qux'';
assert s2 == "foo 'bar' \"baz";
assert s3 == "foo bar'baz";
assert s4 == "";
(import <nixpkgs> {}).runCommand "nix-shell" {} ""

0 comments on commit e053eeb

Please sign in to comment.