2019-06-26 19:06:07 +00:00
|
|
|
#RUN: %fish %s
|
|
|
|
# "Basic && and || support"
|
2018-03-02 02:30:48 +00:00
|
|
|
|
|
|
|
echo first && echo second
|
|
|
|
echo third || echo fourth
|
2020-01-13 19:34:22 +00:00
|
|
|
true && false
|
|
|
|
echo "true && false: $status"
|
|
|
|
true || false
|
|
|
|
echo "true || false: $status"
|
|
|
|
true && false || true
|
|
|
|
echo "true && false || true: $status"
|
2019-06-26 19:06:07 +00:00
|
|
|
# CHECK: first
|
|
|
|
# CHECK: second
|
|
|
|
# CHECK: third
|
|
|
|
# CHECK: true && false: 1
|
|
|
|
# CHECK: true || false: 0
|
|
|
|
# CHECK: true && false || true: 0
|
2018-03-02 18:23:57 +00:00
|
|
|
|
2019-06-26 19:06:07 +00:00
|
|
|
# "&& and || in if statements"
|
2018-03-02 18:23:57 +00:00
|
|
|
|
2020-01-13 19:34:22 +00:00
|
|
|
if true || false
|
|
|
|
echo "if test 1 ok"
|
|
|
|
end
|
|
|
|
if true && false
|
|
|
|
else
|
|
|
|
echo "if test 2 ok"
|
|
|
|
end
|
|
|
|
if true && false; or true
|
|
|
|
echo "if test 3 ok"
|
|
|
|
end
|
|
|
|
if [ 0 = 1 ] || [ 5 -ge 3 ]
|
|
|
|
echo "if test 4 ok"
|
|
|
|
end
|
2019-06-26 19:06:07 +00:00
|
|
|
# CHECK: if test 1 ok
|
|
|
|
# CHECK: if test 2 ok
|
|
|
|
# CHECK: if test 3 ok
|
|
|
|
# CHECK: if test 4 ok
|
2018-03-02 18:23:57 +00:00
|
|
|
|
2019-06-26 19:06:07 +00:00
|
|
|
# "&& and || in while statements"
|
2018-03-02 18:23:57 +00:00
|
|
|
|
|
|
|
set alpha 0
|
|
|
|
set beta 0
|
|
|
|
set gamma 0
|
|
|
|
set delta 0
|
|
|
|
while [ $alpha -lt 2 ] && [ $beta -lt 3 ]
|
2020-01-13 19:34:22 +00:00
|
|
|
or [ $gamma -lt 4 ] || [ $delta -lt 5 ]
|
2018-03-02 18:23:57 +00:00
|
|
|
echo $alpha $beta $gamma
|
|
|
|
set alpha ( math $alpha + 1 )
|
|
|
|
set beta ( math $beta + 1 )
|
|
|
|
set gamma ( math $gamma + 1 )
|
|
|
|
set delta ( math $delta + 1 )
|
|
|
|
end
|
2019-06-26 19:06:07 +00:00
|
|
|
# CHECK: 0 0 0
|
|
|
|
# CHECK: 1 1 1
|
|
|
|
# CHECK: 2 2 2
|
|
|
|
# CHECK: 3 3 3
|
|
|
|
# CHECK: 4 4 4
|
2018-03-02 18:23:57 +00:00
|
|
|
|
2019-06-26 19:06:07 +00:00
|
|
|
# "Nots"
|
2018-03-05 00:06:32 +00:00
|
|
|
|
2020-01-13 19:34:22 +00:00
|
|
|
true && ! false
|
|
|
|
echo $status
|
|
|
|
not true && ! false
|
|
|
|
echo $status
|
|
|
|
not not not true
|
|
|
|
echo $status
|
|
|
|
not ! ! not true
|
|
|
|
echo $status
|
|
|
|
not ! echo not !
|
|
|
|
echo $status
|
2019-06-26 19:06:07 +00:00
|
|
|
# CHECK: 0
|
|
|
|
# CHECK: 1
|
|
|
|
# CHECK: 1
|
|
|
|
# CHECK: 0
|
|
|
|
# CHECK: not !
|
|
|
|
# CHECK: 0
|
2018-03-05 00:06:32 +00:00
|
|
|
|
2019-06-26 19:06:07 +00:00
|
|
|
# "Complex scenarios"
|
2018-03-02 18:23:57 +00:00
|
|
|
|
2020-01-13 19:34:22 +00:00
|
|
|
begin
|
|
|
|
echo 1
|
|
|
|
false
|
|
|
|
end || begin
|
|
|
|
echo 2 && echo 3
|
|
|
|
end
|
2018-03-03 02:09:16 +00:00
|
|
|
|
|
|
|
if false && true
|
2020-01-13 19:34:22 +00:00
|
|
|
or not false
|
|
|
|
echo 4
|
2018-03-03 02:09:16 +00:00
|
|
|
end
|
2019-06-26 19:06:07 +00:00
|
|
|
# CHECK: 1
|
|
|
|
# CHECK: 2
|
|
|
|
# CHECK: 3
|
|
|
|
# CHECK: 4
|
2019-09-08 17:42:24 +00:00
|
|
|
|
2020-08-04 19:39:37 +00:00
|
|
|
# Newlines
|
|
|
|
true &&
|
|
|
|
echo newline after conjunction
|
|
|
|
# CHECK: newline after conjunction
|
|
|
|
false ||
|
|
|
|
echo newline after disjunction
|
|
|
|
# CHECK: newline after disjunction
|
|
|
|
|
|
|
|
true &&
|
|
|
|
|
|
|
|
echo empty lines after conjunction
|
|
|
|
# CHECK: empty lines after conjunction
|
|
|
|
|
|
|
|
true &&
|
|
|
|
# can have comments here!
|
|
|
|
echo comment after conjunction
|
|
|
|
# CHECK: comment after conjunction
|
|
|
|
|
2019-09-08 17:42:24 +00:00
|
|
|
# --help works
|
|
|
|
builtin and --help >/dev/null
|
2021-03-15 22:12:35 +00:00
|
|
|
# CHECKERR: fish: Missing man page {{.*}}
|
2021-03-19 16:20:30 +00:00
|
|
|
# CHECKERR: `help '{{.*}}'` will open the online version.
|
2019-09-08 17:42:24 +00:00
|
|
|
echo $status
|
|
|
|
and --help >/dev/null
|
2021-03-15 22:12:35 +00:00
|
|
|
# CHECKERR: fish: Missing man page {{.*}}
|
2021-03-19 16:20:30 +00:00
|
|
|
# CHECKERR: `help '{{.*}}'` will open the online version.
|
2019-09-08 17:42:24 +00:00
|
|
|
echo $status
|
|
|
|
# CHECK: 0
|
|
|
|
# CHECK: 0
|
|
|
|
|
|
|
|
builtin or --help >/dev/null
|
2021-03-15 22:12:35 +00:00
|
|
|
# CHECKERR: fish: Missing man page {{.*}}
|
2021-03-19 16:20:30 +00:00
|
|
|
# CHECKERR: `help '{{.*}}'` will open the online version.
|
2019-09-08 17:42:24 +00:00
|
|
|
echo $status
|
|
|
|
or --help >/dev/null
|
2021-03-15 22:12:35 +00:00
|
|
|
# CHECKERR: fish: Missing man page {{.*}}
|
2021-03-19 16:20:30 +00:00
|
|
|
# CHECKERR: `help '{{.*}}'` will open the online version.
|
2019-09-08 17:42:24 +00:00
|
|
|
echo $status
|
|
|
|
# CHECK: 0
|
|
|
|
# CHECK: 0
|
|
|
|
|
|
|
|
builtin not --help >/dev/null
|
2021-03-15 22:12:35 +00:00
|
|
|
# CHECKERR: fish: Missing man page {{.*}}
|
2021-03-19 16:20:30 +00:00
|
|
|
# CHECKERR: `help '{{.*}}'` will open the online version.
|
2019-09-08 17:42:24 +00:00
|
|
|
echo $status
|
|
|
|
not --help >/dev/null
|
2021-03-15 22:12:35 +00:00
|
|
|
# CHECKERR: fish: Missing man page {{.*}}
|
2021-03-19 16:20:30 +00:00
|
|
|
# CHECKERR: `help '{{.*}}'` will open the online version.
|
2019-09-08 17:42:24 +00:00
|
|
|
echo $status
|
|
|
|
# CHECK: 0
|
|
|
|
# CHECK: 0
|