mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 21:03:12 +00:00
2c17d34971
This introduces a feature flag, "test-require-arg", that removes builtin test's zero and one argument special modes. That means: - `test -n` returns false - `test -z` returns true - `test -x` with any other option errors out with "missing argument" - `test foo` errors out as expecting an option `test -n` returning true is a frequent source of confusion, and so we are breaking with posix in this regard. As always the flag defaults to off and can be turned on. In future it will default to on and then eventually be made read-only. There is a new FLOG category "deprecated-test", run `fish -d deprecated-test` and it will show any test call that would change in future.
48 lines
1.3 KiB
Fish
48 lines
1.3 KiB
Fish
# RUN: %fish %s
|
|
#
|
|
# Tests for the posix-mandated zero and one argument modes for the `test` builtin, aka `[`.
|
|
|
|
test -n
|
|
echo $status
|
|
#CHECK: 0
|
|
|
|
test -z
|
|
echo $status
|
|
#CHECK: 0
|
|
|
|
test -d
|
|
echo $status
|
|
#CHECK: 0
|
|
|
|
test "foo"
|
|
echo $status
|
|
#CHECK: 0
|
|
|
|
test ""
|
|
echo $status
|
|
#CHECK: 1
|
|
|
|
test -z "" -a foo
|
|
echo $status
|
|
#CHECK: 0
|
|
|
|
set -l fish (status fish-path)
|
|
echo 'test foo; test; test -z; test -n; test -d; echo oops' | $fish -d 'deprecated-*' >/dev/null
|
|
#CHECKERR: test: called with one argument. This will return false in future.
|
|
#CHECKERR: Standard input (line 1):
|
|
#CHECKERR: test foo; test; test -z; test -n; test -d; echo oops
|
|
#CHECKERR: ^
|
|
#CHECKERR: test: called with no arguments. This will be an error in future.
|
|
#CHECKERR: Standard input (line 1):
|
|
#CHECKERR: test foo; test; test -z; test -n; test -d; echo oops
|
|
#CHECKERR: ^
|
|
#CHECKERR: test: called with one argument. This will return false in future.
|
|
# (yes, `test -z` is skipped because it would behave the same)
|
|
#CHECKERR: Standard input (line 1):
|
|
#CHECKERR: test foo; test; test -z; test -n; test -d; echo oops
|
|
#CHECKERR: ^
|
|
#CHECKERR: test: called with one argument. This will return false in future.
|
|
#CHECKERR: Standard input (line 1):
|
|
#CHECKERR: test foo; test; test -z; test -n; test -d; echo oops
|
|
#CHECKERR: ^
|
|
|