72 lines
1.4 KiB
Bash
Executable File
72 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
set -eu
|
|
set -o pipefail
|
|
|
|
: ${BIN:=..}
|
|
: ${EMU:=qemu-riscv64}
|
|
|
|
cmd=$BIN/flagtest
|
|
name=flagtest
|
|
|
|
fail=0
|
|
err() {
|
|
echo "FAIL $name: $*"
|
|
fail=1
|
|
}
|
|
|
|
flagtest() {
|
|
"$EMU" "$cmd" "$@"
|
|
}
|
|
|
|
check_fail() {
|
|
set +e
|
|
out=$(flagtest "$@" 2>&1)
|
|
if [[ "$?" -eq 0 ]]; then
|
|
err "expected command to fail: $cmd $*"
|
|
fi
|
|
}
|
|
|
|
check_ok() {
|
|
set +e
|
|
flagtest "$@"
|
|
if [[ "$?" -ne 0 ]]; then
|
|
err "expected command to succeed: $cmd $*"
|
|
fi
|
|
}
|
|
|
|
# invalid
|
|
check_fail -int # missing arg
|
|
check_fail -str
|
|
check_fail -int x # invalid int
|
|
check_fail -int abc
|
|
check_fail -int 0x10 # not yet supported
|
|
check_fail -int "" # empty string is not a valid number
|
|
check_fail -int=
|
|
check_fail -xxx # invalid flag
|
|
check_fail -bool=x # invalid bool
|
|
|
|
# valid
|
|
check_ok
|
|
check_ok -bool
|
|
check_ok -bool=true
|
|
check_ok -bool=false
|
|
check_ok -int 0
|
|
check_ok -int=1
|
|
check_ok -int 987654321
|
|
check_ok -str=x
|
|
check_ok -str=
|
|
check_ok -str ""
|
|
check_ok -str -xxx # 2nd arg should be treated as a value not a flag
|
|
check_ok -str x -str y # duplicates are allowed
|
|
check_ok -int 1 -int 2
|
|
check_ok -bool -bool
|
|
check_ok X -bool Y # flags can be interspered with arguments
|
|
check_ok -bool -str x -int 1
|
|
|
|
# valid, but maybe it shouldn't be?
|
|
check_ok -bool=
|
|
|
|
# valid. and bool should not consume the "false"
|
|
# (but we don't have a way to check that just yet)
|
|
check_ok -bool false
|