diff --git a/tests/checks/basic.fish b/tests/checks/basic.fish index e28982389..b14130360 100644 --- a/tests/checks/basic.fish +++ b/tests/checks/basic.fish @@ -172,3 +172,143 @@ echo 'echo "source argv {$argv}"' | source - abc def always_fails echo $status #CHECK: 1 + +# Test that subsequent cases do not blow away the status from previous ones +for val in one two three four + switch $val + case one + /bin/sh -c 'exit 1' + case two + /bin/sh -c 'exit 2' + case three + /bin/sh -c 'exit 3' + end + echo $status +end +#CHECK: 1 +#CHECK: 2 +#CHECK: 3 +#CHECK: 0 + +# Test that the `switch` builtin itself does not blow away status before evaluating a case +false +switch one +case one + echo $status +end +#CHECK: 1 + +#test contains -i +contains -i string a b c string d +#CHECK: 4 +contains -i string a b c d; or echo nothing +#CHECK: nothing +contains -i -- string a b c string d +#CHECK: 4 +contains -i -- -- a b c; or echo nothing +#CHECK: nothing +contains -i -- -- a b c -- v +#CHECK: 4 + +# Test if, else, and else if +if true + echo alpha1.1 + echo alpha1.2 +else if false + echo beta1.1 + echo beta1.2 +else if false + echo gamma1.1 + echo gamma1.2 +else + echo delta1.1 + echo delta1.2 +end +#CHECK: alpha1.1 +#CHECK: alpha1.2 + +if false + echo alpha2.1 + echo alpha2.2 +else if begin ; true ; end + echo beta2.1 + echo beta2.2 +else if begin ; echo nope2.1; false ; end + echo gamma2.1 + echo gamma2.2 +else + echo delta2.1 + echo delta2.2 +end +#CHECK: beta2.1 +#CHECK: beta2.2 + +if false + echo alpha3.1 + echo alpha3.2 +else if begin ; echo yep3.1; false ; end + echo beta3.1 + echo beta3.2 +else if begin ; echo yep3.2; true ; end + echo gamma3.1 + echo gamma3.2 +else + echo delta3.1 + echo delta3.2 +end +#CHECK: yep3.1 +#CHECK: yep3.2 +#CHECK: gamma3.1 +#CHECK: gamma3.2 + +if false + echo alpha4.1 + echo alpha4.2 +else if begin ; echo yep4.1; false ; end + echo beta4.1 + echo beta4.2 +else if begin ; echo yep4.2; false ; end + echo gamma4.1 + echo gamma4.2 +else + echo delta4.1 + echo delta4.2 +end +#CHECK: yep4.1 +#CHECK: yep4.2 +#CHECK: delta4.1 +#CHECK: delta4.2 + +if test ! -n "abc" +else if test -n "def" + echo "epsilon5.2" +else if not_a_valid_command but it should be OK because a previous branch was taken + echo "epsilon 5.3" +else if test ! -n "abc" + echo "epsilon 5.4" +end +#CHECK: epsilon5.2 + +# Ensure builtins work +# https://github.com/fish-shell/fish-shell/issues/359 +if not echo skip1 > /dev/null + echo "zeta 6.1" +else if echo skip2 > /dev/null + echo "zeta 6.2" +end +#CHECK: zeta 6.2 + +echo '###' +#CHECK: ### + +# Ensure 'type' works +# https://github.com/fish-shell/fish-shell/issues/513 +function fish_test_type_zzz + true +end +# Should succeed +type -q fish_test_type_zzz ; echo $status +#CHECK: 0 +# Should fail +type -q -f fish_test_type_zzz ; echo $status +#CHECK: 1 diff --git a/tests/test7.err b/tests/test7.err deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/test7.in b/tests/test7.in deleted file mode 100644 index 322982756..000000000 --- a/tests/test7.in +++ /dev/null @@ -1,115 +0,0 @@ -# Test that subsequent cases do not blow away the status from previous ones -for val in one two three four - switch $val - case one - /bin/sh -c 'exit 1' - case two - /bin/sh -c 'exit 2' - case three - /bin/sh -c 'exit 3' - end - echo $status -end - -echo - -# Test that the `switch` builtin itself does not blow away status before evaluating a case -false -switch one -case one - echo $status -end - -#test contains -i -echo test contains -i -contains -i string a b c string d -contains -i string a b c d; or echo nothing -contains -i -- string a b c string d -contains -i -- -- a b c; or echo nothing -contains -i -- -- a b c -- v - -# Test if, else, and else if -if true - echo alpha1.1 - echo alpha1.2 -else if false - echo beta1.1 - echo beta1.2 -else if false - echo gamma1.1 - echo gamma1.2 -else - echo delta1.1 - echo delta1.2 -end - -if false - echo alpha2.1 - echo alpha2.2 -else if begin ; true ; end - echo beta2.1 - echo beta2.2 -else if begin ; echo nope2.1; false ; end - echo gamma2.1 - echo gamma2.2 -else - echo delta2.1 - echo delta2.2 -end - -if false - echo alpha3.1 - echo alpha3.2 -else if begin ; echo yep3.1; false ; end - echo beta3.1 - echo beta3.2 -else if begin ; echo yep3.2; true ; end - echo gamma3.1 - echo gamma3.2 -else - echo delta3.1 - echo delta3.2 -end - -if false - echo alpha4.1 - echo alpha4.2 -else if begin ; echo yep4.1; false ; end - echo beta4.1 - echo beta4.2 -else if begin ; echo yep4.2; false ; end - echo gamma4.1 - echo gamma4.2 -else - echo delta4.1 - echo delta4.2 -end - -if test ! -n "abc" -else if test -n "def" - echo "epsilon5.2" -else if not_a_valid_command but it should be OK because a previous branch was taken - echo "epsilon 5.3" -else if test ! -n "abc" - echo "epsilon 5.4" -end - -# Ensure builtins work -# https://github.com/fish-shell/fish-shell/issues/359 -if not echo skip1 > /dev/null - echo "zeta 6.1" -else if echo skip2 > /dev/null - echo "zeta 6.2" -end - -echo '###' - -# Ensure 'type' works -# https://github.com/fish-shell/fish-shell/issues/513 -function fish_test_type_zzz - true -end -# Should succeed -type -q fish_test_type_zzz ; echo $status -# Should fail -type -q -f fish_test_type_zzz ; echo $status diff --git a/tests/test7.out b/tests/test7.out deleted file mode 100644 index bbe2ab1a5..000000000 --- a/tests/test7.out +++ /dev/null @@ -1,29 +0,0 @@ -1 -2 -3 -0 - -1 -test contains -i -4 -nothing -4 -nothing -4 -alpha1.1 -alpha1.2 -beta2.1 -beta2.2 -yep3.1 -yep3.2 -gamma3.1 -gamma3.2 -yep4.1 -yep4.2 -delta4.1 -delta4.2 -epsilon5.2 -zeta 6.2 -### -0 -1