X-Git-Url: http://git.draconx.ca/gitweb/dxcommon.git/blobdiff_plain/26e9c015ce57db05d46a3750ec6d52064ebc3ecb..06991b16dda9f3dc3991f39599512a7e94260667:/tests/scripts.at diff --git a/tests/scripts.at b/tests/scripts.at index c38faba..92db0a1 100644 --- a/tests/scripts.at +++ b/tests/scripts.at @@ -6,10 +6,45 @@ 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]) +AT_SETUP([bake-config.awk]) +AT_KEYWORDS([bake-config awk script scripts]) + +AT_DATA([cfg.h], +[[#define hello world +/* #undef HAVE_STUFF */ +#define HAVE_OTHER_STUFF 1 +/* #undef HAVE_CRAZY_STUFF */ +]]) + +AT_DATA([lib.h], +[[#if HAVE_STUFF +# define foo hello__ +#elif HAVE_CRAZY_STUFF +# define foo hello +#elif HAVE_OTHER_STUFF +# define foo __hello +#endif +]]) + +AT_CHECK([$AWK -f "$srcdir/scripts/bake-config.awk" cfg.h lib.h], [0], +[[#if 0 /* HAVE_STUFF */ +# define foo hello__ +#elif 0 /* HAVE_CRAZY_STUFF */ +# define foo world /* hello */ +#elif 1 /* HAVE_OTHER_STUFF */ +# define foo __hello +#endif +]]) + +AT_CLEANUP + +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 +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 +72,8 @@ do stuff with ARG --flagval ]]) -AT_CHECK([$AWK -f "$srcdir/scripts/gen-options.awk" 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 +194,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 +246,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 +271,6 @@ p AT_CLEANUP AT_SETUP([gen-options.awk packed format]) -AT_KEYWORDS([gen-options awk script scripts]) AT_DATA([test.c], [[#include struct option { const char *name; int has_arg; int *flag; int val; }; @@ -265,22 +310,18 @@ int main(void) } ]]) -AT_DATA([single.dat], -[[--single-option -]]) -AT_CHECK([$AWK -f "$srcdir/scripts/gen-options.awk" 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' @@ -315,6 +356,7 @@ newline\ \ leading whitespace &j oneline # with a comment +&k with nontrivial whitespace ]]) AT_CHECK([$AWK -f "$srcdir/scripts/gen-strtab.awk" test.h]) @@ -322,21 +364,18 @@ AT_CHECK([$AWK -f "$srcdir/scripts/gen-strtab.awk" 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 int main(void) { printf("---\n"); -]]) -exec 3>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(['}']) +} test0.c AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [--- world @@ -369,6 +408,8 @@ nonewline --- oneline --- +with nontrivial whitespace +--- ], [ignore]) AT_CLEANUP @@ -842,24 +883,25 @@ AT_CLEANUP m4_divert_push([PREPARE_TESTS])dnl test_fix_ltdl () { $PERL -e 'my $x = 42; exit $x;'; test $? = 42 || exit 77 - $PERL -f "$srcdir/scripts/fix-ltdl.pl" "$@" + $PERL "$srcdir/scripts/fix-ltdl.pl" "$@" } test_fix_gnulib () { $PERL -e 'my $x = 42; exit $x;'; test $? = 42 || exit 77 - $PERL -f "$srcdir/scripts/fix-gnulib.pl" "$@" + $PERL "$srcdir/scripts/fix-gnulib.pl" "$@" } test_gnulib_mk () { echo; for arg do - sed -n -f - "$srcdir/tests/data/gnulib.mk" <test.mk.in AT_CHECK([grep SED_HEADER test.mk.in >expout || exit 99]) @@ -868,31 +910,8 @@ grep SED_HEADER test.mk], [0], [expout]) AT_CLEANUP -AT_SETUP([fix-gnulib.pl %reldir% substitution]) - -test_gnulib_mk sys_types >test.mk.in -AT_CHECK([grep '%reldir%' test.mk.in >/dev/null || exit 99]) - -sed -n -f - test.mk.in >expout <<'EOF' -${G;p;b} -/^## begin gnulib/,/^## end gnulib/!b -/^#/{p;b} -s|(srcdir)|(top_srcdir)| -s|%reldir%|lib| -s|BUILT_SOURCES|gnulib_core_headers| -s|sys[[/_]]|lib/&|g -/^MOSTLYCLEANFILES/{h;b} -p -EOF - -AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit -sed -n -e '/^## begin gnulib/,/^## end gnulib/p' \ - -e '/CLEANFILES/p' test.mk], -[0], [expout]) - -AT_CLEANUP - AT_SETUP([fix-gnulib.pl warning removal]) +AT_KEYWORDS([fix-gnulib perl script scripts]) AT_DATA([test.mk.in], [[ ## test begin @@ -912,35 +931,33 @@ EXTRA_LIBRARIES += libgnu.a AT_CLEANUP AT_SETUP([fix-gnulib.pl header directory creation]) +AT_KEYWORDS([fix-gnulib perl script scripts]) -AT_DATA([extract.sed], -[[/AM_V_GEN/b ok -/gl_V_at/b ok -s/:.*/:/ -h -b -:ok -s/'//g -x -G -p -n -s/[)].*/)/ -p +AT_DATA([extract.awk], +[[$0 !~ /^\t/ && $1 ~ /:$/ { + target=$1; + + for (i = 2; i <= NF; i++) { + if ($i ~ /am__dirstamp/) + target = target " " $i; + } + + next; +} + +target != "" && sub(/[$][({](AM_V_GEN|gl_V_at)[})].*$/, "[OK]") { + print target, $1; +} + +{ target=""; } ]]) test_gnulib_mk alloca-opt sys_types stddef >test.mk.in AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit -sed -n -f extract.sed test.mk], [0], -[[lib/alloca.h: - $(AM_V_GEN)$(MKDIR_P) lib - $(AM_V_at) -lib/sys/types.h: - $(AM_V_GEN)$(MKDIR_P) lib/sys - $(AM_V_at) -lib/stddef.h: - $(AM_V_GEN)$(MKDIR_P) lib - $(AM_V_at) +$AWK -f extract.awk test.mk], [0], +[[lib/alloca.h: lib/$(am__dirstamp) [OK] +lib/sys/types.h: lib/sys/$(am__dirstamp) [OK] +lib/stddef.h: lib/$(am__dirstamp) [OK] ]]) AT_CLEANUP @@ -1019,6 +1036,7 @@ helloworld ])]) AT_SETUP([fix-ltdl.pl LIBOBJ mangling (=automake-1.16)]) +AT_KEYWORDS([fix-ltdl perl script scripts]) TEST_FIND_AUTOMAKE([default 1.16 1.17 1.18 1.19], [AS_VERSION_COMPARE(["$amver"], [1.16], [continue])])