From f905690898c36c35df6d5804c39b1e91e70aa633 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sun, 6 Nov 2016 23:01:42 +0100 Subject: [PATCH] env_parallel.{bash,fish,ksh,zsh} fixes + testsuite. --- src/env_parallel.bash | 4 +- src/env_parallel.fish | 12 +++- src/env_parallel.ksh | 4 +- src/env_parallel.zsh | 4 +- testsuite/tests-to-run/parallel-local-ssh7.sh | 56 +++++++++++++++++++ testsuite/wanted-results/parallel-local-ssh7 | 36 +++++++++--- 6 files changed, 103 insertions(+), 13 deletions(-) diff --git a/src/env_parallel.bash b/src/env_parallel.bash index 8f86db45..b06ebbce 100755 --- a/src/env_parallel.bash +++ b/src/env_parallel.bash @@ -65,7 +65,9 @@ env_parallel() { # --record-env if ! perl -e 'exit grep { /^--record-env$/ } @ARGV' -- "$@"; then - (compgen -a; compgen -A function; compgen -A variable) | + (compgen -a; + compgen -A function; + compgen -A variable) | cat > $HOME/.parallel/ignored_vars return 0 fi diff --git a/src/env_parallel.fish b/src/env_parallel.fish index 1ab2d723..c5c87853 100755 --- a/src/env_parallel.fish +++ b/src/env_parallel.fish @@ -79,12 +79,20 @@ function env_parallel end; ) + # --record-env + perl -e 'exit grep { /^--record-env$/ } @ARGV' -- $argv; or begin; + begin; + functions -n | perl -pe 's/,/\n/g'; + set -n; + end | cat > $HOME/.parallel/ignored_vars; + end; + # Export function definitions functions -n | perl -pe 's/,/\n/g' | grep -E "^$_grep_REGEXP"\$ | grep -vE "^$_ignore_UNDERSCORE"\$ | while read d; functions $d; end; # Convert scalar vars to fish \XX quoting eval (set -L | grep -E "^$_grep_REGEXP " | grep -vE "^$_ignore_UNDERSCORE " | perl -ne 'chomp; ($name,$val)=split(/ /,$_,2); - $name=~/^(HOME|USER|COLUMNS|FISH_VERSION|LINES|PWD|SHLVL|_|history|status|version)$/ and next; + $name=~/^(HOME|USER|COLUMNS|FISH_VERSION|LINES|PWD|SHLVL|_|history|status|version)$|\./ and next; if($val=~/^'"'"'/) { next; } print "set $name \"\$$name\";\n"; ') @@ -127,7 +135,7 @@ function env_parallel end |perl -pe 's/\001/\\cb/g and print STDERR "env_parallel: Warning: ASCII value 1 in variables is not supported\n"; s/\n/\001/' ) - parallel $argv; + perl -e 'exit grep { /^--record-env$/ } @ARGV' -- $argv; and parallel $argv; set _parallel_exit_CODE $status set -e PARALLEL_ENV return $_parallel_exit_CODE diff --git a/src/env_parallel.ksh b/src/env_parallel.ksh index fb59238c..54841e2c 100755 --- a/src/env_parallel.ksh +++ b/src/env_parallel.ksh @@ -65,7 +65,9 @@ env_parallel() { # --record-env if ! perl -e 'exit grep { /^--record-env$/ } @ARGV' -- "$@"; then - (compgen -a; compgen -A function; compgen -A variable) | + (alias | perl -pe 's/=.*//'; + typeset +p -f | perl -pe 's/\(\).*//'; + typeset +p | perl -pe 's/^typeset .. //') | cat > $HOME/.parallel/ignored_vars return 0 fi diff --git a/src/env_parallel.zsh b/src/env_parallel.zsh index a43c4dfa..9385fe95 100755 --- a/src/env_parallel.zsh +++ b/src/env_parallel.zsh @@ -65,7 +65,9 @@ env_parallel() { # --record-env if ! perl -e 'exit grep { /^--record-env$/ } @ARGV' -- "$@"; then - (compgen -a; compgen -A function; compgen -A variable) | + (print -l ${(k)aliases}; + print -l ${(k)functions}; + print -l ${(k)parameters}) | cat > $HOME/.parallel/ignored_vars return 0 fi diff --git a/testsuite/tests-to-run/parallel-local-ssh7.sh b/testsuite/tests-to-run/parallel-local-ssh7.sh index 5676bdb1..43755189 100755 --- a/testsuite/tests-to-run/parallel-local-ssh7.sh +++ b/testsuite/tests-to-run/parallel-local-ssh7.sh @@ -4,6 +4,10 @@ echo '### test --env _' echo 'Both test that variables are copied,' echo 'but also that they are NOT copied, if ignored' +# +## par_*_man = tests from the man page +# + par_bash_man() { echo '### bash' @@ -289,6 +293,10 @@ _EOF } +# +## par_*_underscore = tests with --env _ +# + par_bash_underscore() { echo '### bash' myscript=$(cat <<'_EOF' @@ -296,6 +304,10 @@ par_bash_underscore() { . `which env_parallel.bash`; + alias not_copied_alias="echo BAD" + not_copied_func() { echo BAD; }; + not_copied_var=BAD + not_copied_array=(BAD BAD BAD); env_parallel --record-env; alias myecho="echo \$myvar aliases in"; myfunc() { myecho ${myarray[@]} functions $*; }; @@ -308,6 +320,11 @@ par_bash_underscore() { env_parallel --env _ myfunc ::: work; env_parallel --env _ -S server myfunc ::: work; + env_parallel --env _ -S server not_copied_alias ::: error=OK; + env_parallel --env _ -S server not_copied_func ::: error=OK; + env_parallel --env _ -S server echo \$not_copied_var ::: error=OK; + env_parallel --env _ -S server echo \${not_copied_array[@]} ::: error=OK; + echo myvar >> ~/.parallel/ignored_vars; env_parallel --env _ myfunc ::: work; env_parallel --env _ -S server myfunc ::: work; @@ -336,6 +353,10 @@ par_zsh_underscore() { . `which env_parallel.zsh`; + alias not_copied_alias="echo BAD" + not_copied_func() { echo BAD; }; + not_copied_var=BAD + not_copied_array=(BAD BAD BAD); env_parallel --record-env; alias myecho="echo \$myvar aliases in"; eval `cat <<"_EOS"; @@ -349,6 +370,11 @@ par_zsh_underscore() { env_parallel --env _ myfunc ::: work; env_parallel --env _ -S server myfunc ::: work; + env_parallel --env _ -S server not_copied_alias ::: error=OK; + env_parallel --env _ -S server not_copied_func ::: error=OK; + env_parallel --env _ -S server echo \$not_copied_var ::: error=OK; + env_parallel --env _ -S server echo \$\{not_copied_array\[\@\]\} ::: error=OK; + echo myvar >> ~/.parallel/ignored_vars; env_parallel --env _ myfunc ::: work; env_parallel --env _ -S server myfunc ::: work; @@ -377,6 +403,10 @@ par_ksh_underscore() { myscript=$(cat <<'_EOF' echo "### Testing of --env _" + alias not_copied_alias="echo BAD" + not_copied_func() { echo BAD; }; + not_copied_var=BAD + not_copied_array=(BAD BAD BAD); . `which env_parallel.ksh`; env_parallel --record-env; alias myecho="echo \$myvar aliases in"; @@ -390,6 +420,11 @@ par_ksh_underscore() { env_parallel --env _ myfunc ::: work; env_parallel --env _ -S server myfunc ::: work; + env_parallel --env _ -S server not_copied_alias ::: error=OK; + env_parallel --env _ -S server not_copied_func ::: error=OK; + env_parallel --env _ -S server echo \$not_copied_var ::: error=OK; + env_parallel --env _ -S server echo \${not_copied_array[@]} ::: error=OK; + echo myvar >> ~/.parallel/ignored_vars; env_parallel --env _ myfunc ::: work; env_parallel --env _ -S server myfunc ::: work; @@ -416,6 +451,10 @@ _disabled_pdksh_underscore() { myscript=$(cat <<'_EOF' echo "### Testing of --env _" + alias not_copied_alias="echo BAD" + not_copied_func() { echo BAD; }; + not_copied_var=BAD + not_copied_array=(BAD BAD BAD); . `which env_parallel.pdksh`; env_parallel --record-env; alias myecho="echo \$myvar aliases in"; @@ -429,6 +468,11 @@ _disabled_pdksh_underscore() { env_parallel --env _ myfunc ::: work; env_parallel --env _ -S server myfunc ::: work; + env_parallel --env _ -S server not_copied_alias ::: error=OK; + env_parallel --env _ -S server not_copied_func ::: error=OK; + env_parallel --env _ -S server echo \$not_copied_var ::: error=OK; + env_parallel --env _ -S server echo \${not_copied_array[@]} ::: error=OK; + echo myvar >> ~/.parallel/ignored_vars; env_parallel --env _ myfunc ::: work; env_parallel --env _ -S server myfunc ::: work; @@ -526,6 +570,13 @@ par_fish_underscore() { echo "### Testing of --env _" # . `which env_parallel.fish`; + + alias not_copied_alias="echo BAD" + function not_copied_func + echo BAD + end + set not_copied_var "BAD"; + set not_copied_array BAD BAD BAD; env_parallel --record-env; alias myecho="echo \$myvar aliases"; function myfunc @@ -540,6 +591,11 @@ par_fish_underscore() { env_parallel --env _ myfunc ::: work; env_parallel --env _ -S server myfunc ::: work; + env_parallel --env _ -S server not_copied_alias ::: error=OK; + env_parallel --env _ -S server not_copied_func ::: error=OK; + env_parallel --env _ -S server echo \$not_copied_var ::: error=OK; + env_parallel --env _ -S server echo \$not_copied_array ::: error=OK; + echo myvar >> ~/.parallel/ignored_vars; env_parallel --env _ myfunc ::: work; env_parallel --env _ -S server myfunc ::: work; diff --git a/testsuite/wanted-results/parallel-local-ssh7 b/testsuite/wanted-results/parallel-local-ssh7 index 44e7875c..ba854598 100644 --- a/testsuite/wanted-results/parallel-local-ssh7 +++ b/testsuite/wanted-results/parallel-local-ssh7 @@ -61,17 +61,21 @@ par_bash_underscore variables in aliases in and arrays in functions work par_bash_underscore variables in aliases in and arrays in functions work par_bash_underscore variables in aliases in and arrays in functions work par_bash_underscore variables in aliases in and arrays in functions work +par_bash_underscore /bin/bash: line 57: not_copied_alias: command not found +par_bash_underscore /bin/bash: line 57: not_copied_func: command not found +par_bash_underscore error=OK +par_bash_underscore error=OK par_bash_underscore aliases in and arrays in functions work par_bash_underscore aliases in and arrays in functions work par_bash_underscore aliases in functions work par_bash_underscore aliases in functions work -par_bash_underscore /bin/bash: line 71: myecho: command not found +par_bash_underscore /bin/bash: line 52: myecho: command not found par_bash_underscore OK if no myecho ^^^^^^^^^^^^^^^^^^^^^^^^^ -par_bash_underscore /bin/bash: line 71: myecho: command not found +par_bash_underscore /bin/bash: line 52: myecho: command not found par_bash_underscore OK if no myecho ^^^^^^^^^^^^^^^^^^^^^^^^^ -par_bash_underscore /bin/bash: line 69: myfunc: command not found +par_bash_underscore /bin/bash: line 50: myfunc: command not found par_bash_underscore OK if no myfunc ^^^^^^^^^^^^^^^^^^^^^^^^^ -par_bash_underscore /bin/bash: line 69: myfunc: command not found +par_bash_underscore /bin/bash: line 50: myfunc: command not found par_bash_underscore OK if no myfunc ^^^^^^^^^^^^^^^^^^^^^^^^^ par_csh_funky 3 arg alias_works par_csh_funky myvar works @@ -237,6 +241,14 @@ par_fish_underscore variables in aliases and arrays in functions work par_fish_underscore variables in aliases and arrays in functions work par_fish_underscore variables in aliases and arrays in functions work par_fish_underscore variables in aliases and arrays in functions work +par_fish_underscore fish: Unknown command 'not_copied_alias error=OK' +par_fish_underscore fish: not_copied_alias error\=OK +par_fish_underscore ^ +par_fish_underscore fish: Unknown command 'not_copied_func error=OK' +par_fish_underscore fish: not_copied_func error\=OK +par_fish_underscore ^ +par_fish_underscore error=OK +par_fish_underscore error=OK par_fish_underscore aliases and arrays in functions work par_fish_underscore aliases and arrays in functions work par_fish_underscore aliases functions work @@ -319,17 +331,21 @@ par_ksh_underscore variables in aliases in and arrays in functions work par_ksh_underscore variables in aliases in and arrays in functions work par_ksh_underscore variables in aliases in and arrays in functions work par_ksh_underscore variables in aliases in and arrays in functions work +par_ksh_underscore /usr/bin/ksh: line 8: not_copied_alias: not found +par_ksh_underscore /usr/bin/ksh: line 8: not_copied_func: not found +par_ksh_underscore error=OK +par_ksh_underscore error=OK par_ksh_underscore aliases in and arrays in functions work par_ksh_underscore aliases in and arrays in functions work par_ksh_underscore aliases in functions work par_ksh_underscore aliases in functions work -par_ksh_underscore /usr/bin/ksh[114]: myecho: not found [No such file or directory] +par_ksh_underscore /usr/bin/ksh[4]: myecho: not found [No such file or directory] par_ksh_underscore OK if no myecho ^^^^^^^^^^^^^^^^^ -par_ksh_underscore /usr/bin/ksh[114]: myecho: not found [No such file or directory] +par_ksh_underscore /usr/bin/ksh[4]: myecho: not found [No such file or directory] par_ksh_underscore OK if no myecho ^^^^^^^^^^^^^^^^^ -par_ksh_underscore /usr/bin/ksh: line 114: myfunc: not found +par_ksh_underscore /usr/bin/ksh: line 4: myfunc: not found par_ksh_underscore OK if no myfunc ^^^^^^^^^^^^^^^^^ -par_ksh_underscore /usr/bin/ksh: line 114: myfunc: not found +par_ksh_underscore /usr/bin/ksh: line 4: myfunc: not found par_ksh_underscore OK if no myfunc ^^^^^^^^^^^^^^^^^ par_tcsh_funky par_tcsh_funky @@ -484,6 +500,10 @@ par_zsh_underscore variables in aliases in and arrays in functions work par_zsh_underscore variables in aliases in and arrays in functions work par_zsh_underscore variables in aliases in and arrays in functions work par_zsh_underscore variables in aliases in and arrays in functions work +par_zsh_underscore (eval):1: command not found: not_copied_alias +par_zsh_underscore (eval):1: command not found: not_copied_func +par_zsh_underscore BAD error=OK +par_zsh_underscore error=OK par_zsh_underscore aliases in and arrays in functions work par_zsh_underscore aliases in and arrays in functions work par_zsh_underscore aliases in functions work