]> git.draconx.ca Git - dxcommon.git/blobdiff - tests/scripts.at
tests: Ignore output from the C compiler.
[dxcommon.git] / tests / scripts.at
index dbec2c9024e9d54ec4b133aa6cf34b0a053561b6..1748070616dd0477226cafc0694a9c678491c3e4 100644 (file)
@@ -1,4 +1,4 @@
-dnl Copyright © 2021-2023 Nick Bowler
+dnl Copyright © 2021-2024 Nick Bowler
 dnl
 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
 dnl This is free software: you are free to do what the fuck you want to.
@@ -6,6 +6,38 @@ dnl There is NO WARRANTY, to the extent permitted by law.
 
 AT_BANNER([Script tests])
 
+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])
@@ -61,7 +93,8 @@ int main(void)
   return 0;
 }
 ]])
-AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [], [ignore])
+AT_CHECK([$CC -o test0$EXEEXT test0.c 1>&2 && ./test0$EXEEXT],
+  [0], [], [ignore])
 
 # test 1: long option names and help text
 AT_DATA([test1.c],
@@ -112,7 +145,7 @@ AT_DATA([lopthelp.awk],
 ]])
 
 $AWK -f lopthelp.awk options.def >expout
-AT_CHECK([$CC -o test1$EXEEXT test1.c && ./test1$EXEEXT],
+AT_CHECK([$CC -o test1$EXEEXT test1.c 1>&2 && ./test1$EXEEXT],
   [0], [expout], [ignore])
 
 # test 2: short option string
@@ -159,7 +192,7 @@ AT_DATA([soptstr.awk],
 ]])
 
 $AWK -f soptstr.awk options.def >expout
-AT_CHECK([$CC -o test2$EXEEXT test2.c && ./test2$EXEEXT],
+AT_CHECK([$CC -o test2$EXEEXT test2.c 1>&2 && ./test2$EXEEXT],
   [0], [expout], [ignore])
 
 AT_CLEANUP
@@ -280,23 +313,23 @@ int main(void)
 
 TEST_GEN_OPTIONS([[--single-option
 ]], [single.dat])
-AT_CHECK([$CC -o single$EXEEXT test.c && ./single$EXEEXT], [0],
+AT_CHECK([$CC -o single$EXEEXT test.c 1>&2 && ./single$EXEEXT], [0],
 [[0
 --single-option, 0, 0
-]])
+]], [ignore])
 
 TEST_GEN_OPTIONS([[-a, --the-first-option
 -b, --the-second-option=ARG
 -c, --the-third-option[=ARG]
 -d, --the-fourth-option
 ]], [16bit.dat])
-AT_CHECK([$CC -o 16bit$EXEEXT test.c && ./16bit$EXEEXT], [0],
+AT_CHECK([$CC -o 16bit$EXEEXT test.c 1>&2 && ./16bit$EXEEXT], [0],
 [[2
 --the-first-option, 0, 'a'
 --the-second-option, 1, 'b'
 --the-third-option, 2, 'c'
 --the-fourth-option, 0, 'd'
-]])
+]], [ignore])
 
 AT_CLEANUP
 
@@ -324,6 +357,7 @@ newline\
 \   leading whitespace
 &j oneline
 # with a comment
+&k    with   nontrivial   whitespace
 ]])
 
 AT_CHECK([$AWK -f "$srcdir/scripts/gen-strtab.awk" <test.def >test.h])
@@ -344,7 +378,7 @@ AS_ECHO(['  return 0;'])
 AS_ECHO(['}'])
 } <identifiers >test0.c
 
-AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [---
+AT_CHECK([$CC -o test0$EXEEXT test0.c 1>&2 && ./test0$EXEEXT], [0], [---
 world
 ---
 hello world
@@ -375,6 +409,8 @@ nonewline
 ---
 oneline
 ---
+with   nontrivial   whitespace
+---
 ], [ignore])
 
 AT_CLEANUP
@@ -398,12 +434,12 @@ AT_DATA([test.c],
 #include HEADER
 int main(void) { printf("%d %s\n", hello, strtab+hello); return 0; }
 ]])
-AT_CHECK([$CC -DHEADER='"test0.h"' -o test0$EXEEXT test.c && ./test0$EXEEXT],
-  [0], [[0 hello
-]])
-AT_CHECK([$CC -DHEADER='"test1.h"' -o test1$EXEEXT test.c && ./test1$EXEEXT],
-  [0], [[1 hello
-]])
+AT_CHECK([$CC -DHEADER='"test0.h"' -o test0$EXEEXT test.c 1>&2 &&
+  ./test0$EXEEXT], [0], [[0 hello
+]], [ignore])
+AT_CHECK([$CC -DHEADER='"test1.h"' -o test1$EXEEXT test.c 1>&2 &&
+  ./test1$EXEEXT], [0], [[1 hello
+]], [ignore])
 
 AT_CLEANUP
 
@@ -430,11 +466,11 @@ int main(void)
   return 0;
 }
 ]])
-AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0],
+AT_CHECK([$CC -o test0$EXEEXT test0.c 1>&2 && ./test0$EXEEXT], [0],
 [[foobar
 bar
 baz
-]])
+]], [ignore])
 
 AT_CLEANUP
 
@@ -479,13 +515,13 @@ int main(void)
 }
 ]])
 
-AT_CHECK([$CC -DHEADER='"test0.h"' -o test0$EXEEXT test.c && ./test0$EXEEXT],
-  [0], [[hello world world goodbye
-]])
+AT_CHECK([$CC -DHEADER='"test0.h"' -o test0$EXEEXT test.c 1>&2 &&
+  ./test0$EXEEXT], [0], [[hello world world goodbye
+]], [ignore])
 
-AT_CHECK([$CC -DHEADER='"test1.h"' -o test1$EXEEXT test.c && ./test1$EXEEXT],
-  [0], [[hello world world goodbye
-]])
+AT_CHECK([$CC -DHEADER='"test1.h"' -o test1$EXEEXT test.c 1>&2 &&
+  ./test1$EXEEXT], [0], [[hello world world goodbye
+]], [ignore])
 
 
 AT_CLEANUP
@@ -558,7 +594,8 @@ int main(void)
 }
 ]])
 sed '/^#/d' tree.def >expout
-AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [expout])
+AT_CHECK([$CC -o test0$EXEEXT test0.c 1>&2 && ./test0$EXEEXT],
+  [0], [expout], [ignore])
 
 AT_CLEANUP
 
@@ -600,7 +637,7 @@ int main(void)
 }
 ]])
 
-AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0],
+AT_CHECK([$CC -o test0$EXEEXT test0.c 1>&2 && ./test0$EXEEXT], [0],
 [[1, 3
 2, 6
 0, 0
@@ -610,7 +647,7 @@ AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0],
 1, 0
 2, 0
 0, 0
-]])
+]], [ignore])
 
 AT_DATA([flat.def],
 [[FLAT
@@ -622,12 +659,12 @@ AT_DATA([flat.def],
 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],
+AT_CHECK([$CC -o test1$EXEEXT test1.c 1>&2 && ./test1$EXEEXT], [0],
 [[1, 0
 2, 0
 3, 0
 0, 0
-]])
+]], [ignore])
 
 AT_CLEANUP
 
@@ -848,24 +885,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" <<EOF
-/^## begin gnulib module $arg/,/^## end   gnulib module $arg/p
-EOF
+    sed -n -e \
+      "/^## begin gnulib module $arg/,/^## end   gnulib module $arg/p" \
+      "$srcdir/tests/data/gnulib.mk"
   done
 }
 m4_divert_pop([PREPARE_TESTS])
 
 AT_SETUP([fix-gnulib.pl SED_HEADER variables])
+AT_KEYWORDS([fix-gnulib perl script scripts])
 
 test_gnulib_mk gen-header >test.mk.in
 AT_CHECK([grep SED_HEADER test.mk.in >expout || exit 99])
@@ -874,31 +912,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
@@ -918,35 +933,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
@@ -1025,6 +1038,7 @@ helloworld
 ])])
 
 AT_SETUP([fix-ltdl.pl LIBOBJ mangling (<automake-1.16)])
+AT_KEYWORDS([fix-ltdl perl script scripts])
 
 TEST_FIND_AUTOMAKE([default 1.10 1.11 1.12 1.13 1.14 1.15],
   [AS_VERSION_COMPARE(["$amver"], [1.16], [], [continue], [continue])])
@@ -1033,6 +1047,7 @@ TEST_LTDL_LIBOBJ_MANGLING
 AT_CLEANUP
 
 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])])