From c3b7ff6af1fa247b4df631d924f8b79fc6f6fc90 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 22 Jan 2023 23:23:52 -0500 Subject: [PATCH] tests: Generate gen-options.awk expected output better. In the main test group for gen-options.awk, various combinations of sed and shell line noise are used to create the expected output. It turns out that at least some versions of Solaris /bin/sed don't accept patterns like [^\n] as meaning "any character other than newline", which causes this line noise to fail. We could perhaps use /usr/xpg4/bin/sed instead which seems to not have this specific problem, but let's just do everything in awk which is much simpler. --- tests/scripts.at | 145 ++++++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 71 deletions(-) diff --git a/tests/scripts.at b/tests/scripts.at index 6c90f5a..c03a83f 100644 --- a/tests/scripts.at +++ b/tests/scripts.at @@ -91,55 +91,23 @@ int main(void) } ]]) -# pick out interesting bits from the definitions file -sed -n '/^-/s/^.*--\([[^\= @<:@]]*\).*$/\1/p' options.def >options -sed -n '/^-/{ - s/[[^=]]*\(=[[^@:>@ ]]*\).*$/\1/ - s/^[[^=]].*// - s/^=// - p -}' options.def >argnames - -AS_ECHO(["-"]) | sed -n '1s/^-.*//p -1,/^-/d -t clear -:clear -s/^-.*//p -t -s/^#.*// -s/^ *// -t next -:next -N -s/\n-.*// -t done -s/\n#.*// -s/\n */\n/g -t next -:done -s/"/\\\\"/g -s/[[^\n]][[^\n]]*/\\"&\\"/g -s/^\n*// -s/\n*$// -s/\n\n*/ /g -p -' options.def - >helptext - -exec 3expout -while read opt <&3 && read arg <&4 && read help <&5; do - if test ${arg:+y}; then - AS_ECHO(["--$opt=$arg"]) >&6 - else - AS_ECHO(["--$opt"]) >&6 - fi - eval "set x $help"; shift - for arg - do - AS_ECHO(["$arg"]) >&6 - done -done -exec 3<&- 4<&- 5<&- 6>&- +AT_DATA([lopthelp.awk], +[[/^#/ { next } +/^-/ { + if ($1 !~ /^--/) + $1 = $2; + if (sub(/\@:>@$/, "", $1)) + sub(/\@<:@/, "", $1); + + print $1; + next; +} +{ sub(/^[ \t]*/, ""); } +/./ { print; } +]]) + +$AWK -f lopthelp.awk options.def >expout AT_CHECK([$CC -o test1$EXEEXT test1.c && ./test1$EXEEXT], [0], [expout], [ignore]) @@ -173,39 +141,74 @@ int main(void) } ]]) -sed -n '/^-/{ - s/=.*/:/ - s/[[@<:@]]/:/ - s/^-\([[^-]]\)[[^:]]*/\1/p - s/^-.*//p -}' options.def >sopts +AT_DATA([soptstr.awk], +[[/^-/ { + if ($1 ~ /^--/) + next; -exec 3expout -while read lopt <&3 && read sopt <&4; do - if test ${sopt:+y}; then - AS_ECHO(["--$lopt $sopt"]) >&5 - fi -done -exec 3<&- 4<&- 5>&- + sopt = substr($1, 2, 1); + arg = sub(/\@:>@$/, "", $2); + arg += sub(/\@<:@?=.*$/, "", $2); + + print $2 " " sopt substr("::", 1, arg); +} +]]) +$AWK -f soptstr.awk options.def >expout AT_CHECK([$CC -o test2$EXEEXT test2.c && ./test2$EXEEXT], [0], [expout], [ignore]) # Check that all help strings are translatable -sed 's/\([[^\\]]\\\)" /\1\\n\\" /g' helptext >help-po -exec 3expected.po -while read opt <&3 && read arg <&4 && read help <&5; do - if test ${arg:+y}; then - AS_ECHO(["msgctxt \"$opt\" msgid \"$arg\""]) >&6 - fi - AS_ECHO(["msgctxt \"$opt\" msgid${help:+ }$help"]) >&6 -done -exec 3<&- 4<&- 5<&- 6>&- +AT_DATA([messages.awk], +[[BEGIN { lines = -1; } +END { output(); } + +/^#/ { next } +/^-/ { + output(); + if ($1 !~ /^--/) + $1 = $2; + + tmp=$1; + arg=""; + if (sub(/\@<:@?=.*/, "", $1)) { + arg = substr(tmp, index(tmp, "=")+1); + sub(/\@:>@$/, "", arg); + } + + sub(/^--/, "", $1); + ctxt=("msgctxt \"" $1 "\" msgid"); + + if (arg) + print ctxt, ("\"" arg "\""); + next; +} + +{ sub(/^[ \t]*/, ""); } +/./ { + gsub(/"/, "\\\"", $0); + help[lines++] = $0; +} + +function output(i) +{ + if (lines >= 0) { + printf "%s", ctxt; + for (i = 0; i < lines; i++) { + nl = (i+1 < lines ? "\\n" : ""); + printf(" \"%s%s\"", help[i], nl); + } + print ""; + } + + lines = 0; +} +]]) AT_CHECK([xgettext --keyword=PN_:1c,2 options.h test -f messages.po || exit 77]) -LC_ALL=C sort expected.po >expout +$AWK -f messages.awk options.def | LC_ALL=C sort >expout AT_CHECK([sed -n '/^msgctxt/{ t next :next -- 2.43.2