mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 14:06:16 +02:00
Merge pull request #10337 from Cyclic4179/patch-1
`nix shell` shebang: support O'Caml comments
This commit is contained in:
commit
ef26133df3
2 changed files with 20 additions and 1 deletions
|
@ -285,7 +285,7 @@ void RootArgs::parseCmdline(const Strings & _cmdline, bool allowShebang)
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
std::getline(stream,line);
|
std::getline(stream,line);
|
||||||
static const std::string commentChars("#/\\%@*-");
|
static const std::string commentChars("#/\\%@*-(");
|
||||||
std::string shebangContent;
|
std::string shebangContent;
|
||||||
while (std::getline(stream,line) && !line.empty() && commentChars.find(line[0]) != std::string::npos){
|
while (std::getline(stream,line) && !line.empty() && commentChars.find(line[0]) != std::string::npos){
|
||||||
line = chomp(line);
|
line = chomp(line);
|
||||||
|
|
|
@ -93,6 +93,24 @@ foo
|
||||||
EOF
|
EOF
|
||||||
chmod +x $nonFlakeDir/shebang-comments.sh
|
chmod +x $nonFlakeDir/shebang-comments.sh
|
||||||
|
|
||||||
|
cat > $nonFlakeDir/shebang-different-comments.sh <<EOF
|
||||||
|
#! $(type -P env) nix
|
||||||
|
# some comments
|
||||||
|
// some comments
|
||||||
|
/* some comments
|
||||||
|
* some comments
|
||||||
|
\ some comments
|
||||||
|
% some comments
|
||||||
|
@ some comments
|
||||||
|
-- some comments
|
||||||
|
(* some comments
|
||||||
|
#! nix --offline shell
|
||||||
|
#! nix flake1#fooScript
|
||||||
|
#! nix --no-write-lock-file --command cat
|
||||||
|
foo
|
||||||
|
EOF
|
||||||
|
chmod +x $nonFlakeDir/shebang-different-comments.sh
|
||||||
|
|
||||||
cat > $nonFlakeDir/shebang-reject.sh <<EOF
|
cat > $nonFlakeDir/shebang-reject.sh <<EOF
|
||||||
#! $(type -P env) nix
|
#! $(type -P env) nix
|
||||||
# some comments
|
# some comments
|
||||||
|
@ -607,6 +625,7 @@ expectStderr 1 nix flake metadata "$flake2Dir" --no-allow-dirty --reference-lock
|
||||||
[[ $($nonFlakeDir/shebang.sh) = "foo" ]]
|
[[ $($nonFlakeDir/shebang.sh) = "foo" ]]
|
||||||
[[ $($nonFlakeDir/shebang.sh "bar") = "foo"$'\n'"bar" ]]
|
[[ $($nonFlakeDir/shebang.sh "bar") = "foo"$'\n'"bar" ]]
|
||||||
[[ $($nonFlakeDir/shebang-comments.sh ) = "foo" ]]
|
[[ $($nonFlakeDir/shebang-comments.sh ) = "foo" ]]
|
||||||
|
[[ "$($nonFlakeDir/shebang-different-comments.sh)" = "$(cat $nonFlakeDir/shebang-different-comments.sh)" ]]
|
||||||
[[ $($nonFlakeDir/shebang-inline-expr.sh baz) = "foo"$'\n'"baz" ]]
|
[[ $($nonFlakeDir/shebang-inline-expr.sh baz) = "foo"$'\n'"baz" ]]
|
||||||
[[ $($nonFlakeDir/shebang-file.sh baz) = "foo"$'\n'"baz" ]]
|
[[ $($nonFlakeDir/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 $nonFlakeDir/shebang-reject.sh 2>&1 | grepQuiet -F 'error: unsupported unquoted character in nix shebang: *. Use double backticks to escape?'
|
||||||
|
|
Loading…
Reference in a new issue