[Toybox] Testing: how to check return code

Andrew Ilijic ilijic.andrew at gmail.com
Wed Oct 30 11:44:09 PDT 2019


Thank you Jarno & enh,

I ended up using the following:
```
testing "with -w - Fail if negative" \
"$IN && ls -w -5 2> /dev/null ; echo \$? && $OUT" "1\n" "" ""
```
enh, I knew I needed to delay the evaluation of `$?` I just could not
remember or figure out how to do it.

> cmd1 && cmd2 && echo success || echo epic fail
Jarno, I had forgotten that usage of the `&&` and  `||` operators. I will use
it in the future.

Let me know if the following should be its own thread.
> As someone who likes to see the specific exit value (because it's less
> ambiguous when you see it in a failure than "yes" or "ok" or
> whatever)...
I am with you enh. In this case, I wanted the error code because
GNU `ls` says the command can exit with { 0, 1, 2 }.
https://linux.die.net/man/1/ls
POSIX says exit status is { 0, >0 }
https://pubs.opengroup.org/onlinepubs/9699919799/
In this case which specification wins?

enh, the other week you mentioned Android will not use the build if
there are failing tests. Does the above apply to `TEST_HOST=1
make tests`? If so, then I will rewrite the test.

~Andrew



More information about the Toybox mailing list