1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-14 11:12:10 +00:00
serenity/Userland/Shell/Tests/if.sh
AnotherTest 86f50aa74e Shell: Make tests use PASS/FAIL instead of exit codes
There's no guarantee that the last executed command will have a zero
exit code, and so the shell exit code may or may not be zero, even if
all the tests pass.
Also changes the `test || echo fail && exit` to
`if not test { echo fail && exit }`, since that's nicer-looking.
2021-01-19 08:19:43 +01:00

54 lines
1 KiB
Bash

#!/bin/sh
source 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