fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Nahorerror rewrite: use new `Error` to report errors30e6aa85e

master
5.5 KiB190 linesraw
1#RUN: %fish %s
2status -b
3and echo '"status -b" unexpectedly returned true at top level'
4
5begin
6    status -b
7    or echo '"status -b" unexpectedly returned false inside a begin block'
8end
9
10status -l
11and echo '"status -l" unexpectedly returned true for a non-login shell'
12
13status -i
14and echo '"status -i" unexpectedly returned true for a non-interactive shell'
15
16status is-login
17and echo '"status is-login" unexpectedly returned true for a non-login shell'
18
19status is-interactive
20and echo '"status is-interactive" unexpectedly returned true for a non-interactive shell'
21
22# We should get an error message about an invalid combination of flags.
23status --is-interactive --is-login
24#CHECKERR: status: is-interactive is-login: options cannot be used together
25
26# We should get an error message about an unexpected arg for `status
27# is-block`.
28status -b is-interactive
29#CHECKERR: status: is-block is-interactive: options cannot be used together
30# XXX this would be better if it referred to -b rather than what it is
31
32# Try to set the job control to an invalid mode.
33status job-control full1
34#CHECKERR: status job-control: Invalid job control mode 'full1'
35status --job-control=1none
36#CHECKERR: status: Invalid job control mode '1none'
37
38# Now set it to a valid mode.
39status job-control none
40
41status current-command | sed s/^/^/
42# CHECK: ^fish
43
44# Check status -u outside functions
45status current-function
46#CHECK: Not a function
47
48function test_function
49    status current-function
50end
51
52test_function
53#CHECK: test_function
54eval test_function
55#CHECK: test_function
56
57# Future Feature Flags
58status features | head -n3
59#CHECK: stderr-nocaret          on  3.0 ^ no longer redirects stderr (historical, can no longer be changed)
60#CHECK: qmark-noglob            on  3.0 ? no longer globs
61#CHECK: regex-easyesc           on  3.1 string replace -r needs fewer \'s
62status test-feature stderr-nocaret
63echo $status
64#CHECK: 0
65status test-feature not-a-feature
66echo $status
67#CHECK: 2
68
69# Ensure $status isn't reset before a function is executed
70function echo_last
71    echo $status
72end
73
74false
75echo_last
76echo $status #1
77#CHECK: 1
78#CHECK: 0
79
80# Verify that if swallows failure - see #1061
81if false
82end
83echo $status
84#CHECK: 0
85
86# Verify errors from writes - see #7857.
87if test -e /dev/full
88    # Failed writes to stdout produce 1.
89    echo foo >/dev/full
90    if test $status -ne 1
91        echo "Wrong status when writing to /dev/full"
92    end
93
94    # Here the builtin should fail with status 2,
95    # and also the write should fail with status 1.
96    # The builtin has precedence.
97    builtin string --not-a-valid-option 2>/dev/full
98    if test $status -ne 2
99        echo "Wrong status for failing builtin"
100    end
101    echo "Failed write tests finished"
102else
103    echo "Failed write tests skipped"
104    echo "write: skipped" 1>&2
105    echo "write: skipped" 1>&2
106end
107# CHECK: Failed write tests {{finished|skipped}}
108# CHECKERR: write: {{.*}}
109# CHECKERR: write: {{.*}}
110
111function test-stack-trace-main
112    status stack-trace
113end
114
115function test-stack-trace-other
116    test-stack-trace-main
117end
118
119printf "%s\n" (test-stack-trace-other | string replace \t '<TAB>')[1..4]
120# CHECK: in function 'test-stack-trace-main'
121# CHECK: <TAB>called on line {{\d+}} of file {{.*}}/status.fish
122# CHECK: in function 'test-stack-trace-other'
123# CHECK: <TAB>called on line {{\d+}} of file {{.*}}/status.fish
124
125functions -c test-stack-trace-other test-stack-trace-copy
126printf "%s\n" (test-stack-trace-copy | string replace \t '<TAB>')[1..4]
127# CHECK: in function 'test-stack-trace-main'
128# CHECK: <TAB>called on line {{\d+}} of file {{.*}}/status.fish
129# CHECK: in function 'test-stack-trace-copy'
130# CHECK: <TAB>called on line {{\d+}} of file {{.*}}/status.fish
131
132status test-terminal-feature
133and should have failed on missing arg
134# CHECKERR: status test-terminal-feature: expected 1 arguments; got 0
135status test-terminal-feature 1 2
136and should have failed on too many args
137# CHECKERR: status test-terminal-feature: expected 1 arguments; got 2
138status test-terminal-feature unrecognized-feature
139and should have failed on unrecognized feature
140# CHECKERR: status test-terminal-feature: unrecognized feature 'unrecognized-feature'
141status test-terminal-feature scroll-content-up
142and should have failed when running without a TTY
143
144status -L abc
145# CHECKERR: status: abc: invalid integer
146status -L 9999999999999999999999
147# CHECKERR: status: Invalid level value '9999999999999999999999'
148
149status unknown-subcmd
150# CHECKERR: status unknown-subcmd: invalid subcommand
151
152status job-control abc cdf
153# CHECKERR: status job-control: expected 1 arguments; got 2
154
155status test-feature
156# CHECKERR: status test-feature: expected 1 arguments; got 0
157status test-feature one two
158# CHECKERR: status test-feature: expected 1 arguments; got 2
159
160status get-file
161# CHECKERR: status get-file: expected 1 arguments; got 0
162status get-file one two
163# CHECKERR: status get-file: expected 1 arguments; got 2
164
165if status buildinfo | string match -q "*localize-messages*"
166    echo Skipped
167else
168    set -l result "$(status language 2>&1)"
169    if string match -q "fish was built with the `localize-messages` feature disabled. The `status language` command is unavailable." -- "$result"
170        echo Success
171    else
172        echo "Failed: $result"
173    end
174end
175# CHECK: {{Skipped|Success}}
176
177if not { status buildinfo | string match -q "*localize-messages*" }
178    echo Skipped
179else
180    set -l result "$(status language foo 2>&1)"
181    if string match -q "status language: foo: invalid subcommand" -- "$result"
182        echo Success
183    else
184        echo "Failed: $result"
185    end
186end
187# CHECK: {{Skipped|Success}}
188
189status build-info other-arg
190# CHECKERR: status build-info: expected 0 arguments; got 1