]> git.draconx.ca Git - dxcommon.git/commitdiff
Implement initial test suite.
authorNick Bowler <nbowler@draconx.ca>
Tue, 10 Mar 2015 04:10:49 +0000 (21:10 -0700)
committerNick Bowler <nbowler@draconx.ca>
Sun, 19 Apr 2015 18:49:06 +0000 (14:49 -0400)
First stab at a new autotest-based test suite for dxcommon.  Start with
a simple test case to expose a longstanding problem in DX_BASEDIR.

.gitignore [new file with mode: 0644]
Makefile.am [new file with mode: 0644]
configure.ac [new file with mode: 0644]
m4/autotest.m4 [new file with mode: 0644]
m4/utils.m4 [new file with mode: 0644]
tests/macros.at [new file with mode: 0644]
testsuite.at [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..9171f9d
--- /dev/null
@@ -0,0 +1,14 @@
+/config.*
+/configure
+/aclocal.m4
+/autom4te.cache
+/install-sh
+/missing
+/testsuite.dir
+/testsuite.log
+/testsuite
+/package.m4
+/atconfig
+Makefile.in
+Makefile
+.deps
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..21b5f95
--- /dev/null
@@ -0,0 +1,58 @@
+# Copyright © 2015 Nick Bowler
+#
+# License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+# This is free software: you are free to do what the fuck you want to.
+# There is NO WARRANTY, to the extent permitted by law.
+
+ACLOCAL_AMFLAGS = -I m4
+
+EXTRA_DIST =
+SUFFIXES =
+
+check-local: check-autotest
+check-autotest: testsuite
+       $(SHELL) testsuite $(TESTSUITEFLAGS)
+.PHONY: check-autotest
+
+clean-local: clean-autotest
+clean-autotest:
+       test ! -f testsuite || $(SHELL) testsuite --clean
+.PHONY: clean-autotest
+
+maintainer-clean-local: maintainer-clean-autotest
+maintainer-clean-autotest:
+       rm -f testsuite package.m4
+.PHONY: maintainerclean-autotest
+
+package.m4:
+       $(AM_V_GEN) :; { \
+         printf 'm4_define([%s], [%s])\n' \
+           AT_PACKAGE_NAME      '$(PACKAGE_NAME)' \
+           AT_PACKAGE_TARNAME   '$(PACKAGE_TARNAME)' \
+           AT_PACKAGE_VERSION   '$(PACKAGE_VERSION)' \
+           AT_PACKAGE_STRING    '$(PACKAGE_STRING)' \
+           AT_PACKAGE_BUGREPORT '$(PACKAGE_BUGREPORT)' \
+           AT_PACKAGE_URL       '$(PACKAGE_URL)' \
+       ; } >$@.tmp
+       $(AM_V_at) mv -f $@.tmp $@
+
+testsuite: testsuite.at package.m4
+if !HAVE_AUTOTEST
+       @:; { \
+         printf 'ERROR: Autotest was not available at configure time.\n'; \
+         printf 'You should only need it if you modified the test suite.\n'; \
+         printf 'Autotest is part of autom4te, included in the GNU\n'; \
+         printf 'Autoconf package: <https://gnu.org/s/autoconf/>\n'; \
+       } 1>&2
+       @false
+endif
+       $(AM_V_GEN) $(AUTOTEST) $(ATFLAGS) -p m4_include -o $@.tmp testsuite.at
+       $(AM_V_at) :; { \
+         $(AUTOTEST) $(ATFLAGS) -t m4_include:'$@: $$1' testsuite.at; \
+         $(AUTOTEST) $(ATFLAGS) -t m4_include:'$$1:' testsuite.at; \
+       } >$(DEPDIR)/$(@F).P
+       $(AM_V_at) mv -f $@.tmp $@
+
+EXTRA_DIST += testsuite testsuite.at package.m4
+
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/testsuite.P@am__quote@
diff --git a/configure.ac b/configure.ac
new file mode 100644 (file)
index 0000000..abfccf7
--- /dev/null
@@ -0,0 +1,25 @@
+dnl Copyright © 2015 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.
+dnl There is NO WARRANTY, to the extent permitted by law.
+
+AC_PREREQ([2.68])
+AC_INIT([dxcommon], [0], [nbowler@draconx.ca])
+AC_CONFIG_SRCDIR([m4/base.m4])
+
+AC_PROG_CC
+
+AM_INIT_AUTOMAKE([-Wall -Wno-portability foreign subdir-objects])
+AM_SILENT_RULES([yes])
+
+DX_INIT([.])
+
+AC_CONFIG_TESTDIR([.])
+DX_PROG_AUTOTEST
+AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = x"yes"])
+
+AC_CONFIG_FILES([
+  Makefile
+])
+AC_OUTPUT
diff --git a/m4/autotest.m4 b/m4/autotest.m4
new file mode 100644 (file)
index 0000000..f9e1eea
--- /dev/null
@@ -0,0 +1,47 @@
+dnl Copyright © 2015 Nick Bowler
+dnl
+dnl Macro to find an working autotest installation.
+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.
+dnl There is NO WARRANTY, to the extent permitted by law.
+
+m4_define([_DX_PROG_AUTOTEST_SRC], [cat >conftest.at <<'EOF'
+m4@&t@_define(@<:@AT_PACKAGE_STRING@:>@,    @<:@AC_PACKAGE_STRING@:>@)
+m4@&t@_define(@<:@AT_PACKAGE_BUGREPORT@:>@, @<:@AC_PACKAGE_BUGREPORT@:>@)
+AT_INIT
+EOF])
+
+m4_define([_DX_PROG_AUTOTEST_CHECK_OUT],
+  [AS_IF([$FGREP "$PACKAGE_STRING" conftest.out >/dev/null 2>&1],
+    [DX_DO([dx_cv_autotest_works=yes],
+      [AS_VAR_SET([dx_cv_autotest_cmd], ["$1"])])])])
+
+m4_define([_DX_PROG_AUTOTEST_CHECK_CMD],
+  [AS_IF([test x"$dx_cv_autotest_cmd" = x"false"],
+    [AS_IF([AC_RUN_LOG([$1 conftest.at >conftest.sh])],
+      [AS_IF([AC_RUN_LOG([$SHELL conftest.sh --version >conftest.out])],
+        [_DX_PROG_AUTOTEST_CHECK_OUT($@)])])])])
+
+m4_define([_DX_PROG_AUTOTEST_SET_VAR],
+  [DX_DO([AC_CACHE_CHECK([for autotest], [dx_cv_autotest_cmd],
+            [AS_VAR_SET_IF([AUTOTEST],
+              [dx_cv_autotest_cmd=$AUTOTEST],
+              [DX_DO([dx_cv_autotest_works=no dx_cv_autotest_cmd=false],
+                [AS_VAR_SET_IF([AUTOTEST],
+                  [_DX_PROG_AUTOTEST_CHECK_CMD([$AUTOTEST])])],
+                [AS_VAR_SET_IF([AUTOM4TE],
+                  [_DX_PROG_AUTOTEST_CHECK_CMD([$AUTOM4TE -l autotest])])],
+                [_DX_PROG_AUTOTEST_CHECK_CMD([autom4te -l autotest])])])])],
+    [AUTOTEST=$dx_cv_autotest_cmd])])
+
+AC_DEFUN([DX_PROG_AUTOTEST],
+  [m4_do([AC_REQUIRE([AC_PROG_FGREP])],
+    [AC_ARG_VAR([AUTOTEST], [command to compile autotest programs])],
+    [DX_DO([_DX_PROG_AUTOTEST_SRC],
+      [_DX_PROG_AUTOTEST_SET_VAR],
+      [AC_CACHE_CHECK([whether autotest works],
+        [dx_cv_autotest_works],
+        [DX_DO([dx_cv_autotest_works=no],
+          [_DX_PROG_AUTOTEST_CHECK_CMD([$AUTOTEST])])])])],
+    [AC_SUBST([AUTOTEST])])])
diff --git a/m4/utils.m4 b/m4/utils.m4
new file mode 100644 (file)
index 0000000..0939e74
--- /dev/null
@@ -0,0 +1,11 @@
+dnl Copyright © 2015 Nick Bowler
+dnl
+dnl Assorted helper macros
+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.
+dnl There is NO WARRANTY, to the extent permitted by law.
+
+dnl DX_DO(arg, ...)
+dnl Expand each argument in sequence, inserting newlines between them.
+AC_DEFUN([DX_DO], [m4_do([$1], [m4_map([m4_newline], m4_cdr($@))])])
diff --git a/tests/macros.at b/tests/macros.at
new file mode 100644 (file)
index 0000000..9986d75
--- /dev/null
@@ -0,0 +1,46 @@
+dnl Copyright © 2015 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.
+dnl There is NO WARRANTY, to the extent permitted by law.
+
+AT_BANNER([Autoconf macros])
+
+m4_define([TEST_CONFIGURE_AC], [AT_DATA([configure.ac],
+[[AC_INIT([test], [0])
+]$1[
+AC_OUTPUT
+]])
+cp "$srcdir/install-sh" \
+   "$srcdir/config.guess" \
+   "$srcdir/config.sub" \
+   .
+])
+
+m4_define([TEST_AUTORECONF],
+  [AT_CHECK([autoreconf -I "$srcdir/m4"], [0], [], [stderr])])
+
+m4_define([TEST_CONFIGURE], [AT_CHECK([./configure $1], [0], [ignore])])
+
+dnl Verify that the DX_BASEDIR macro expands correctly during argument
+dnl collection.  Crucially, the output must not contain any other text.
+AT_SETUP([DX_BASEDIR during argument collection])
+
+AT_XFAIL_IF([:])
+
+AT_DATA([test.in],
+[[@TEST@
+]])
+
+TEST_CONFIGURE_AC(
+[[AC@&t@_SUBST([TEST], 'm4@&t@_dquote(DX_BASEDIR)')
+AC_CONFIG_FILES([test])
+]])
+TEST_AUTORECONF
+TEST_CONFIGURE
+
+printf '%s\n' "$srcdir" | sed -e 's:/\./:/:g' -e 's:/\.$::g' \
+                              -e 's:\(.\)//*:\1/:g' >expout
+AT_CHECK([cat test], [0], [expout])
+
+AT_CLEANUP
diff --git a/testsuite.at b/testsuite.at
new file mode 100644 (file)
index 0000000..aa5abaf
--- /dev/null
@@ -0,0 +1,10 @@
+dnl Copyright © 2015 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.
+dnl There is NO WARRANTY, to the extent permitted by law.
+
+AT_INIT
+AT_COLOR_TESTS
+
+m4_include([tests/macros.at])