]> git.draconx.ca Git - dxcommon.git/commitdiff
gen-options.awk: Fix test with older gettext.
authorNick Bowler <nbowler@draconx.ca>
Fri, 17 Nov 2023 04:17:22 +0000 (23:17 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sat, 18 Nov 2023 21:39:55 +0000 (16:39 -0500)
Really old versions of xgettext do not support msgctx, but they do
produce _some_ output so the test is not skipped, just fails.

Enhance the xgettext probe to skip the test with these old versions, and
split it into two so we can still get a proper pass result for the rest.

tests/scripts.at

index c38faba07caf02cc03fa5836ec85d39e92ef2297..880bb6c9b7c81dfd99b14a486147bcc356234a78 100644 (file)
@@ -6,10 +6,13 @@ dnl There is NO WARRANTY, to the extent permitted by law.
 
 AT_BANNER([Script tests])
 
-AT_SETUP([gen-options.awk])
-AT_KEYWORDS([gen-options awk script scripts])
+m4_define([TEST_GEN_OPTIONS],
+[AT_KEYWORDS([gen-options awk script scripts])dnl
+AT_DATA([m4_default([$2], [options.def])], [$1])
+AT_CHECK([$AWK -f "$srcdir/scripts/gen-options.awk" dnl
+<m4_default([$2], [options.def]) >options.h])])
 
-AT_DATA([options.def],
+m4_define([TEST_GEN_OPTIONS_SAMPLE],
 [[--option-only
 --option-with-val (5)
 --option-with-flagval (&x, 5)
@@ -37,7 +40,8 @@ do stuff with ARG
 --flagval
 ]])
 
-AT_CHECK([$AWK -f "$srcdir/scripts/gen-options.awk" <options.def >options.h])
+AT_SETUP([gen-options.awk])
+TEST_GEN_OPTIONS([TEST_GEN_OPTIONS_SAMPLE])
 
 AT_DATA([context.h],
 [[struct option { const char *name; int has_arg; int *flag; int val; };
@@ -158,6 +162,11 @@ $AWK -f soptstr.awk options.def >expout
 AT_CHECK([$CC -o test2$EXEEXT test2.c && ./test2$EXEEXT],
   [0], [expout], [ignore])
 
+AT_CLEANUP
+
+AT_SETUP([gen-options.awk xgettext annotation])
+TEST_GEN_OPTIONS([TEST_GEN_OPTIONS_SAMPLE])
+
 # Check that all help strings are translatable
 AT_DATA([messages.awk],
 [[BEGIN { lines = -1; }
@@ -205,8 +214,13 @@ function output(i)
 }
 ]])
 
+dnl Antique versions of xgettext which predate the pgettext/msgctx feature
+dnl will produce an output po file with no msgctx lines.  So try to spot
+dnl that and skip the test with such versions.
 AT_CHECK([xgettext --keyword=PN_:1c,2 options.h
-  test -f messages.po || exit 77])
+  test -f messages.po || exit 77
+  grep msgid messages.po >/dev/null &&
+    { grep msgctx messages.po >/dev/null || exit 77; }])
 
 $AWK -f messages.awk options.def | LC_ALL=C sort >expout
 AT_CHECK([sed -n '/^msgctxt/{
@@ -225,7 +239,6 @@ p
 AT_CLEANUP
 
 AT_SETUP([gen-options.awk packed format])
-AT_KEYWORDS([gen-options awk script scripts])
 
 AT_DATA([test.c], [[#include <stdio.h>
 struct option { const char *name; int has_arg; int *flag; int val; };
@@ -265,22 +278,18 @@ int main(void)
 }
 ]])
 
-AT_DATA([single.dat],
-[[--single-option
-]])
-AT_CHECK([$AWK -f "$srcdir/scripts/gen-options.awk" <single.dat >options.h])
+TEST_GEN_OPTIONS([[--single-option
+]], [single.dat])
 AT_CHECK([$CC -o single$EXEEXT test.c && ./single$EXEEXT], [0],
 [[0
 --single-option, 0, 0
 ]])
 
-AT_DATA([16bit.dat],
-[[-a, --the-first-option
+TEST_GEN_OPTIONS([[-a, --the-first-option
 -b, --the-second-option=ARG
 -c, --the-third-option[=ARG]
 -d, --the-fourth-option
-]])
-AT_CHECK([$AWK -f "$srcdir/scripts/gen-options.awk" <16bit.dat >options.h])
+]], [16bit.dat])
 AT_CHECK([$CC -o 16bit$EXEEXT test.c && ./16bit$EXEEXT], [0],
 [[2
 --the-first-option, 0, 'a'