Skip to content

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
danfuzz committed Oct 4, 2023
1 parent 8361bbf commit 1052879
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test for error detection of totally unknown argument declaration options.
10 changes: 10 additions & 0 deletions tests/02-core/03-arg-processor/91-unknown-declaration-opts/run
Original file line number Diff line number Diff line change
@@ -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}"
31 changes: 31 additions & 0 deletions tests/02-core/03-arg-processor/91-unknown-declaration-opts/the-cmd
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

[[ "$(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.'
15 changes: 15 additions & 0 deletions tests/02-core/03-arg-processor/92-call-or-var/expect.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tests/02-core/03-arg-processor/92-call-or-var/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Test for error detection of the requirement to declare at least
one of `--call` or `--var`.
10 changes: 10 additions & 0 deletions tests/02-core/03-arg-processor/92-call-or-var/run
Original file line number Diff line number Diff line change
@@ -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}"
26 changes: 26 additions & 0 deletions tests/02-core/03-arg-processor/92-call-or-var/the-cmd
Original file line number Diff line number Diff line change
@@ -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.'

0 comments on commit 1052879

Please sign in to comment.