mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 02:37:35 +00:00
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.
This commit is contained in:
parent
5ec139e728
commit
86f50aa74e
14 changed files with 177 additions and 128 deletions
|
@ -1,5 +1,7 @@
|
|||
#/bin/sh
|
||||
|
||||
source test-commons.inc
|
||||
|
||||
setopt --verbose
|
||||
|
||||
rm -rf shell-test
|
||||
|
@ -8,21 +10,30 @@ cd shell-test
|
|||
|
||||
# Simple sequence (grouping)
|
||||
{ echo test > testfile }
|
||||
test "$(cat testfile)" = "test" || echo cannot write to file in subshell && exit 1
|
||||
if not test "$(cat testfile)" = "test" {
|
||||
fail cannot write to file in subshell
|
||||
}
|
||||
|
||||
# Simple sequence - many commands
|
||||
{ echo test1 > testfile; echo test2 > testfile }
|
||||
test "$(cat testfile)" = "test2" || echo cannot write to file in subshell 2 && exit 1
|
||||
|
||||
if not test "$(cat testfile)" = "test2" {
|
||||
fail cannot write to file in subshell 2
|
||||
}
|
||||
|
||||
# Does it exit with the last exit code?
|
||||
{ test -z "a" }
|
||||
exitcode=$?
|
||||
test "$exitcode" -eq 1 || echo exits with $exitcode when it should exit with 1 && exit 1
|
||||
if not test "$exitcode" -eq 1 {
|
||||
fail exits with $exitcode when it should exit with 1
|
||||
}
|
||||
|
||||
{ test -z "a" || echo test }
|
||||
exitcode=$?
|
||||
test "$exitcode" -eq 0 || echo exits with $exitcode when it should exit with 0 && exit 1
|
||||
if not test "$exitcode" -eq 0 {
|
||||
fail exits with $exitcode when it should exit with 0
|
||||
}
|
||||
|
||||
cd ..
|
||||
rm -rf shell-test
|
||||
|
||||
echo PASS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue