mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-21 03:21:16 -03:00
Deprecate builtin test's one- and zero-argument modes (#10365)
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.
This commit is contained in:
@@ -58,6 +58,7 @@ status features
|
||||
#CHECK: regex-easyesc on 3.1 string replace -r needs fewer \'s
|
||||
#CHECK: ampersand-nobg-in-token on 3.4 & only backgrounds if followed by a separator
|
||||
#CHECK: remove-percent-self off 3.8 %self is no longer expanded (use $fish_pid)
|
||||
#CHECK: test-require-arg off 3.8 builtin test requires an argument
|
||||
status test-feature stderr-nocaret
|
||||
echo $status
|
||||
#CHECK: 0
|
||||
|
||||
48
tests/checks/test-posix.fish
Normal file
48
tests/checks/test-posix.fish
Normal file
@@ -0,0 +1,48 @@
|
||||
# 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: ^
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# RUN: %fish %s
|
||||
# RUN: %fish --features test-require-arg %s
|
||||
#
|
||||
# Tests for the `test` builtin, aka `[`.
|
||||
test inf -gt 0
|
||||
@@ -94,3 +94,51 @@ test epoch -ef old && echo bad ef || echo good ef
|
||||
#CHECK: good ef
|
||||
|
||||
rm -f epoch old newest epochlink
|
||||
|
||||
test -n
|
||||
echo -- -n $status
|
||||
#CHECK: -n 1
|
||||
test -z
|
||||
echo -- -z $status
|
||||
#CHECK: -z 0
|
||||
|
||||
test -d
|
||||
#CHECKERR: test: Missing argument at index 2
|
||||
#CHECKERR: -d
|
||||
#CHECKERR: ^
|
||||
#CHECKERR: {{.*}}test.fish (line {{\d+}}):
|
||||
#CHECKERR: test -d
|
||||
#CHECKERR: ^
|
||||
|
||||
test "foo"
|
||||
#CHECKERR: test: Missing argument at index 2
|
||||
#CHECKERR: foo
|
||||
#CHECKERR: ^
|
||||
#CHECKERR: {{.*}}test.fish (line {{\d+}}):
|
||||
#CHECKERR: test "foo"
|
||||
#CHECKERR: ^
|
||||
|
||||
test ""
|
||||
#CHECKERR: test: Missing argument at index 2
|
||||
#CHECKERR: ^
|
||||
#CHECKERR: {{.*}}test.fish (line {{\d+}}):
|
||||
#CHECKERR: test ""
|
||||
#CHECKERR: ^
|
||||
|
||||
test -z "" -a foo
|
||||
#CHECKERR: test: Missing argument at index 5
|
||||
#CHECKERR: -z -a foo
|
||||
#CHECKERR: ^
|
||||
#CHECKERR: {{.*}}test.fish (line {{\d+}}):
|
||||
#CHECKERR: test -z "" -a foo
|
||||
#CHECKERR: ^
|
||||
|
||||
echo $status
|
||||
#CHECK: 1
|
||||
|
||||
test
|
||||
#CHECKERR: test: Expected at least one argument
|
||||
#CHECKERR: {{.*}}test.fish (line {{\d+}}):
|
||||
#CHECKERR: test
|
||||
#CHECKERR: ^
|
||||
#CHECKERR: (Type 'help test' for related documentation)
|
||||
|
||||
Reference in New Issue
Block a user