mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-21 21:46:15 +02:00
tests/functional: Support negative codes in expect, expectStderr
This commit is contained in:
parent
03326d606f
commit
783a8341ee
2 changed files with 23 additions and 2 deletions
|
@ -236,7 +236,8 @@ expect() {
|
|||
expected="$1"
|
||||
shift
|
||||
"$@" && res=0 || res="$?"
|
||||
if [[ $res -ne $expected ]]; then
|
||||
# also match "negative" codes, which wrap around to >127
|
||||
if [[ $res -ne $expected && $res -ne $[256 + expected] ]]; then
|
||||
echo "Expected exit code '$expected' but got '$res' from command ${*@Q}" >&2
|
||||
return 1
|
||||
fi
|
||||
|
@ -250,7 +251,8 @@ expectStderr() {
|
|||
expected="$1"
|
||||
shift
|
||||
"$@" 2>&1 && res=0 || res="$?"
|
||||
if [[ $res -ne $expected ]]; then
|
||||
# also match "negative" codes, which wrap around to >127
|
||||
if [[ $res -ne $expected && $res -ne $[256 + expected] ]]; then
|
||||
echo "Expected exit code '$expected' but got '$res' from command ${*@Q}" >&2
|
||||
return 1
|
||||
fi
|
||||
|
|
|
@ -13,6 +13,25 @@ expect 1 false
|
|||
# `expect` will fail when we get it wrong
|
||||
expect 1 expect 0 false
|
||||
|
||||
function ret() {
|
||||
return $1
|
||||
}
|
||||
|
||||
# `expect` can call functions, not just executables
|
||||
expect 0 ret 0
|
||||
expect 1 ret 1
|
||||
|
||||
# `expect` supports negative exit codes
|
||||
expect -1 ret -1
|
||||
|
||||
# or high positive ones, equivalent to negative ones
|
||||
expect 255 ret 255
|
||||
expect 255 ret -1
|
||||
expect -1 ret 255
|
||||
|
||||
# but it doesn't confuse negative exit codes with positive ones
|
||||
expect 1 expect -10 ret 10
|
||||
|
||||
noisyTrue () {
|
||||
echo YAY! >&2
|
||||
true
|
||||
|
|
Loading…
Reference in a new issue