]> git.draconx.ca Git - upkg.git/commitdiff
Port tests to Autotest.
authorNick Bowler <nbowler@draconx.ca>
Sun, 27 Feb 2022 04:06:52 +0000 (23:06 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sun, 27 Feb 2022 04:08:57 +0000 (23:08 -0500)
All my other projects use Autotest, which I like quite a lot better than
the Automake test harness.  So let's convert this project now, which has
only a couple dead simple scripts to convert.

.gitignore
Makefile.am
configure.ac
test/decodeindex.c
tests/engine-pcx-rlencode.sh [deleted file]
tests/functions.at [new file with mode: 0644]
tests/libupkg-index-decode.sh [deleted file]
testsuite.at [new file with mode: 0644]

index 4231653fa546c15c19a4f4374133a6698535ffe1..f0171109248031582d59033a561ac171ad542028 100644 (file)
@@ -1,3 +1,4 @@
+*.a
 *.gobstamp
 *.la
 *.lo
@@ -9,6 +10,8 @@
 /Makefile
 /Makefile.in
 /aclocal.m4
+/atconfig
+/atlocal
 /autom4te.cache
 /compile
 /config.*
 /ltmain.sh
 /missing
 /mkinstalldirs
+/package.m4
 /snippet
 /stamp-h1
 /test-driver
 /test-suite.log
+/testsuite
+/testsuite.deps
+/testsuite.dir
+/testsuite.log
 /upkg
index 57d8142e5bd22cfc4671d1458245c1a73ff7708a..da9a3958a78dfc470559acb2ac600a6d222a5516 100644 (file)
@@ -4,7 +4,6 @@
 # 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.
 
-AUTOMAKE_OPTIONS = parallel-tests color-tests
 ACLOCAL_AMFLAGS = -I m4 -I common/m4
 MAINTAINERCLEANFILES =
 MOSTLYCLEANFILES =
@@ -39,6 +38,7 @@ upkg_LDADD   = libuobject.la libupkg.la libgnu.la $(GLIB_LIBS)
 $(upkg_OBJECTS): $(gnulib_headers) src/upkgopts.h
 
 libupkg_la_SOURCES = src/libupkg.c common/src/pack.c common/src/pack.h
+$(libupkg_la_OBJECTS): $(gnulib_headers)
 
 uobjectdir = $(includedir)/uobject
 uobject_HEADERS = src/uobject/uobject.h src/uobject/exportable.h \
@@ -83,23 +83,19 @@ engine_la_SOURCES  += src/engine/music-modplug.c src/engine/modplug-types.h
 engine_la_LIBADD   += $(LIBMODPLUG_LIBS)
 endif
 
-check_LTLIBRARIES = libtest.la
 check_PROGRAMS = test/decodeindex test/pcxrle
+check_LIBRARIES = libtest.a
 
-libtest_la_SOURCES = test/common.c test/common.h
+libtest_a_SOURCES = test/common.c test/common.h
+$(libtest_a_OBJECTS): $(gnulib_headers)
 
-test_decodeindex_LDADD = libupkg.la libgnu.la libtest.la
+TEST_LIBS = libtest.a libgnu.la
+
+test_decodeindex_LDADD = libupkg.la $(TEST_LIBS)
 $(test_decodeindex_OBJECTS): $(gnulib_headers)
-test_pcxrle_LDADD = src/engine/pcx.lo libupkg.la libgnu.la libtest.la
+test_pcxrle_LDADD = src/engine/pcx.lo libupkg.la $(TEST_LIBS)
 $(test_pcxrle_OBJECTS): $(gnulib_headers)
 
-TESTS_ENVIRONMENT = SHELL='$(SHELL)' EXEEXT='$(EXEEXT)'
-TEST_EXTENSIONS = .sh
-SH_LOG_COMPILER = $(SHELL)
-
-TESTS = tests/libupkg-index-decode.sh tests/engine-pcx-rlencode.sh
-EXTRA_DIST += $(TESTS)
-
 # Supporting rules for GObject Builder
 GOB_V   = $(GOB_V_@AM_V@)
 GOB_V_  = $(GOB_V_@AM_DEFAULT_V@)
@@ -167,3 +163,4 @@ unfuck-distdir:
 
 include $(top_srcdir)/lib/gnulib.mk
 include $(top_srcdir)/libltdl/ltdl.mk
+include $(top_srcdir)/common/snippet/autotest.mk
index b5d8d3d2b17fc98fa80538cc03e5737772878003..fef71211dcc53700790a7263e29621d31d2c8211 100644 (file)
@@ -78,5 +78,9 @@ CFLAGS=$save_CFLAGS LIBS=$save_LIBS])
 ])
 AM_CONDITIONAL([HAVE_GOB2_DYN], [test x"$dx_cv_gob2_dynamic_types" = x"yes"])
 
+AC_CONFIG_TESTDIR([.], [test:.])
+DX_PROG_AUTOTEST
+AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = x"yes"])
+
 AC_CONFIG_FILES([Makefile libuobject.pc])
 AC_OUTPUT
index c072a07c25f72a41c800aa5a7ef368dc02489d3e..1eef6a66485b6fd4e2695f382527a3f69c058f60 100644 (file)
@@ -52,7 +52,7 @@ static void print_bytes(FILE *f, int indent, void *buf, size_t n)
        fprintf(f, "%*s", indent, "");
 
        if (n == 0) {
-               printf("(empty)\n");
+               fprintf(f, "(empty)\n");
                return;
        }
 
diff --git a/tests/engine-pcx-rlencode.sh b/tests/engine-pcx-rlencode.sh
deleted file mode 100644 (file)
index 3a05444..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/sh
-#
-# Check corner cases of the PCX run-length encoder.
-# Copyright © 2012 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.
-
-pcxrle=test/pcxrle$EXEEXT
-
-$pcxrle 00   || exit 1
-$pcxrle 0000 || exit 1
-$pcxrle c100 || exit 1
-
-# Test RLE rollover
-t1=00
-t2=$t1$t1
-t4=$t2$t2
-t8=$t4$t4
-t16=$t8$t8
-t32=$t16$t16
-t64=$t32$t32
-
-$pcxrle "$t32$t16$t8$t4$t2$t1" || exit 1 # maximum possible run
-$pcxrle "$t64" || exit 1
-$pcxrle "$t64$t64$t64" || exit 1
diff --git a/tests/functions.at b/tests/functions.at
new file mode 100644 (file)
index 0000000..fe8632e
--- /dev/null
@@ -0,0 +1,62 @@
+# Copyright © 2012, 2022 Nick Bowler
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+AT_SETUP([upkg_decode_index])
+AT_KEYWORDS([core function])
+
+# various encodings of zero
+m4_foreach_w([INDEX], [00 4000 408000 40808000 4080808000],
+  [AT_CHECK([decodeindex INDEX], [0], [0
+])
+])
+
+# truncated encodings of zero
+m4_foreach_w([INDEX], ['' 40 4080 408080 40808080],
+  [AT_CHECK([decodeindex INDEX], [1], [ignore], [ignore])
+])
+
+# overlong encoding of zero
+AT_CHECK([decodeindex 408080808000], [1], [ignore], [ignore])
+
+AT_CLEANUP
+
+AT_SETUP([pcx_write_scanline run-length encoding])
+AT_KEYWORDS([engine function])
+
+AT_CHECK([pcxrle 00], [0], [00
+])
+AT_CHECK([pcxrle 0000], [0], [c200
+])
+AT_CHECK([pcxrle c100], [0], [c1c100
+])
+
+zero1=00
+zero4=$zero1$zero1$zero1$zero1
+zero16=$zero4$zero4$zero4$zero4
+zero63=$zero16$zero16$zero16$zero4$zero4$zero4$zero1$zero1$zero1
+zero64=$zero16$zero16$zero16$zero16
+zero192=$zero64$zero64$zero64
+
+AT_CHECK([# maximum possible run
+pcxrle $zero63], [0], [ff00
+])
+AT_CHECK([# one more than maximum
+pcxrle $zero64], [0], [ff0000
+])
+AT_CHECK([# consecutive runs
+pcxrle $zero192], [0], [ff00ff00ff00c300
+])
+
+AT_CLEANUP
diff --git a/tests/libupkg-index-decode.sh b/tests/libupkg-index-decode.sh
deleted file mode 100644 (file)
index 80b328d..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/bin/sh
-#
-# Check various corner cases of upkg_decode_index.
-# Copyright © 2012, 2022 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.
-
-decodeindex=test/decodeindex$EXEEXT
-scriptname=$0
-
-test_index() {
-       decode_cmd=`exec 3>&1
-               { $decodeindex "$1" 3>&-
-                       echo decode_status=$? >&3
-               } | { read val 3>&-
-                       echo decode_val=\'$val\' >&3;
-               }`
-       eval "$decode_cmd"
-
-       case $# in
-       2)
-               (exit $decode_status) || return 1
-               if test x"$decode_val" != x"$2"; then
-                       printf '%s: result (%d) does not match expected (%d)\n' \
-                               "$scriptname" "$decode_val" "$2"
-                       return 1
-               fi
-               ;;
-       1)
-               if (exit $decode_status); then
-                       printf '%s: false positive on (%s), got (%d)\n' \
-                               "$scriptname" "$1" "$decode_val"
-                       return 1
-               fi
-               ;;
-       esac
-}
-
-test_index 00 0         || exit 1
-test_index 4000 0       || exit 1
-test_index 408000 0     || exit 1
-test_index 40808000 0   || exit 1
-test_index 4080808000 0 || exit 1
-
-# False positives
-test_index ''           || exit 1
-test_index 40           || exit 1
-test_index 4080         || exit 1
-test_index 408080       || exit 1
-test_index 40808080     || exit 1
-test_index 4080808080   || exit 1
-test_index 408080808000 || exit 1
diff --git a/testsuite.at b/testsuite.at
new file mode 100644 (file)
index 0000000..74348cc
--- /dev/null
@@ -0,0 +1,21 @@
+AT_COPYRIGHT([Copyright © 2022 Nick Bowler])
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+AT_INIT
+AT_COLOR_TESTS
+
+AT_TESTED([upkg])
+
+m4_include([tests/functions.at])