Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
diff tests/common.t @ 809:6cf3e1021862
common.subr: Change handling of internal errors.
They now
- return 64 or 70
- print always an error message to stderr
- set the given option variable to the null value
- unset OPTARG
in *every* case. This is independent whether the short options start with
an `:' character or not.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 05 Nov 2024 18:42:40 +0100 |
| parents | 2cd233b137ec |
| children |
line wrap: on
line diff
--- a/tests/common.t Tue Nov 05 11:57:34 2024 +0100 +++ b/tests/common.t Tue Nov 05 18:42:40 2024 +0100 @@ -46,14 +46,14 @@ $ [ "${opt_b_val}" = "value-of-b" ] $ [ -z "${error}" ] -Not null-terminated long options speccifications +Not null-terminated long options specifications $ OPTIND=1 > getopts "ab:-:" opt --long-a --long-b arg > postprocess_getopts_for_long "ab:-:" opt "long-a" "long-b" /bin/sh: ERROR: Missing null terminator for long option specifications - [1] - $ [ "${opt}" = '?' ] + [64] + $ [ -z "${opt}" ] $ [ -z "${OPTARG+SET}" ] Not null-terminated long options specs (alternate error handling) @@ -61,10 +61,10 @@ $ OPTIND=1 > getopts ":ab:-:" opt --long-a --long-b arg > postprocess_getopts_for_long ":ab:-:" opt "long-a" "long-b" - [1] - $ [ "${opt}" = ':' ] - $ [ -n "${OPTARG+SET}" ] - $ [ -z "${OPTARG}" ] + /bin/sh: ERROR: Missing null terminator for long option specifications + [64] + $ [ -z "${opt}" ] + $ [ -z "${OPTARG+SET}" ] Illegal long option @@ -234,83 +234,43 @@ Invalid character in long option $ error='' - > opt_a=no > OPTIND=1 - > while getopts "ab:-:" opt --long=a ; do - > postprocess_getopts_for_long "ab:-:" opt "long=a" "" --long=a arg - > case "$opt" in - > a|long=a) opt_a=yes - > [ -z "${OPTARG+SET}" ] || echo "ERROR: OPTARG" - > ;; - > \?) - > error=foo - > ;; - > *) - > error=bar - > ;; - > esac - > done + > getopts "ab:-:" opt --long=a + > postprocess_getopts_for_long "ab:-:" opt "long=a" "" --long=a arg /bin/sh: ERROR: Long option specification contains a forbidden `=' character: long=a - $ [ "${error}" = "foo" ] + [64] + $ [ -z "${opt}" ] + $ [ -z "${OPTARG+SET}" ] Invalid character in long option (alternate error handling) $ error='' - > opt_a=no > OPTIND=1 - > while getopts ":a-:" opt --long=a ; do - > postprocess_getopts_for_long ":a-:" opt "long=a" "" --long=a arg - > case "$opt" in - > a|long=a) opt_a=yes - > [ -z "${OPTARG+SET}" ] || echo "ERROR: OPTARG" - > ;; - > \?) - > error="${OPTARG}" - > ;; - > *) - > error=bar - > ;; - > esac - > done - $ [ "${error}" = "long=a" ] + > getopts ":a-:" opt --long=a + > postprocess_getopts_for_long ":a-:" opt "long=a" "" --long=a arg + /bin/sh: ERROR: Long option specification contains a forbidden `=' character: long=a + [64] + $ [ -z "${opt}" ] + $ [ -z "${OPTARG+SET}" ] Invalid character in long option $ error='' - > opt_b=no > OPTIND=1 - > while getopts "b:-:" opt --long=a ; do - > postprocess_getopts_for_long "b:-:" opt "long=b=" "" --long=b=value arg - > case "$opt" in - > b|long=b) opt_b=yes - > ;; - > \?) - > error=foo - > ;; - > *) - > error=bar - > ;; - > esac - > done + > getopts "b:-:" opt --long=a + > postprocess_getopts_for_long "b:-:" opt "long=b=" "" --long=b=value arg /bin/sh: ERROR: Long option specification contains a forbidden `=' character: long=b= - $ [ "${error}" = "foo" ] + [64] + $ [ -z "${opt}" ] + $ [ -z "${OPTARG+SET}" ] Invalid character in long option (alternate error handling) $ error='' - > opt_b=no > OPTIND=1 - > while getopts ":b:-:" opt --long=a ; do - > postprocess_getopts_for_long ":b:-:" opt "long=b=" "" --long=b=value arg - > case "$opt" in - > b|long=b) opt_b=yes - > ;; - > \?) - > error="${OPTARG}" - > ;; - > *) - > error=bar - > ;; - > esac - > done - $ [ "${error}" = "long=b=" ] + > getopts ":b:-:" opt --long=a + > postprocess_getopts_for_long ":b:-:" opt "long=b=" "" --long=b=value arg + /bin/sh: ERROR: Long option specification contains a forbidden `=' character: long=b= + [64] + $ [ -z "${opt}" ] + $ [ -z "${OPTARG+SET}" ] \ No newline at end of file
