ladybird/Userland/Shell/Tests/if.sh
Andrew Kaster 8fc862f710 Userland: Install shell tests on Serenity
Also make them runnable anywhere. Previously they required $PWD to be
the directory containing test-commons.inc, and for $PWD to be writable.
2021-02-28 18:19:37 +01:00

55 lines
1.0 KiB
Bash

#!/bin/sh
source $(dirname "$0")/test-commons.inc
setopt --verbose
if test 1 -eq 1 {
# Are comments ok?
# Basic 'if' structure, empty block.
if true {
} else {
fail "if true runs false branch"
}
if false {
fail "if false runs true branch"
} else {
}
# Can we put `else` on a new line?
if false {
echo "if false runs true branch"
exit 2
}
else {
}
# Basic 'if' structure, without 'else'
if false {
fail "'if false' runs the branch"
}
# Extended 'cond' form.
if false {
fail "'if false' with 'else if' runs first branch"
} else if true {
} else {
fail "'if false' with 'else if' runs last branch"
}
# FIXME: Some form of 'not' would be nice
# &&/|| in condition
if true || false {
} else {
fail "'if true || false' runs false branch"
}
if true && false {
fail "'if true && false' runs true branch"
}
} else {
fail "'if test 1 -eq 1' runs false branch"
}
echo PASS