diff --git a/src/cmd/ksh93/tests/builtins.sh b/src/cmd/ksh93/tests/builtins.sh index 6fd3893f6..3dde36cfd 100755 --- a/src/cmd/ksh93/tests/builtins.sh +++ b/src/cmd/ksh93/tests/builtins.sh @@ -774,5 +774,77 @@ unset foo [[ $(printf '%(%f)T') == $(printf '%(%Y.%m.%d-%H:%M:%S)T') ]] || err_exit 'date format %f is not the same as %Y.%m.%d-%H:%M:%S' [[ $(printf '%(%q)T') == $(printf '%(%Qz)T') ]] && err_exit 'date format %q is the same as %Qz' +# ====== +# Test various AST getopts usage/manual outputs + +OPTIND=1 +USAGE=$' +[-s8? +@(#)$Id: foo (ksh93) 2020-07-16 $ +] +[+NAME?foo - bar] +[+DESC?Baz.] +[x:xylophone?Lorem.] +[y:ypsilon?Ipsum.] +[z:zeta?Sit.] + +[ name=value ... ] +-y [ name ... ] + +[+SEE ALSO?\bgetopts\b(1)] +' + +function testusage { + getopts "$USAGE" dummy 2>&1 +} + +actual=$(testusage -\?) +expect='Usage: testusage [-xyz] [ name=value ... ] + Or: testusage [ options ] -y [ name ... ]' +[[ $actual == "$expect" ]] || err_exit "getopts: '-?' output" \ + "(expected $(printf %q "$expect"), got $(printf %q "$actual"))" + +actual=$(testusage --\?x) +expect='Usage: testusage [ options | --help | --man ] [ name=value ... ] + Or: testusage [ options ] -y [ name ... ] +OPTIONS + -x, --xylophone Lorem.' +[[ $actual == "$expect" ]] || err_exit "getopts: '--?x' output" \ + "(expected $(printf %q "$expect"), got $(printf %q "$actual"))" + +actual=$(testusage --help) +expect='Usage: testusage [ options | --help | --man ] [ name=value ... ] + Or: testusage [ options ] -y [ name ... ] +OPTIONS + -x, --xylophone Lorem. + -y, --ypsilon Ipsum. + -z, --zeta Sit.' +[[ $actual == "$expect" ]] || err_exit "getopts: '--help' output" \ + "(expected $(printf %q "$expect"), got $(printf %q "$actual"))" + +actual=$(testusage --man) +expect='NAME + foo - bar + +SYNOPSIS + foo [ options | --help | --man ] [ name=value ... ] + foo [ options | --help | --man ] -y [ name ... ] + +DESC + Baz. + +OPTIONS + -x, --xylophone Lorem. + -y, --ypsilon Ipsum. + -z, --zeta Sit. + +SEE ALSO + getopts(1) + +IMPLEMENTATION + version foo (ksh93) 2020-07-16' +[[ $actual == "$expect" ]] || err_exit "getopts: '--man' output" \ + "(expected $(printf %q "$expect"), got $(printf %q "$actual"))" + # ====== exit $((Errors<125?Errors:125)) diff --git a/src/lib/libast/misc/optget.c b/src/lib/libast/misc/optget.c index 7c735bbac..cafa2565c 100644 --- a/src/lib/libast/misc/optget.c +++ b/src/lib/libast/misc/optget.c @@ -176,7 +176,7 @@ static unsigned char map[UCHAR_MAX]; static Optstate_t state; -#if !_PACKAGE_astsa +#if 0 /* #if !_PACKAGE_astsa // this somehow corrupts "Or:" usage mesages, e.g. in 'typeset -\?' */ #define ID ast.id