]> git.draconx.ca Git - dxcommon.git/blobdiff - tests/scripts.at
gen-tree.awk: Add options to tweak the strtab output.
[dxcommon.git] / tests / scripts.at
index fdc0240ad25ee54e1b4d1f6a2c1383a56ea430a8..dcbcce56ead507575e2e45f83920daa05907bad6 100644 (file)
@@ -7,6 +7,7 @@ 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_DATA([options.def],
 [[--option-only
@@ -220,6 +221,7 @@ p
 AT_CLEANUP
 
 AT_SETUP([gen-strtab.awk])
+AT_KEYWORDS([gen-strtab awk script scripts])
 
 AT_DATA([test.def],
 [[
@@ -301,6 +303,8 @@ oneline
 AT_CLEANUP
 
 AT_SETUP([gen-tree.awk])
+AT_KEYWORDS([gen-tree awk script scripts])
+
 AT_DATA([tree.def],
 [[ROOT0
   r0a, r0a_OFFSET
@@ -359,6 +363,7 @@ int main(void)
   print_subtree(tree0, 0, 1);
   printf("ROOT1\n");
   print_subtree(tree1, 0, 1);
+  return 0;
 }
 ]])
 cp tree.def expout
@@ -366,7 +371,76 @@ AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [expout])
 
 AT_CLEANUP
 
+# Test the gen-tree features that avoid creating string labels for nodes.
+AT_SETUP([gen-tree.awk @nostrtab option])
+AT_KEYWORDS([gen-tree awk script scripts])
+
+AT_DATA([tree.def],
+[[@nostrtab
+ROOT
+ a 1, a_OFFSET
+  b 1
+  c 2
+ d 2, d_OFFSET
+  e 1
+  f 2
+]])
+AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <tree.def >tree.h])
+
+AT_DATA([test0.c],
+[[float tree_strtab = 0;
+#define a []
+#define b []
+#define c []
+#define e []
+#define f []
+#include "tree.h"
+#include <stdio.h>
+
+static struct { int num, offset; } root[] = { ROOT_INITIALIZER };
+
+int main(void)
+{
+  unsigned i;
+  for (i = 0; i < sizeof root / sizeof root[0]; i++) {
+    printf("%d, %d\n", root[i].num, root[i].offset);
+  }
+}
+]])
+
+AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0],
+[[1, 3
+2, 6
+0, 0
+1, 0
+2, 0
+0, 0
+1, 0
+2, 0
+0, 0
+]])
+
+AT_DATA([flat.def],
+[[FLAT
+ a 1
+ b 2
+ c 3
+@nostrtab
+]])
+AT_CHECK([$AWK -f "$builddir/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],
+[[1, 0
+2, 0
+3, 0
+0, 0
+]])
+
+AT_CLEANUP
+
 AT_SETUP([join.awk])
+AT_KEYWORDS([join awk script scripts])
 
 JOIN="$AWK -f $builddir/scripts/join.awk --"
 
@@ -580,14 +654,22 @@ AT_CHECK([echo wat | $JOIN -v1 - /dev/null], [0],
 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" "$@"
+}
 test_fix_gnulib () {
   $PERL -e 'my $x = 42; exit $x;'; test $? = 42 || exit 77
   $PERL -f "$srcdir/scripts/fix-gnulib.pl" "$@"
 }
 test_gnulib_mk () {
-  echo; sed -n -f - "$srcdir/tests/data/gnulib.mk" <<EOF
-/^## begin gnulib module $1/,/^## end   gnulib module $1/p
+  echo;
+  for arg
+  do
+    sed -n -f - "$srcdir/tests/data/gnulib.mk" <<EOF
+/^## begin gnulib module $arg/,/^## end   gnulib module $arg/p
 EOF
+  done
 }
 m4_divert_pop([PREPARE_TESTS])
 
@@ -599,3 +681,169 @@ AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
 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_DATA([test.mk.in], [[
+## test begin
+noinst_LTLIBRARIES += libgnu.la
+libgnu_la_CFLAGS = $(AM_CFLAGS) $(GL_CFLAG_GNULIB_WARNINGS)
+noinst_LIBRARIES += libgnu.a
+libgnu_a_CFLAGS = $(AM_CFLAGS) $(GL_CFLAG_GNULIB_WARNINGS)
+## test end
+]])
+AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
+sed -n '/^## test begin/,/^## test end/p' test.mk], [0], [## test begin
+EXTRA_LTLIBRARIES += libgnu.la
+EXTRA_LIBRARIES += libgnu.a
+## test end
+])
+
+AT_CLEANUP
+
+AT_SETUP([fix-gnulib.pl header directory creation])
+
+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
+]])
+
+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)
+]])
+
+AT_CLEANUP
+
+dnl TEST_FIND_AUTOMAKE_VER([to-check], [test-action])
+dnl
+dnl For each whitespace-separated version token in to-check, check if we can
+dnl run the programs automake-VER and aclocal-VER.  The special token 'default'
+dnl also checks the unversioned automake and aclocal (or, if set in the
+dnl environment, $AUTOMAKE and $ACLOCAL).
+dnl
+dnl Then test-action is expanded such that shell variables $ac and $am refer to
+dnl the aclocal and automake programs, and $amver is the actual version
+dnl reported by --version.  The action should do nothing if the version is
+dnl acceptable, or "continue" if the version is unacceptable.
+dnl
+dnl If an acceptable version is found, the AUTOMAKE and ACLOCAL environment
+dnl variables are set accordingly.  Otherwise, the test group is skipped.
+m4_define([TEST_FIND_AUTOMAKE],
+[have_am=false
+for am in $1; do
+  AS_CASE([$am],
+    [default], [ac=${ACLOCAL-aclocal} am=${AUTOMAKE-automake}],
+    [ac=aclocal-$am; am=automake-$am])
+  amver=`$am --version | sed -n '1s/.* //p'`
+  acver=`$ac --version | sed -n '1s/.* //p'`
+  set x $amver $acver; shift; test x"$[]#" = x"2" || continue
+  test x"$amver" = x"$acver" || continue
+  $2
+  have_am=:; break
+done
+AT_CHECK([$have_am || exit 77])
+AUTOMAKE=$am; export AUTOMAKE
+ACLOCAL=$ac; export ACLOCAL
+AT_CHECK([$ACLOCAL --version && $AUTOMAKE --version], [0], [stdout])
+])
+
+m4_define([TEST_LTDL_LIBOBJ_MANGLING],
+[TEST_CONFIGURE_AC([[AM_INIT_AUTOMAKE([foreign subdir-objects])
+AC_PROG_CC
+LT_INIT
+AC_SUBST([ltdl_LTLIBOBJS], [libltdl/test.lo])
+AC_CONFIG_FILES([Makefile])
+]])
+
+mkdir libltdl
+AT_DATA([ltdl.mk.in], [[
+AM_CPPFLAGS += -DSTRING=\"helloworld\"
+
+noinst_LTLIBRARIES = libltdl/libltdl.la
+libltdl_libltdl_la_SOURCES = libltdl/ltdl.c
+libltdl_libltdl_la_LIBADD = $(ltdl_LTLIBOBJS)
+libltdl_libltdl_la_DEPENDENCIES = $(ltdl_LTLIBOBJS)
+
+EXTRA_DIST += libltdl/test.c
+]])
+AT_DATA([Makefile.am], [[AM_CPPFLAGS =
+include $(top_srcdir)/ltdl.mk
+AM_LIBTOOLFLAGS = --quiet
+bin_PROGRAMS = test
+test_SOURCES =
+test_LDADD = libltdl/libltdl.la
+all-local: ; @printf '%s\n' $(AM_CPPFLAGS)
+]])
+AT_DATA([libltdl/test.c], [[#include <stdio.h>
+int foo(void) { printf("%s\n", STRING); return 0; }
+]])
+AT_DATA([libltdl/ltdl.c], [[int foo(void); int main(void) { return foo(); }
+]])
+
+AT_CHECK([test_fix_ltdl -i ltdl.mk.in -o ltdl.mk])
+libtoolize; TEST_AUTORECONF
+TEST_CONFIGURE([--disable-shared])
+AT_CHECK([make -s && ./test], [0], [
+helloworld
+])])
+
+AT_SETUP([fix-ltdl.pl LIBOBJ mangling (<automake-1.16)])
+
+TEST_FIND_AUTOMAKE([default 1.10 1.11 1.12 1.13 1.14 1.15],
+  [AS_VERSION_COMPARE(["$amver"], [1.16], [], [continue], [continue])])
+TEST_LTDL_LIBOBJ_MANGLING
+
+AT_CLEANUP
+
+AT_SETUP([fix-ltdl.pl LIBOBJ mangling (>=automake-1.16)])
+
+TEST_FIND_AUTOMAKE([default 1.16 1.17 1.18 1.19],
+  [AS_VERSION_COMPARE(["$amver"], [1.16], [continue])])
+TEST_LTDL_LIBOBJ_MANGLING
+
+AT_CLEANUP