-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
448 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
tests/03-arg-processor/002-one-required-positional/expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
## no args or options passed | ||
|
||
### stderr | ||
``` | ||
the-cmd: Missing required argument <zongo>. | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed `--` | ||
|
||
### stderr | ||
``` | ||
the-cmd: Missing required argument <zongo>. | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed positional arg | ||
|
||
### stdout | ||
``` | ||
Value: i-am-arguing | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed two positional args | ||
|
||
### stderr | ||
``` | ||
the-cmd: Too many positional arguments. | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed `--` then positional arg | ||
|
||
### stdout | ||
``` | ||
Value: MORE_ARGUING | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed `--` then arg that looks like an option | ||
|
||
### stdout | ||
``` | ||
Value: --non-option | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed a double-dash option | ||
|
||
### stderr | ||
``` | ||
the-cmd: Unknown option: --x | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed a double-dash option then a positional arg | ||
|
||
### stderr | ||
``` | ||
the-cmd: Unknown option: --x | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Test of a single required positional argument. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
# Copyright 2022-2023 the Bashy-lib Authors (Dan Bornstein et alia). | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
. "$(dirname "$(readlink -f "$0")")/../../_test-init.sh" || exit "$?" | ||
|
||
cmd="$(this-cmd-dir)/the-cmd" | ||
|
||
call-and-log-as-test 'no args or options passed' \ | ||
"${cmd}" | ||
|
||
call-and-log-as-test 'passed `--`' \ | ||
"${cmd}" -- | ||
|
||
call-and-log-as-test 'passed positional arg' \ | ||
"${cmd}" i-am-arguing | ||
|
||
call-and-log-as-test 'passed two positional args' \ | ||
"${cmd}" florp fleep | ||
|
||
call-and-log-as-test 'passed `--` then positional arg' \ | ||
"${cmd}" -- MORE_ARGUING | ||
|
||
call-and-log-as-test 'passed `--` then arg that looks like an option' \ | ||
"${cmd}" -- --non-option | ||
|
||
call-and-log-as-test 'passed a double-dash option' \ | ||
"${cmd}" --x | ||
|
||
call-and-log-as-test 'passed a double-dash option then a positional arg' \ | ||
"${cmd}" --x bloop |
22 changes: 22 additions & 0 deletions
22
tests/03-arg-processor/002-one-required-positional/the-cmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
# Copyright 2022-2023 the Bashy-lib Authors (Dan Bornstein et alia). | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
. "$(dirname "$(readlink -f "$0")")/../../_init.sh" || exit "$?" | ||
|
||
|
||
# | ||
# Argument parsing | ||
# | ||
|
||
define-usage $' | ||
${name} -- test command | ||
This is a test command. | ||
' | ||
|
||
positional-arg --required --var=theName zongo | ||
|
||
process-args "$@" || usage --short | ||
|
||
printf 'Value: %q\n' "${theName}" |
91 changes: 91 additions & 0 deletions
91
tests/03-arg-processor/003-one-optional-positional/expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
## no args or options passed | ||
|
||
### stdout | ||
``` | ||
Value: zorch | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed `--` | ||
|
||
### stdout | ||
``` | ||
Value: zorch | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed positional arg | ||
|
||
### stdout | ||
``` | ||
Value: i-am-arguing | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed two positional args | ||
|
||
### stderr | ||
``` | ||
the-cmd: Too many positional arguments. | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed `--` then positional arg | ||
|
||
### stdout | ||
``` | ||
Value: MORE_ARGUING | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed `--` then arg that looks like an option | ||
|
||
### stdout | ||
``` | ||
Value: --non-option | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed a double-dash option | ||
|
||
### stderr | ||
``` | ||
the-cmd: Unknown option: --x | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed a double-dash option then a positional arg | ||
|
||
### stderr | ||
``` | ||
the-cmd: Unknown option: --x | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Test of a single optional positional argument. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
# Copyright 2022-2023 the Bashy-lib Authors (Dan Bornstein et alia). | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
. "$(dirname "$(readlink -f "$0")")/../../_test-init.sh" || exit "$?" | ||
|
||
cmd="$(this-cmd-dir)/the-cmd" | ||
|
||
call-and-log-as-test 'no args or options passed' \ | ||
"${cmd}" | ||
|
||
call-and-log-as-test 'passed `--`' \ | ||
"${cmd}" -- | ||
|
||
call-and-log-as-test 'passed positional arg' \ | ||
"${cmd}" i-am-arguing | ||
|
||
call-and-log-as-test 'passed two positional args' \ | ||
"${cmd}" florp fleep | ||
|
||
call-and-log-as-test 'passed `--` then positional arg' \ | ||
"${cmd}" -- MORE_ARGUING | ||
|
||
call-and-log-as-test 'passed `--` then arg that looks like an option' \ | ||
"${cmd}" -- --non-option | ||
|
||
call-and-log-as-test 'passed a double-dash option' \ | ||
"${cmd}" --x | ||
|
||
call-and-log-as-test 'passed a double-dash option then a positional arg' \ | ||
"${cmd}" --x bloop |
22 changes: 22 additions & 0 deletions
22
tests/03-arg-processor/003-one-optional-positional/the-cmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
# Copyright 2022-2023 the Bashy-lib Authors (Dan Bornstein et alia). | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
. "$(dirname "$(readlink -f "$0")")/../../_init.sh" || exit "$?" | ||
|
||
|
||
# | ||
# Argument parsing | ||
# | ||
|
||
define-usage $' | ||
${name} -- test command | ||
This is a test command. | ||
' | ||
|
||
positional-arg --var=theName --init=zorch zongo | ||
|
||
process-args "$@" || usage --short | ||
|
||
printf 'Value: %q\n' "${theName}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
## no args or options passed | ||
|
||
### stderr | ||
``` | ||
the-cmd: Missing required argument <avec-yes>. | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed `--` | ||
|
||
### stderr | ||
``` | ||
the-cmd: Missing required argument <avec-yes>. | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed one positional arg | ||
|
||
### stdout | ||
``` | ||
avec-yes: one | ||
some-value: '' | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed two positional args | ||
|
||
### stdout | ||
``` | ||
avec-yes: florp | ||
some-value: fleep | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed three positional args | ||
|
||
### stderr | ||
``` | ||
the-cmd: Too many positional arguments. | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed `--` then one positional arg | ||
|
||
### stdout | ||
``` | ||
avec-yes: ONE | ||
some-value: '' | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed `--` then two positional args | ||
|
||
### stdout | ||
``` | ||
avec-yes: YES | ||
some-value: MORE-YES | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## passed `--` then three positional args | ||
|
||
### stderr | ||
``` | ||
the-cmd: Too many positional arguments. | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 |
Oops, something went wrong.