fish-shell/tests/checks/eval.fish
ridiculousfish 38f4330683 Rationalize $status and errors
Prior to this fix, fish was rather inconsistent in when $status gets set
in response to an error. For example, a failed expansion like "$foo["
would not modify $status.

This makes the following inter-related changes:

1. String expansion now directly returns the value to set for $status on
error. The value is always used.

2. parser_t::eval() now directly returns the proc_status_t, which cleans
up a lot of call sites.

3. We expose a new function exec_subshell_for_expand() which ignores
$status but returns errors specifically related to subshell expansion.

4. We reify the notion of "expansion breaking" errors. These include
command-not-found, expand syntax errors, and others.

The upshot is we are more consistent about always setting $status on
errors.
2020-01-25 17:28:41 -08:00

59 lines
1.0 KiB
Fish

# RUN: %fish %s
# Regression test for issue #4443
eval set -l previously_undefined foo
echo $previously_undefined
# CHECK: foo
# Test redirection
eval "echo you can\\'t see this 1>&2" 2>/dev/null
# Test return statuses
false
eval true
echo $status
# CHECK: 0
false
eval false
echo $status
# CHECK: 1
# Test return status in case of parsing error
false
eval "("
echo $status
# CHECK: 123
# CHECKERR: {{.*}}checks/eval.fish (line {{\d+}}): Unexpected end of string, expecting ')'
# CHECKERR: (
# CHECKERR: ^
false
eval '""'
echo $status
# CHECK: 123
# CHECKERR: {{.*}}checks/eval.fish (line {{\d+}}): The expanded command was empty.
# CHECKERR: ""
# CHECKERR: ^
function empty
end
# Regression tests for issue #5692
false
eval
echo blank eval: $status # 0
# CHECK: blank eval: 0
false
eval ""
echo empty arg eval: $status # 0
# CHECK: empty arg eval: 0
false
eval empty
echo empty function eval $status # 0
# CHECK: empty function eval 0
false
eval "begin; end;"
echo empty block eval: $status # 0
# CHECK: empty block eval: 0