diff --git a/tests/02-core/03-arg-processor/91-unknown-declaration-opts/expect.md b/tests/02-core/03-arg-processor/91-unknown-declaration-opts/expect.md new file mode 100644 index 0000000..ed86302 --- /dev/null +++ b/tests/02-core/03-arg-processor/91-unknown-declaration-opts/expect.md @@ -0,0 +1,19 @@ +## test + +### stderr +``` +the-cmd: +the-cmd:18: Unknown option: --florp +the-cmd:19: Unknown option: --fleep +the-cmd:20: Unknown option: --flomp +the-cmd:21: Unknown option: --beep +the-cmd:22: Unknown option: --what-the-muffin +the-cmd:25: Invalid option syntax: -zonk +the-cmd:26: Invalid option syntax: ---zonk +the-cmd:27: Invalid option syntax: --Zomg +Cannot process arguments, due to declaration errors. + +the-cmd -- test command +``` + +### exit: 1 diff --git a/tests/02-core/03-arg-processor/91-unknown-declaration-opts/info.txt b/tests/02-core/03-arg-processor/91-unknown-declaration-opts/info.txt new file mode 100644 index 0000000..63b6ed9 --- /dev/null +++ b/tests/02-core/03-arg-processor/91-unknown-declaration-opts/info.txt @@ -0,0 +1 @@ +Test for error detection of totally unknown argument declaration options. diff --git a/tests/02-core/03-arg-processor/91-unknown-declaration-opts/run b/tests/02-core/03-arg-processor/91-unknown-declaration-opts/run new file mode 100755 index 0000000..2144004 --- /dev/null +++ b/tests/02-core/03-arg-processor/91-unknown-declaration-opts/run @@ -0,0 +1,10 @@ +#!/bin/bash +# Copyright 2022-2023 the Bashy-lib Authors (Dan Bornstein et alia). +# SPDX-License-Identifier: Apache-2.0 + +[[ "$(readlink -f "$0")" =~ ^(.*/tests/) ]] && . "${BASH_REMATCH[1]}_test-init.sh" || exit 1 + +cmd="$(this-cmd-dir)/the-cmd" + +call-and-log-as-test 'test' \ + "${cmd}" diff --git a/tests/02-core/03-arg-processor/91-unknown-declaration-opts/the-cmd b/tests/02-core/03-arg-processor/91-unknown-declaration-opts/the-cmd new file mode 100755 index 0000000..30346c3 --- /dev/null +++ b/tests/02-core/03-arg-processor/91-unknown-declaration-opts/the-cmd @@ -0,0 +1,31 @@ +#!/bin/bash +# Copyright 2022-2023 the Bashy-lib Authors (Dan Bornstein et alia). +# SPDX-License-Identifier: Apache-2.0 + +[[ "$(readlink -f "$0")" =~ ^(.*/tests/) ]] && . "${BASH_REMATCH[1]}_init.sh" || exit 1 + + +# +# Argument parsing +# + +define-usage $' + ${name} -- test command + + This is a test command. +' + +opt-value --florp --var=var1 some-value +opt-choice --fleep=zonk --call=func1 yes no +opt-toggle --init=23 --flomp --var=var2 boop +positional-arg --beep=boop --required --var=var3 some-position +rest-arg --filter='/./' --call=func2 --what-the-muffin the-rest + +# Examples of "option-like" but not syntactically correct as options. +opt-value -zonk --var=v x +opt-value ---zonk --var=v x +opt-value --Zomg --var=v x + +process-args "$@" || usage --short + +echo 'Nopers.' diff --git a/tests/02-core/03-arg-processor/92-call-or-var/expect.md b/tests/02-core/03-arg-processor/92-call-or-var/expect.md new file mode 100644 index 0000000..466fcfe --- /dev/null +++ b/tests/02-core/03-arg-processor/92-call-or-var/expect.md @@ -0,0 +1,15 @@ +## test + +### stderr +``` +the-cmd: +the-cmd:18: Unknown option: --florp +the-cmd:19: Unknown option: --fleep +the-cmd:20: Unknown option: --flomp +the-cmd:21: Unknown option: --beep +Cannot process arguments, due to declaration errors. + +the-cmd -- test command +``` + +### exit: 1 diff --git a/tests/02-core/03-arg-processor/92-call-or-var/info.txt b/tests/02-core/03-arg-processor/92-call-or-var/info.txt new file mode 100644 index 0000000..224b725 --- /dev/null +++ b/tests/02-core/03-arg-processor/92-call-or-var/info.txt @@ -0,0 +1,2 @@ +Test for error detection of the requirement to declare at least +one of `--call` or `--var`. diff --git a/tests/02-core/03-arg-processor/92-call-or-var/run b/tests/02-core/03-arg-processor/92-call-or-var/run new file mode 100755 index 0000000..2144004 --- /dev/null +++ b/tests/02-core/03-arg-processor/92-call-or-var/run @@ -0,0 +1,10 @@ +#!/bin/bash +# Copyright 2022-2023 the Bashy-lib Authors (Dan Bornstein et alia). +# SPDX-License-Identifier: Apache-2.0 + +[[ "$(readlink -f "$0")" =~ ^(.*/tests/) ]] && . "${BASH_REMATCH[1]}_test-init.sh" || exit 1 + +cmd="$(this-cmd-dir)/the-cmd" + +call-and-log-as-test 'test' \ + "${cmd}" diff --git a/tests/02-core/03-arg-processor/92-call-or-var/the-cmd b/tests/02-core/03-arg-processor/92-call-or-var/the-cmd new file mode 100755 index 0000000..c0639c8 --- /dev/null +++ b/tests/02-core/03-arg-processor/92-call-or-var/the-cmd @@ -0,0 +1,26 @@ +#!/bin/bash +# Copyright 2022-2023 the Bashy-lib Authors (Dan Bornstein et alia). +# SPDX-License-Identifier: Apache-2.0 + +[[ "$(readlink -f "$0")" =~ ^(.*/tests/) ]] && . "${BASH_REMATCH[1]}_init.sh" || exit 1 + + +# +# Argument parsing +# + +define-usage $' + ${name} -- test command + + This is a test command. +' + +opt-value some-value +opt-choice yes no +opt-toggle boop +positional-arg --filter='/boop/' some-position +rest-arg --required the-rest + +process-args "$@" || usage --short + +echo 'Nopers.'