X-Git-Url: https://git.draconx.ca/gitweb/dxcommon.git/blobdiff_plain/62bc7469bf3ef88c4f81ddf615aa7dabe9ddbf74..d4f7fab64222a7d3ce15e86c5c7b32f7cdd3ce93:/tests/scripts.at diff --git a/tests/scripts.at b/tests/scripts.at index 70df388..3a91bd0 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 "$builddir/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; }; @@ -91,55 +127,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]) @@ -169,42 +173,88 @@ int main(void) if (SOPT_STRING[i+1] != ':') putchar('\n'); } + return 0; } ]]) -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]) +AT_CLEANUP + +AT_SETUP([gen-options.awk xgettext annotation]) +TEST_GEN_OPTIONS([TEST_GEN_OPTIONS_SAMPLE]) + # 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; +} +]]) + +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; }]) -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 @@ -221,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; }; @@ -257,25 +306,22 @@ int main(void) else printf("'%c'\n", o.val); } + return 0; } ]]) -AT_DATA([single.dat], -[[--single-option -]]) -AT_CHECK([$AWK -f "$builddir/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 "$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' @@ -312,26 +358,23 @@ newline\ # with a comment ]]) -AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" test.h]) +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 @@ -374,13 +417,13 @@ AT_KEYWORDS([gen-strtab awk script scripts]) AT_DATA([test0.def], [[&hello hello ]]) -AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" test0.h]) +AT_CHECK([$AWK -f "$srcdir/scripts/gen-strtab.awk" test0.h]) AT_DATA([test1.def], [[@nozero &hello hello ]]) -AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" test1.h]) +AT_CHECK([$AWK -f "$srcdir/scripts/gen-strtab.awk" test1.h]) AT_DATA([test.c], [[#include @@ -396,6 +439,37 @@ AT_CHECK([$CC -DHEADER='"test1.h"' -o test1$EXEEXT test.c && ./test1$EXEEXT], AT_CLEANUP +AT_SETUP([gen-strtab.awk @macro option]) +AT_KEYWORDS([gen-strtab awk script scripts]) + +AT_DATA([test0.def], +[[@macro +&foo foobar +&bar bar +&baz baz +]]) +AT_CHECK([$AWK -f "$srcdir/scripts/gen-strtab.awk" test0.h]) + +AT_DATA([test0.c], +[[#include +extern const char strtab[]; +#include "test0.h" + +int main(void) +{ + static const char mystrtab[] = STRTAB_INITIALIZER; + printf("%s\n%s\n%s\n", mystrtab+foo, mystrtab+bar, mystrtab+baz); + return 0; +} +]]) +AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], +[[foobar +bar +baz +]]) + +AT_CLEANUP + AT_SETUP([gen-strtab.awk l10n options]) AT_KEYWORDS([gen-strtab awk script scripts]) @@ -409,7 +483,7 @@ AT_DATA([test0.def], &b world &c goodbye ]]) -AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" test0.h]) +AT_CHECK([$AWK -f "$srcdir/scripts/gen-strtab.awk" test0.h]) AT_CHECK([sed -n -f l10n.sed test0.h | LC_ALL=C sort], [0], [["goodbye" "hello world" @@ -421,7 +495,7 @@ AT_DATA([test1.def], &&b world &&c goodbye ]]) -AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" test1.h]) +AT_CHECK([$AWK -f "$srcdir/scripts/gen-strtab.awk" test1.h]) AT_CHECK([sed -n -f l10n.sed test1.h], [0], [["hello world" ]]) @@ -476,7 +550,7 @@ ROOT1 # comment ]]) -AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" tree.h]) +AT_CHECK([$AWK -f "$srcdir/scripts/gen-tree.awk" tree.h]) AT_DATA([test0.c], [[#include "tree.h" @@ -534,7 +608,7 @@ ROOT e 1 f 2 ]]) -AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" tree.h]) +AT_CHECK([$AWK -f "$srcdir/scripts/gen-tree.awk" tree.h]) AT_DATA([test0.c], [[float tree_strtab = 0; @@ -554,6 +628,7 @@ int main(void) for (i = 0; i < sizeof root / sizeof root[0]; i++) { printf("%d, %d\n", root[i].num, root[i].offset); } + return 0; } ]]) @@ -576,7 +651,7 @@ AT_DATA([flat.def], c 3 @nostrtab ]]) -AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" flat.h]) +AT_CHECK([$AWK -f "$srcdir/scripts/gen-tree.awk" 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], @@ -591,7 +666,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 @@ -805,24 +880,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]) @@ -832,21 +908,29 @@ grep SED_HEADER test.mk], [0], [expout]) AT_CLEANUP AT_SETUP([fix-gnulib.pl %reldir% substitution]) +AT_KEYWORDS([fix-gnulib perl script scripts]) 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} +sed -n expout ' +$G +$p +$b /^## begin gnulib/,/^## end gnulib/!b -/^#/{p;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 +/^MOSTLYCLEANFILES/{ +h +b +} +p' AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit sed -n -e '/^## begin gnulib/,/^## end gnulib/p' \ @@ -856,6 +940,7 @@ sed -n -e '/^## begin gnulib/,/^## end gnulib/p' \ AT_CLEANUP AT_SETUP([fix-gnulib.pl warning removal]) +AT_KEYWORDS([fix-gnulib perl script scripts]) AT_DATA([test.mk.in], [[ ## test begin @@ -875,6 +960,7 @@ 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 @@ -982,6 +1068,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])])