-
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.
This PR is the follow-on from the previous one. It removes the non-`[]` `--enum` option, and also makes the regex-style filter code get evaluated using the same helper as other filters.
- Loading branch information
Showing
8 changed files
with
236 additions
and
51 deletions.
There are no files selected for viewing
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
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
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
115 changes: 115 additions & 0 deletions
115
tests/02-core/02-arg-processor/19-filter-regex/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,115 @@ | ||
## nop filter, empty value | ||
|
||
### stdout | ||
``` | ||
value: '' | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## nop filter, non-empty value | ||
|
||
### stdout | ||
``` | ||
value: beep | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## "non-empty" filter, empty value | ||
|
||
### stderr | ||
``` | ||
the-cmd: Invalid value for option --non-empty: | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 | ||
|
||
- - - - - - - - - - | ||
|
||
## "non-empty" filter, non-empty value | ||
|
||
### stdout | ||
``` | ||
value: beep | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## single-quotes in filter, matching value | ||
|
||
### stdout | ||
``` | ||
value: $'beep \'x\' boop' | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## single-quotes in filter, non-matching value | ||
|
||
### stderr | ||
``` | ||
the-cmd: Invalid value for option --looks-like-sq-string: beep x boop | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 | ||
|
||
- - - - - - - - - - | ||
|
||
## double-quotes in filter, matching value | ||
|
||
### stdout | ||
``` | ||
value: 'beep "x" boop' | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## double-quotes in filter, non-matching value | ||
|
||
### stderr | ||
``` | ||
the-cmd: Invalid value for option --looks-like-dq-string: beep x boop | ||
the-cmd -- test command | ||
``` | ||
|
||
### exit: 1 | ||
|
||
- - - - - - - - - - | ||
|
||
## dollar-substitution-looking thing in filter, matching value | ||
|
||
### stdout | ||
``` | ||
value: 'yes abc' | ||
``` | ||
|
||
### exit: 0 | ||
|
||
- - - - - - - - - - | ||
|
||
## dollar-substitution-looking thing in filter, non-matching value | ||
|
||
### stderr | ||
``` | ||
the-cmd: Invalid value for option --looks-like-dollar: no abczz | ||
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 @@ | ||
Tests of regex-style `--filter`. |
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,34 @@ | ||
#!/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 'nop filter, empty value' \ | ||
"${cmd}" --nop='' | ||
|
||
call-and-log-as-test 'nop filter, non-empty value' \ | ||
"${cmd}" --nop=beep | ||
|
||
call-and-log-as-test '"non-empty" filter, empty value' \ | ||
"${cmd}" --non-empty='' | ||
|
||
call-and-log-as-test '"non-empty" filter, non-empty value' \ | ||
"${cmd}" --non-empty=beep | ||
|
||
# These test that the regex syntax accepted isn't treated like Bash source, in | ||
# that quote marks are treated as literals, and `$` always means end-of-input. | ||
call-and-log-as-test 'single-quotes in filter, matching value' \ | ||
"${cmd}" --looks-like-sq-string=$'beep \'x\' boop' | ||
call-and-log-as-test 'single-quotes in filter, non-matching value' \ | ||
"${cmd}" --looks-like-sq-string=$'beep x boop' | ||
call-and-log-as-test 'double-quotes in filter, matching value' \ | ||
"${cmd}" --looks-like-dq-string=$'beep \"x\" boop' | ||
call-and-log-as-test 'double-quotes in filter, non-matching value' \ | ||
"${cmd}" --looks-like-dq-string=$'beep x boop' | ||
call-and-log-as-test 'dollar-substitution-looking thing in filter, matching value' \ | ||
"${cmd}" --looks-like-dollar=$'yes abc' | ||
call-and-log-as-test 'dollar-substitution-looking thing in filter, non-matching value' \ | ||
"${cmd}" --looks-like-dollar=$'no abczz' |
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,28 @@ | ||
#!/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 --var=value --filter='/^/' nop | ||
opt-value --var=value --filter='/./' non-empty | ||
opt-value --var=value --filter=$'/\'x\'/' looks-like-sq-string | ||
opt-value --var=value --filter='/"x"/' looks-like-dq-string | ||
|
||
Z='zzz' | ||
opt-value --var=value --filter=$'/abc$Z?/' looks-like-dollar | ||
|
||
process-args "$@" || exit "$?" | ||
|
||
echo "value: $(vals "${value}")" |
Oops, something went wrong.