Skip to content

Commit

Permalink
Add srcenv Csh/Tcsh init
Browse files Browse the repository at this point in the history
  • Loading branch information
ins0mniaque committed Dec 10, 2024
1 parent bf8ccfe commit a522626
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 52 deletions.
8 changes: 6 additions & 2 deletions srcenv
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,12 @@ init() {
bash|\
ksh|pdksh|mksh|\
posix|sh|\
zsh) echo "$cmd() { eval \"\$($0 $shell $opts --cmd \"$cmd\" \"\$@\")\"; }" ;;
csh|tcsh|\
zsh) echo "$cmd() { eval \"\$($0 $shell $opts --cmd \"$cmd\" \"\$@\")\"; }" ;;
csh|tcsh) if [ -e /dev/stdin ]; then
echo "alias $cmd '$0 $shell $opts --cmd \"$cmd\" \!* | source /dev/stdin'"
else
echo "alias $cmd 'set mktemp = \"\`mktemp\`\"; $0 $shell $opts --cmd \"$cmd\" \!* > \"\$mktemp\"; source \"\$mktemp\"; rm -f \"\$mktemp\"'"
fi ;;
elvish|\
fish|\
murex|\
Expand Down
133 changes: 83 additions & 50 deletions srcenv.tests
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,44 @@ snapshot=$(jq -n env); eval "$(./srcenv %s --backup)"; eval "$(./srcenv %s --res
jq %s --argjson snapshot "$snapshot" -n
EOF

{ csh_script="$(cat) '$diff'"; } << 'EOF'
if [ -e /dev/stdin ]; then
{ csh_script="$(cat) '$diff'"; } << 'EOF'
set snapshot = "`jq -n env`"; ./srcenv %s | source /dev/stdin
jq %s --argjson snapshot "$snapshot:q" -n
EOF

{ csh_restore_script="$(cat) '$diff'"; } << 'EOF'
{ csh_init_script="$(cat) '$diff'"; } << 'EOF'
./srcenv init %s | source /dev/stdin
set snapshot = "`jq -n env`"
src %s
jq %s --argjson snapshot "$snapshot:q" -n
EOF

{ csh_restore_script="$(cat) '$diff'"; } << 'EOF'
set snapshot = "`jq -n env`"; ./srcenv %s --backup | source /dev/stdin; ./srcenv %s --restore | source /dev/stdin
jq %s --argjson snapshot "$snapshot:q" -n
EOF
else
{ csh_script="$(cat) '$diff'"; } << 'EOF'
set snapshot = "`jq -n env`"; ./srcenv %s > nostdin.csh; source nostdin.csh
rm -f nostdin.csh
jq %s --argjson snapshot "$snapshot:q" -n
EOF

{ csh_init_script="$(cat) '$diff'"; } << 'EOF'
./srcenv init %s > nostdin.csh; source nostdin.csh
rm -f nostdin.csh
set snapshot = "`jq -n env`"
src %s
jq %s --argjson snapshot "$snapshot:q" -n
EOF

{ csh_restore_script="$(cat) '$diff'"; } << 'EOF'
set snapshot = "`jq -n env`"; ./srcenv %s --backup > nostdin.csh; source nostdin.csh; ./srcenv %s --restore > nostdin.csh; source nostdin.csh
rm -f nostdin.csh
jq %s --argjson snapshot "$snapshot:q" -n
EOF
fi

{ elvish_script="$(cat) '$diff'"; } << 'EOF'
var snapshot = (jq -n env | slurp); eval (./srcenv %s | slurp)
Expand Down Expand Up @@ -748,114 +777,118 @@ script() {

sh=$(detect sh) || msg warn 'sh not found; skipping tests...'
run_posix_tests "$sh" "sh srcenv"
run "$sh" "sh -c $(script "$posix_script" 'sh test.env' )" "$json_output"
run "$sh" "sh -c $(script "$posix_script" 'sh test.env.sh' )" "$json_output"
run "$sh" "sh -c $(script "$posix_init_script" 'sh' 'test.env' )" "$json_backup_output"
run "$sh" "sh -c $(script "$posix_init_script" 'sh' 'test.env.sh' )" "$json_backup_output"
run "$sh" "sh -c $(script "$posix_script" 'sh test.env' )" "$json_output"
run "$sh" "sh -c $(script "$posix_script" 'sh test.env.sh' )" "$json_output"
run "$sh" "sh -c $(script "$posix_init_script" 'sh' 'test.env' )" "$json_backup_output"
run "$sh" "sh -c $(script "$posix_init_script" 'sh' 'test.env.sh' )" "$json_backup_output"
run "$sh" "sh -c $(script "$posix_restore_script" 'sh test.env' 'sh')" '{}'
run "$sh" "sh -c $(script "$posix_restore_script" 'sh test.env.sh' 'sh')" '{}'

ash=$(detect ash) || msg warn 'Ash not found; skipping tests...'
run_posix_tests "$ash" "ash srcenv"
run "$ash" "ash -c $(script "$posix_script" 'ash test.env' )" "$json_output"
run "$ash" "ash -c $(script "$posix_script" 'ash test.env.sh' )" "$json_output"
run "$ash" "ash -c $(script "$posix_init_script" 'ash' 'test.env' )" "$json_backup_output"
run "$ash" "ash -c $(script "$posix_init_script" 'ash' 'test.env.sh' )" "$json_backup_output"
run "$ash" "ash -c $(script "$posix_script" 'ash test.env' )" "$json_output"
run "$ash" "ash -c $(script "$posix_script" 'ash test.env.sh' )" "$json_output"
run "$ash" "ash -c $(script "$posix_init_script" 'ash' 'test.env' )" "$json_backup_output"
run "$ash" "ash -c $(script "$posix_init_script" 'ash' 'test.env.sh' )" "$json_backup_output"
run "$ash" "ash -c $(script "$posix_restore_script" 'ash test.env' 'ash')" '{}'
run "$ash" "ash -c $(script "$posix_restore_script" 'ash test.env.sh' 'ash')" '{}'

bash=$(detect bash) || msg warn 'Bash not found; skipping tests...'
run_posix_tests "$bash" "bash srcenv"
run "$bash" "bash -c $(script "$posix_script" 'bash test.env' )" "$json_output"
run "$bash" "bash -c $(script "$posix_script" 'bash test.env.sh' )" "$json_output"
run "$bash" "bash -c $(script "$posix_init_script" 'bash' 'test.env' )" "$json_backup_output"
run "$bash" "bash -c $(script "$posix_init_script" 'bash' 'test.env.sh' )" "$json_backup_output"
run "$bash" "bash -c $(script "$posix_script" 'bash test.env' )" "$json_output"
run "$bash" "bash -c $(script "$posix_script" 'bash test.env.sh' )" "$json_output"
run "$bash" "bash -c $(script "$posix_init_script" 'bash' 'test.env' )" "$json_backup_output"
run "$bash" "bash -c $(script "$posix_init_script" 'bash' 'test.env.sh' )" "$json_backup_output"
run "$bash" "bash -c $(script "$posix_restore_script" 'bash test.env' 'bash')" '{}'
run "$bash" "bash -c $(script "$posix_restore_script" 'bash test.env.sh' 'bash')" '{}'

dash=$(detect dash) || msg warn 'Dash not found; skipping tests...'
run_posix_tests "$dash" "dash srcenv"
run "$dash" "dash -c $(script "$posix_script" 'dash test.env' )" "$json_output"
run "$dash" "dash -c $(script "$posix_script" 'dash test.env.sh' )" "$json_output"
run "$dash" "dash -c $(script "$posix_init_script" 'dash' 'test.env' )" "$json_backup_output"
run "$dash" "dash -c $(script "$posix_init_script" 'dash' 'test.env.sh' )" "$json_backup_output"
run "$dash" "dash -c $(script "$posix_script" 'dash test.env' )" "$json_output"
run "$dash" "dash -c $(script "$posix_script" 'dash test.env.sh' )" "$json_output"
run "$dash" "dash -c $(script "$posix_init_script" 'dash' 'test.env' )" "$json_backup_output"
run "$dash" "dash -c $(script "$posix_init_script" 'dash' 'test.env.sh' )" "$json_backup_output"
run "$dash" "dash -c $(script "$posix_restore_script" 'dash test.env' 'dash')" '{}'
run "$dash" "dash -c $(script "$posix_restore_script" 'dash test.env.sh' 'dash')" '{}'

ksh=$(detect ksh) || msg warn 'Ksh not found; skipping tests...'
run_posix_tests "$ksh" "ksh srcenv"
run "$ksh" "ksh -c $(script "$posix_script" 'ksh test.env' )" "$json_output"
run "$ksh" "ksh -c $(script "$posix_script" 'ksh test.env.sh' )" "$json_output"
run "$ksh" "ksh -c $(script "$posix_init_script" 'ksh' 'test.env' )" "$json_backup_output"
run "$ksh" "ksh -c $(script "$posix_init_script" 'ksh' 'test.env.sh' )" "$json_backup_output"
run "$ksh" "ksh -c $(script "$posix_script" 'ksh test.env' )" "$json_output"
run "$ksh" "ksh -c $(script "$posix_script" 'ksh test.env.sh' )" "$json_output"
run "$ksh" "ksh -c $(script "$posix_init_script" 'ksh' 'test.env' )" "$json_backup_output"
run "$ksh" "ksh -c $(script "$posix_init_script" 'ksh' 'test.env.sh' )" "$json_backup_output"
run "$ksh" "ksh -c $(script "$posix_restore_script" 'ksh test.env' 'ksh')" '{}'
run "$ksh" "ksh -c $(script "$posix_restore_script" 'ksh test.env.sh' 'ksh')" '{}'

mksh=$(detect mksh) || msg warn 'Mksh not found; skipping tests...'
run_posix_tests "$mksh" "mksh srcenv"
run "$mksh" "mksh -c $(script "$posix_script" 'mksh test.env' )" "$json_output"
run "$mksh" "mksh -c $(script "$posix_script" 'mksh test.env.sh' )" "$json_output"
run "$mksh" "mksh -c $(script "$posix_init_script" 'mksh' 'test.env' )" "$json_backup_output"
run "$mksh" "mksh -c $(script "$posix_init_script" 'mksh' 'test.env.sh' )" "$json_backup_output"
run "$mksh" "mksh -c $(script "$posix_script" 'mksh test.env' )" "$json_output"
run "$mksh" "mksh -c $(script "$posix_script" 'mksh test.env.sh' )" "$json_output"
run "$mksh" "mksh -c $(script "$posix_init_script" 'mksh' 'test.env' )" "$json_backup_output"
run "$mksh" "mksh -c $(script "$posix_init_script" 'mksh' 'test.env.sh' )" "$json_backup_output"
run "$mksh" "mksh -c $(script "$posix_restore_script" 'mksh test.env' 'mksh')" '{}'
run "$mksh" "mksh -c $(script "$posix_restore_script" 'mksh test.env.sh' 'mksh')" '{}'

zsh=$(detect zsh) || msg warn 'Zsh not found; skipping tests...'
run_posix_tests "$zsh" "zsh srcenv"
run "$zsh" "zsh -c $(script "$posix_script" 'zsh test.env' )" "$json_output"
run "$zsh" "zsh -c $(script "$posix_script" 'zsh test.env.sh' )" "$json_output"
run "$zsh" "zsh -c $(script "$posix_init_script" 'zsh' 'test.env' )" "$json_backup_output"
run "$zsh" "zsh -c $(script "$posix_init_script" 'zsh' 'test.env.sh' )" "$json_backup_output"
run "$zsh" "zsh -c $(script "$posix_script" 'zsh test.env' )" "$json_output"
run "$zsh" "zsh -c $(script "$posix_script" 'zsh test.env.sh' )" "$json_output"
run "$zsh" "zsh -c $(script "$posix_init_script" 'zsh' 'test.env' )" "$json_backup_output"
run "$zsh" "zsh -c $(script "$posix_init_script" 'zsh' 'test.env.sh' )" "$json_backup_output"
run "$zsh" "zsh -c $(script "$posix_restore_script" 'zsh test.env' 'zsh')" '{}'
run "$zsh" "zsh -c $(script "$posix_restore_script" 'zsh test.env.sh' 'zsh')" '{}'

csh=$(detect csh) || msg warn 'Csh not found; skipping tests...'
run "$csh" "csh -c $(script "$csh_script" 'csh test.env' )" "$json_output"
run "$csh" "csh -c $(script "$csh_script" 'csh test.env.sh' )" "$json_output"
run "$csh" "csh -c $(script "$csh_script" 'csh test.env' )" "$json_output"
run "$csh" "csh -c $(script "$csh_script" 'csh test.env.sh' )" "$json_output"
run "$csh" "csh -c $(script "$csh_init_script" 'csh' 'test.env' )" "$json_backup_output"
run "$csh" "csh -c $(script "$csh_init_script" 'csh' 'test.env.sh' )" "$json_backup_output"
run "$csh" "csh -c $(script "$csh_restore_script" 'csh test.env' 'csh')" '{}'
run "$csh" "csh -c $(script "$csh_restore_script" 'csh test.env.sh' 'csh')" '{}'

tcsh=$(detect tcsh) || msg warn 'Tcsh not found; skipping tests...'
run "$tcsh" "tcsh -c $(script "$csh_script" 'tcsh test.env' )" "$json_output"
run "$tcsh" "tcsh -c $(script "$csh_script" 'tcsh test.env.sh' )" "$json_output"
run "$tcsh" "tcsh -c $(script "$csh_script" 'tcsh test.env' )" "$json_output"
run "$tcsh" "tcsh -c $(script "$csh_script" 'tcsh test.env.sh' )" "$json_output"
run "$tcsh" "tcsh -c $(script "$csh_init_script" 'tcsh' 'test.env' )" "$json_backup_output"
run "$tcsh" "tcsh -c $(script "$csh_init_script" 'tcsh' 'test.env.sh' )" "$json_backup_output"
run "$tcsh" "tcsh -c $(script "$csh_restore_script" 'tcsh test.env' 'tcsh')" '{}'
run "$tcsh" "tcsh -c $(script "$csh_restore_script" 'tcsh test.env.sh' 'tcsh')" '{}'

elvish=$(detect elvish) || msg warn 'Elvish not found; skipping tests...'
run "$elvish" "elvish -c $(script "$elvish_script" 'elvish test.env' )" "$json_output"
run "$elvish" "elvish -c $(script "$elvish_script" 'elvish test.env.sh' )" "$json_output"
run "$elvish" "elvish -c $(script "$elvish_script" 'elvish test.env' )" "$json_output"
run "$elvish" "elvish -c $(script "$elvish_script" 'elvish test.env.sh' )" "$json_output"
run "$elvish" "elvish -c $(script "$elvish_restore_script" 'elvish test.env' 'elvish')" '{}'
run "$elvish" "elvish -c $(script "$elvish_restore_script" 'elvish test.env.sh' 'elvish')" '{}'

fish=$(detect fish) || msg warn 'Fish not found; skipping tests...'
run "$fish" "fish -c $(script "$fish_script" 'fish test.env' )" "$json_output"
run "$fish" "fish -c $(script "$fish_script" 'fish test.env.sh' )" "$json_output"
run "$fish" "fish -c $(script "$fish_script" 'fish test.env' )" "$json_output"
run "$fish" "fish -c $(script "$fish_script" 'fish test.env.sh' )" "$json_output"
run "$fish" "fish -c $(script "$fish_restore_script" 'fish test.env' 'fish')" '{}'
run "$fish" "fish -c $(script "$fish_restore_script" 'fish test.env.sh' 'fish')" '{}'

murex=$(detect murex) || msg warn 'Murex not found; skipping tests...'
run "$murex" "murex -c $(script "$murex_script" 'murex test.env' )" "$json_output"
run "$murex" "murex -c $(script "$murex_script" 'murex test.env.sh' )" "$json_output"
run "$murex" "murex -c $(script "$murex_script" 'murex test.env' )" "$json_output"
run "$murex" "murex -c $(script "$murex_script" 'murex test.env.sh' )" "$json_output"
run "$murex" "murex -c $(script "$murex_restore_script" 'murex test.env' 'murex')" '{}'
run "$murex" "murex -c $(script "$murex_restore_script" 'murex test.env.sh' 'murex')" '{}'

nu=$(detect nu) || msg warn 'Nushell not found; skipping tests...'
run "$nu" "nu -c $(script "$nu_setup_script" 'nu test.env' ); nu -c $(script "$nu_script")" "$json_output"
run "$nu" "nu -c $(script "$nu_setup_script" 'nu test.env.sh'); nu -c $(script "$nu_script")" "$json_output"
run "$nu" "nu -c $(script "$nu_json_script" 'json test.env' )" "$json_output"
run "$nu" "nu -c $(script "$nu_json_script" 'json test.env.sh' )" "$json_output"
run "$nu" "nu -c $(script "$nu_restore_script" 'json test.env' 'json')" '{}'
run "$nu" "nu -c $(script "$nu_restore_script" 'json test.env.sh' 'json')" '{}'
run "$nu" "nu -c $(script "$nu_setup_script" 'nu test.env' ); nu -c $(script "$nu_script")" "$json_output"
run "$nu" "nu -c $(script "$nu_setup_script" 'nu test.env.sh'); nu -c $(script "$nu_script")" "$json_output"
run "$nu" "nu -c $(script "$nu_json_script" 'json test.env' )" "$json_output"
run "$nu" "nu -c $(script "$nu_json_script" 'json test.env.sh' )" "$json_output"
run "$nu" "nu -c $(script "$nu_restore_script" 'json test.env' 'json')" '{}'
run "$nu" "nu -c $(script "$nu_restore_script" 'json test.env.sh' 'json')" '{}'

pwsh=$(detect pwsh) || msg warn 'PowerShell not found; skipping tests...'
run "$pwsh" "pwsh -c $(script "$pwsh_script" 'pwsh test.env' )" "$json_output"
run "$pwsh" "pwsh -c $(script "$pwsh_script" 'pwsh test.env.sh' )" "$json_output"
run "$pwsh" "pwsh -c $(script "$pwsh_script" 'pwsh test.env' )" "$json_output"
run "$pwsh" "pwsh -c $(script "$pwsh_script" 'pwsh test.env.sh' )" "$json_output"
run "$pwsh" "pwsh -c $(script "$pwsh_restore_script" 'pwsh test.env' 'pwsh')" '{}'
run "$pwsh" "pwsh -c $(script "$pwsh_restore_script" 'pwsh test.env.sh' 'pwsh')" '{}'

powershell=$(detect powershell) || msg warn 'Windows PowerShell not found; skipping tests...'
run "$powershell" "powershell -c $(script "$powershell_script" 'powershell test.env' )" "$json_output"
run "$powershell" "powershell -c $(script "$powershell_script" 'powershell test.env.sh' )" "$json_output"
run "$powershell" "powershell -c $(script "$powershell_script" 'powershell test.env' )" "$json_output"
run "$powershell" "powershell -c $(script "$powershell_script" 'powershell test.env.sh' )" "$json_output"
run "$powershell" "powershell -c $(script "$powershell_restore_script" 'powershell test.env' 'powershell')" '{}'
run "$powershell" "powershell -c $(script "$powershell_restore_script" 'powershell test.env.sh' 'powershell')" '{}'

Expand Down

0 comments on commit a522626

Please sign in to comment.