Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/helpers.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function run() {
# run:1: command not found: a-non-existent-command
# It would be skipped otherwise, i.e. "run: command ..." would be printed
IFS=$'\n' eval "output=\$( function run {
${cmd[@]/(#m)*/${${${${${(M)MATCH:#(${(j:|:)~dont_quote})}:+$MATCH}}:-\"${MATCH//(#b)([\"\`\\])/\\${match[1]}}\"}}} 2>&1 }; run )";
${cmd[@]/(#m)*/${${${${${(M)MATCH:#(${(j:|:)~dont_quote})}:+$MATCH}}:-\"${MATCH//(#b)([\"\`\\$])/\\${match[1]}}\"}}} 2>&1 }; run )";

# Get the process exit state
state="$?"
Expand Down Expand Up @@ -163,7 +163,7 @@ function evl() {
# It would be skipped otherwise, i.e. "eval: command ..." would be printed.
# This is to maintain consistency with the messages printed from run().
IFS=$'\n' builtin eval "function __eval {
${___cmd[@]/(#m)*/${${${${${(M)MATCH:#(${(j:|:)~___dont_quote})}:+$MATCH}}:-\"${MATCH//(#b)([\"\`\\])/\\${match[1]}}\"}}} \
${___cmd[@]/(#m)*/${${${${${(M)MATCH:#(${(j:|:)~___dont_quote})}:+$MATCH}}:-\"${MATCH//(#b)([\"\`\\$])/\\${match[1]}}\"}}} \
}; __eval >!$___OUTFILE 2>&1";

# Get the process exit state
Expand Down
18 changes: 18 additions & 0 deletions tests/run.zunit
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,21 @@
assert $state equals 127
assert $output matches 'run:[0-9]+: command not found: a-non-existent-command'
}

@test 'Command parameters expand in the command shell, not the ZUnit shell' {
# The command is built as text and evaluated, so every word that is not a
# shell operator gets requoted. If `$' is not escaped there, the ZUnit shell
# expands it first and the command sees an empty value. Regression test for
# issue #24.
run zsh -f -c 'typeset inner=INNER_VALUE; print -r -- "got=[${inner}]"'

assert $state equals 0
assert "$output" contains 'got=[INNER_VALUE]'
}

@test 'A var= assignment reaches the command shell intact' {
run env SOME_ISSUE_24_VAR=xyz zsh -f -c 'print -r -- "v=$SOME_ISSUE_24_VAR"'

assert $state equals 0
assert "$output" contains 'v=xyz'
}
Loading