mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-02 05:41: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:
@@ -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