Make tests usable with path with spaces
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?
2024-12-27 19:54:43 +00:00
|
|
|
# RUN: fish=%fish %fish %s
|
2019-07-31 12:04:24 +00:00
|
|
|
# Check that switch with an argument expanding to nothing still works.
|
|
|
|
switch $foo
|
|
|
|
case a
|
|
|
|
echo a
|
|
|
|
case ''
|
|
|
|
echo very little
|
|
|
|
case '*'
|
|
|
|
echo Nothin
|
|
|
|
case ''
|
|
|
|
echo banana
|
|
|
|
end
|
|
|
|
#CHECK: very little
|
|
|
|
|
|
|
|
switch (true)
|
|
|
|
case a
|
|
|
|
echo a
|
|
|
|
case ''
|
|
|
|
echo very little
|
|
|
|
case '*'
|
|
|
|
echo Nothin
|
|
|
|
case ''
|
|
|
|
echo banana
|
|
|
|
end
|
|
|
|
#CHECK: very little
|
|
|
|
|
|
|
|
switch (echo)
|
|
|
|
case a
|
|
|
|
echo a
|
|
|
|
case ''
|
|
|
|
echo very little
|
|
|
|
case '*'
|
|
|
|
echo Nothin
|
|
|
|
case ''
|
|
|
|
echo banana
|
|
|
|
end
|
|
|
|
#CHECK: very little
|
|
|
|
|
|
|
|
# Multiple arguments is still an error, we've not decided on good behavior for this.
|
|
|
|
switch (echo; echo; echo)
|
|
|
|
case a
|
|
|
|
echo a
|
|
|
|
case ""
|
|
|
|
echo very little
|
|
|
|
case "*"
|
|
|
|
echo Nothin
|
|
|
|
case ""
|
|
|
|
echo banana
|
|
|
|
end
|
|
|
|
#CHECKERR: {{.*/?}}switch.fish (line {{\d+}}): switch: Expected at most one argument, got 3
|
|
|
|
#CHECKERR:
|
|
|
|
#CHECKERR: switch (echo; echo; echo)
|
2022-08-11 15:22:03 +00:00
|
|
|
#CHECKERR: ^~~~~~~~~~~~~~~~~^
|
2019-07-31 12:04:24 +00:00
|
|
|
|
|
|
|
# As is no argument at all.
|
|
|
|
# Because this is a syntax error, we need to start a sub-fish or we wouldn't execute anything else.
|
|
|
|
$fish -c '
|
|
|
|
switch
|
|
|
|
case a
|
|
|
|
echo a
|
|
|
|
case ""
|
|
|
|
echo very little
|
|
|
|
case "*"
|
|
|
|
echo Nothin
|
|
|
|
case ""
|
|
|
|
echo banana
|
|
|
|
end
|
|
|
|
'
|
|
|
|
#CHECKERR: fish: 'case' builtin not inside of switch block
|
|
|
|
#CHECKERR: case a
|
2022-08-11 15:22:03 +00:00
|
|
|
#CHECKERR: ^~~^
|
2020-02-08 09:43:40 +00:00
|
|
|
|
|
|
|
set smurf green
|
|
|
|
|
2020-03-09 18:36:12 +00:00
|
|
|
switch $smurf
|
|
|
|
case "*ee*"
|
|
|
|
echo Test 1 pass
|
|
|
|
case "*"
|
|
|
|
echo Test 1 fail
|
|
|
|
end
|
2020-02-08 09:43:40 +00:00
|
|
|
#CHECK: Test 1 pass
|
|
|
|
|
|
|
|
switch $smurf
|
2020-03-09 18:36:12 +00:00
|
|
|
case *ee*
|
|
|
|
echo Test 2 fail
|
|
|
|
case red green blue
|
|
|
|
echo Test 2 pass
|
|
|
|
case "*"
|
|
|
|
echo Test 2 fail
|
2020-02-08 09:43:40 +00:00
|
|
|
end
|
2021-08-11 16:40:37 +00:00
|
|
|
#CHECKERR: {{.*}}switch.fish (line {{\d+}}): No matches for wildcard '*ee*'. See `help wildcards-globbing`.
|
2020-02-08 09:43:40 +00:00
|
|
|
#CHECKERR: case *ee*
|
2022-08-11 15:22:03 +00:00
|
|
|
#CHECKERR: ^~~^
|
2020-02-08 09:43:40 +00:00
|
|
|
#CHECK: Test 2 pass
|
|
|
|
|
|
|
|
switch $smurf
|
2020-03-09 18:36:12 +00:00
|
|
|
case cyan magenta yellow
|
|
|
|
echo Test 3 fail
|
|
|
|
case "*"
|
|
|
|
echo Test 3 pass
|
2020-02-08 09:43:40 +00:00
|
|
|
end
|
|
|
|
#CHECK: Test 3 pass
|
2021-04-19 14:47:17 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
set -l PATH
|
|
|
|
switch (doesnotexist)
|
|
|
|
case '*'
|
|
|
|
echo Matched!
|
|
|
|
end
|
|
|
|
# CHECKERR: fish: Unknown command: doesnotexist
|
2024-12-27 19:02:11 +00:00
|
|
|
# CHECKERR: {{.*}}checks/switch.fish (line {{\d+}}):
|
2021-04-19 14:47:17 +00:00
|
|
|
# CHECKERR: doesnotexist
|
2022-08-11 15:22:03 +00:00
|
|
|
# CHECKERR: ^~~~~~~~~~~^
|
2021-04-19 14:47:17 +00:00
|
|
|
# CHECKERR: in command substitution
|
2024-12-27 19:02:11 +00:00
|
|
|
# CHECKERR: {{\t}}called on line {{\d+}} of file {{.*}}checks/switch.fish
|
|
|
|
# CHECKERR: {{.*}}checks/switch.fish (line {{\d+}}): Unknown command
|
2021-04-19 14:47:17 +00:00
|
|
|
# CHECKERR: switch (doesnotexist)
|
2022-08-11 15:22:03 +00:00
|
|
|
# CHECKERR: ^~~~~~~~~~~~~^
|
2021-04-19 14:47:17 +00:00
|
|
|
end
|
Make tests usable with path with spaces
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?
2024-12-27 19:54:43 +00:00
|
|
|
|
|
|
|
exit 0
|