-dnl Copyright © 2021-2022 Nick Bowler
+dnl Copyright © 2021-2023 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.
AT_BANNER([Script tests])
AT_SETUP([gen-options.awk])
+AT_KEYWORDS([gen-options awk script scripts])
AT_DATA([options.def],
[[--option-only
if (SOPT_STRING[i+1] != ':')
putchar('\n');
}
+ return 0;
}
]])
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; };
+
+#include "options.h"
+
+static unsigned opts[] = { LOPTS_PACKED_INITIALIZER };
+
+int main(void)
+{
+ unsigned i;
+ int x =
+#if !LOPT_PACK_BITS
+ 0
+#elif LOPT_PACK_BITS <= 8
+ 1
+#elif LOPT_PACK_BITS <= 16
+ 2
+#elif LOPT_PACK_BITS <= 32
+ 3
+#else
+# error too big
+#endif
+ ;
+ printf("%d\n", x);
+ for (i = 0; i < sizeof opts / sizeof opts[0]; i++) {
+ struct option o;
+
+ LOPT_UNPACK(o, opts[i]);
+ printf("--%s, %d, ", o.name, o.has_arg);
+ if (o.val > UCHAR_MAX)
+ printf("%d\n", o.val - UCHAR_MAX - 1);
+ else
+ printf("'%c'\n", o.val);
+ }
+ return 0;
+}
+]])
+
+AT_DATA([single.dat],
+[[--single-option
+]])
+AT_CHECK([$AWK -f "$builddir/scripts/gen-options.awk" <single.dat >options.h])
+AT_CHECK([$CC -o single$EXEEXT test.c && ./single$EXEEXT], [0],
+[[0
+--single-option, 0, 0
+]])
+
+AT_DATA([16bit.dat],
+[[-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])
+AT_CHECK([$CC -o 16bit$EXEEXT test.c && ./16bit$EXEEXT], [0],
+[[2
+--the-first-option, 0, 'a'
+--the-second-option, 1, 'b'
+--the-third-option, 2, 'c'
+--the-fourth-option, 0, 'd'
+]])
+
+AT_CLEANUP
+
AT_SETUP([gen-strtab.awk])
+AT_KEYWORDS([gen-strtab awk script scripts])
AT_DATA([test.def],
[[
---
], [ignore])
+AT_CLEANUP
+
+AT_SETUP([gen-strtab.awk @nozero option])
+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_DATA([test1.def],
+[[@nozero
+&hello hello
+]])
+AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test1.def >test1.h])
+
+AT_DATA([test.c],
+[[#include <stdio.h>
+#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_CLEANUP
+
+AT_SETUP([gen-strtab.awk l10n options])
+AT_KEYWORDS([gen-strtab awk script scripts])
+
+AT_DATA([l10n.sed], dnl (
+[[/^#/b
+s/.*N_(\([^)]*\)).*/\1/p
+]])
+
+AT_DATA([test0.def],
+[[&a hello world
+&b world
+&c goodbye
+]])
+AT_CHECK([$AWK -f "$builddir/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"
+"world"
+]])
+
+AT_DATA([test1.def],
+[[&a hello world
+&&b world
+&&c goodbye
+]])
+AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test1.def >test1.h])
+AT_CHECK([sed -n -f l10n.sed test1.h], [0],
+[["hello world"
+]])
+
+AT_DATA([test.c],
+[[#include <stdio.h>
+#include HEADER
+
+int main(void)
+{
+ printf("%s %s %s\n", strtab+a, strtab+b, strtab+c);
+ return 0;
+}
+]])
+
+AT_CHECK([$CC -DHEADER='"test0.h"' -o test0$EXEEXT test.c && ./test0$EXEEXT],
+ [0], [[hello world world goodbye
+]])
+
+AT_CHECK([$CC -DHEADER='"test1.h"' -o test1$EXEEXT test.c && ./test1$EXEEXT],
+ [0], [[hello world world goodbye
+]])
+
+
AT_CLEANUP
AT_SETUP([gen-tree.awk])
+AT_KEYWORDS([gen-tree awk script scripts])
+
AT_DATA([tree.def],
-[[ROOT0
+[[# comment
+ROOT0
r0a, r0a_OFFSET
r0b, r0b_OFFSET
r0c
r0e, r0e_OFFSET
r0f
r0g
+# comment
ROOT1
r1a, r1a_OFFSET
r1b, r1b_OFFSET
r1e
r1b
r1e
+# comment
]])
AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <tree.def >tree.h])
print_subtree(tree0, 0, 1);
printf("ROOT1\n");
print_subtree(tree1, 0, 1);
+ return 0;
}
]])
-cp tree.def expout
+sed '/^#/d' tree.def >expout
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);
+ }
+ return 0;
+}
+]])
+
+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 --"
$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])
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