]> git.draconx.ca Git - dxcommon.git/blobdiff - tests/scripts.at
gen-strtab.awk: Work around HP-UX shell bug in test case.
[dxcommon.git] / tests / scripts.at
index 932a0621915acefd39c39ce5510cc0d88605bb64..dbec2c9024e9d54ec4b133aa6cf34b0a053561b6 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 "$builddir/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 "$builddir/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 "$builddir/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'
@@ -317,26 +326,23 @@ newline\
 # with a comment
 ]])
 
-AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test.def >test.h])
+AT_CHECK([$AWK -f "$srcdir/scripts/gen-strtab.awk" <test.def >test.h])
 
 sed -n 's/^[[&]]\([[^ ]]*\).*/\1/p' test.def >identifiers
 
 # test 0: sanity test
-AT_DATA([test0.c],
-[[#include "test.h"
+{ cat <<'EOF'
+#include "test.h"
 #include <stdio.h>
 
 int main(void)
 {
   printf("---\n");
-]])
-exec 3<identifiers 4>>test0.c
-while read ident <&3; do
-  AS_ECHO(['  printf("%s\n---\n", '"strtab+$ident);"]) >&4
-done
-AS_ECHO(['  return 0;']) >&4
-AS_ECHO(['}']) >&4
-exec 3<&- 4>&-
+EOF
+while read id; do AS_ECHO(['  printf("%s\n---\n", strtab+'"$id"');']); done
+AS_ECHO(['  return 0;'])
+AS_ECHO(['}'])
+} <identifiers >test0.c
 
 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [---
 world
@@ -379,13 +385,13 @@ AT_KEYWORDS([gen-strtab awk script scripts])
 AT_DATA([test0.def],
 [[&hello hello
 ]])
-AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test0.def >test0.h])
+AT_CHECK([$AWK -f "$srcdir/scripts/gen-strtab.awk" <test0.def >test0.h])
 
 AT_DATA([test1.def],
 [[@nozero
 &hello hello
 ]])
-AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test1.def >test1.h])
+AT_CHECK([$AWK -f "$srcdir/scripts/gen-strtab.awk" <test1.def >test1.h])
 
 AT_DATA([test.c],
 [[#include <stdio.h>
@@ -410,7 +416,7 @@ AT_DATA([test0.def],
 &bar bar
 &baz baz
 ]])
-AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test0.def >test0.h])
+AT_CHECK([$AWK -f "$srcdir/scripts/gen-strtab.awk" <test0.def >test0.h])
 
 AT_DATA([test0.c],
 [[#include <stdio.h>
@@ -445,7 +451,7 @@ AT_DATA([test0.def],
 &b world
 &c goodbye
 ]])
-AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test0.def >test0.h])
+AT_CHECK([$AWK -f "$srcdir/scripts/gen-strtab.awk" <test0.def >test0.h])
 AT_CHECK([sed -n -f l10n.sed test0.h | LC_ALL=C sort], [0],
 [["goodbye"
 "hello world"
@@ -457,7 +463,7 @@ AT_DATA([test1.def],
 &&b world
 &&c goodbye
 ]])
-AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test1.def >test1.h])
+AT_CHECK([$AWK -f "$srcdir/scripts/gen-strtab.awk" <test1.def >test1.h])
 AT_CHECK([sed -n -f l10n.sed test1.h], [0],
 [["hello world"
 ]])
@@ -512,7 +518,7 @@ ROOT1
 # comment
 ]])
 
-AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <tree.def >tree.h])
+AT_CHECK([$AWK -f "$srcdir/scripts/gen-tree.awk" <tree.def >tree.h])
 
 AT_DATA([test0.c],
 [[#include "tree.h"
@@ -570,7 +576,7 @@ ROOT
   e 1
   f 2
 ]])
-AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <tree.def >tree.h])
+AT_CHECK([$AWK -f "$srcdir/scripts/gen-tree.awk" <tree.def >tree.h])
 
 AT_DATA([test0.c],
 [[float tree_strtab = 0;
@@ -613,7 +619,7 @@ AT_DATA([flat.def],
  c 3
 @nostrtab
 ]])
-AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <flat.def >flat.h])
+AT_CHECK([$AWK -f "$srcdir/scripts/gen-tree.awk" <flat.def >flat.h])
 
 sed -e 's/tree\.h/flat.h/' -e 's/ROOT/FLAT/' test0.c >test1.c
 AT_CHECK([$CC -o test1$EXEEXT test1.c && ./test1$EXEEXT], [0],
@@ -628,7 +634,7 @@ AT_CLEANUP
 AT_SETUP([join.awk])
 AT_KEYWORDS([join awk script scripts])
 
-JOIN="$AWK -f $builddir/scripts/join.awk --"
+JOIN="$AWK -f $srcdir/scripts/join.awk --"
 
 AT_DATA([a],
 [[1 a