mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 04:58:57 +00:00
e66f6878b5
This is somewhat subtle: The #RUN line in a littlecheck file will be run by a posix shell, which means the substitutions will also be mangled by it. Now, we *have* shell-quoted them, but unfortunately what we need is to quote them for inside a pre-existing layer of quotes, e.g. # RUN: fish -C 'set -g fish %fish' here, %fish can't be replaced with `'path with spaces/fish'`, because that ends up as # RUN: fish -C 'set -g fish 'path with spaces/fish'' which is just broken. So instead, we pass it as a variable to that fish: # RUN: fish=%fish fish... In addition, we need to not mangle the arguments in our test_driver. For that, because we insist on posix shell, which has only one array, and we source a file, we *need* to stop having that file use arguments. Which is okay - test_env.sh could previously be used to start a test, and now it no longer can because that is test_*driver*.sh's job. For the interactive tests, it's slightly different: pexpect.spawn(foo) is sensitive to shell metacharacters like space. So we shell-quote it. But if you pass any args to pexpect.spawn, it no longer uses a shell, and so we cannot shell-quote it. There could be a better way to fix this?
55 lines
1.7 KiB
Fish
55 lines
1.7 KiB
Fish
#RUN: fish=%fish %fish %s
|
|
# Test that using variables as command names work correctly.
|
|
|
|
$EMPTY_VARIABLE
|
|
#CHECKERR: {{.*}}checks/vars_as_commands.fish (line {{\d+}}): The expanded command was empty.
|
|
#CHECKERR: $EMPTY_VARIABLE
|
|
#CHECKERR: ^~~~~~~~~~~~~~^
|
|
"$EMPTY_VARIABLE"
|
|
#CHECKERR: {{.*}}checks/vars_as_commands.fish (line {{\d+}}): The expanded command was empty.
|
|
#CHECKERR: "$EMPTY_VARIABLE"
|
|
#CHECKERR: ^~~~~~~~~~~~~~~~^
|
|
|
|
set CMD1 echo basic command as variable
|
|
$CMD1
|
|
#CHECK: basic command as variable
|
|
|
|
set CMD2 echo '(' not expanded again
|
|
$CMD2
|
|
#CHECK: ( not expanded again
|
|
|
|
# Test using variables with the builtin decorator
|
|
builtin $CMD1
|
|
#CHECK: basic command as variable
|
|
|
|
# Test implicit cd
|
|
set CMD3 /usr/bin
|
|
$CMD3 && echo $PWD
|
|
#CHECK: /usr/bin
|
|
|
|
# $status specifically is not valid, to avoid a common error
|
|
# with `if $status`
|
|
echo 'if $status; echo foo; end' | $fish --no-config
|
|
#CHECKERR: fish: $status is not valid as a command. See `help conditions`
|
|
#CHECKERR: if $status; echo foo; end
|
|
#CHECKERR: ^~~~~~^
|
|
echo 'not $status' | $fish --no-config
|
|
#CHECKERR: fish: $status is not valid as a command. See `help conditions`
|
|
#CHECKERR: not $status
|
|
#CHECKERR: ^~~~~~^
|
|
|
|
# Script doesn't run at all.
|
|
echo 'echo foo; and $status' | $fish --no-config
|
|
#CHECKERR: fish: $status is not valid as a command. See `help conditions`
|
|
#CHECKERR: echo foo; and $status
|
|
#CHECKERR: ^~~~~~^
|
|
|
|
echo 'set -l status_cmd true; if $status_cmd; echo Heck yes this is true; end' | $fish --no-config
|
|
#CHECK: Heck yes this is true
|
|
|
|
foo=bar $NONEXISTENT -c 'set foo 1 2 3; set --show foo'
|
|
#CHECKERR: {{.*}}checks/vars_as_commands.fish (line {{\d+}}): The expanded command was empty.
|
|
#CHECKERR: foo=bar $NONEXISTENT -c 'set foo 1 2 3; set --show foo'
|
|
#CHECKERR: ^~~~~~~~~~~^
|
|
|
|
exit 0
|