System tests: Usage checks: better error messages

Current error messages are really awful, and cause great
suffering every time someone adds a new subcommand. Let's
see if these are better.

Signed-off-by: Ed Santiago <santiago@redhat.com>
This commit is contained in:
Ed Santiago
2022-04-13 14:07:57 -06:00
parent 480bc83b80
commit 9ef745d541

View File

@ -68,9 +68,10 @@ function check_help() {
if [ "$cmd" != "help" ]; then if [ "$cmd" != "help" ]; then
dprint "$command_string invalid-arg" dprint "$command_string invalid-arg"
run_podman '?' "$@" $cmd invalid-arg run_podman '?' "$@" $cmd invalid-arg
is "$status" 125 "'$command_string invalid-arg' - exit status" is "$status" 125 \
"'$usage' indicates that the command takes no arguments. I invoked it with 'invalid-arg' and expected an error status"
is "$output" "Error: .* takes no arguments" \ is "$output" "Error: .* takes no arguments" \
"'$command_string' with extra (invalid) arguments" "'$usage' indicates that the command takes no arguments. I invoked it with 'invalid-arg' and expected the following error message"
fi fi
found[takes_no_args]=1 found[takes_no_args]=1
fi fi
@ -115,9 +116,10 @@ function check_help() {
# try to read username/password from stdin. # try to read username/password from stdin.
dprint "$command_string (without required args)" dprint "$command_string (without required args)"
run_podman '?' "$@" $cmd </dev/null run_podman '?' "$@" $cmd </dev/null
is "$status" 125 "'$command_string' with no arguments - exit status" is "$status" 125 \
"'$usage' indicates at least one required arg. I invoked it with no args and expected an error exit code"
is "$output" "Error:.* \(require\|specif\|must\|provide\|need\|choose\|accepts\)" \ is "$output" "Error:.* \(require\|specif\|must\|provide\|need\|choose\|accepts\)" \
"'$command_string' without required arg" "'$usage' indicates at least one required arg. I invoked it with no args and expected one of these error messages"
found[required_args]=1 found[required_args]=1
fi fi
@ -138,9 +140,10 @@ function check_help() {
local n_args=$(wc -w <<<"$rhs") local n_args=$(wc -w <<<"$rhs")
run_podman '?' "$@" $cmd $(seq --format='x%g' 0 $n_args) run_podman '?' "$@" $cmd $(seq --format='x%g' 0 $n_args)
is "$status" 125 "'$command_string' with >$n_args arguments - exit status" is "$status" 125 \
"'$usage' indicates a maximum of $n_args args. I invoked it with more, and expected this exit status"
is "$output" "Error:.* \(takes no arguments\|requires exactly $n_args arg\|accepts at most\|too many arguments\|accepts $n_args arg(s), received\|accepts between .* and .* arg(s), received \)" \ is "$output" "Error:.* \(takes no arguments\|requires exactly $n_args arg\|accepts at most\|too many arguments\|accepts $n_args arg(s), received\|accepts between .* and .* arg(s), received \)" \
"'$command_string' with >$n_args arguments" "'$usage' indicates a maximum of $n_args args. I invoked it with more, and expected one of these error messages"
found[fixed_args]=1 found[fixed_args]=1
fi fi