]> git.draconx.ca Git - gob-dx.git/commitdiff
Pull in dxcommon for library tests.
authorNick Bowler <nbowler@draconx.ca>
Thu, 21 Feb 2019 16:26:58 +0000 (11:26 -0500)
committerNick Bowler <nbowler@draconx.ca>
Wed, 27 Feb 2019 13:48:50 +0000 (08:48 -0500)
Use the glib tests from dxcommon and hook up an initial Autotest-based
test suite which attempts to replicate the functionality of the old
(very basic) test functions.

12 files changed:
.gitignore
.gitmodules [new file with mode: 0644]
Makefile.am
atlocal.in [new file with mode: 0644]
bootstrap [new file with mode: 0755]
common [new submodule]
configure.ac
src/str_test.c [deleted file]
t/str.gob [moved from src/str.gob with 100% similarity]
t/test.gob [moved from src/test.gob with 100% similarity]
tests/general.at [new file with mode: 0644]
testsuite.at [new file with mode: 0644]

index d476b8f7085d0dadb85b7ff6e4dfef74bd90e791..cef6aa1e332392cfc3c4771264179279c56fb2a8 100644 (file)
@@ -3,6 +3,8 @@
 .dirstamp
 /INSTALL
 /aclocal.m4
+/atconfig
+/atlocal
 /autom4te.cache
 /compile
 /config.*
 /libtool
 /ltmain.sh
 /missing
+/package.m4
 /stamp-h1
+/testsuite
+/testsuite.deps
+/testsuite.dir
+/testsuite.log
 /ylwrap
 Makefile
 Makefile.in
diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..a0019b3
--- /dev/null
@@ -0,0 +1,3 @@
+[submodule "common"]
+       path = common
+       url = https://git.draconx.ca/dxcommon.git
index 83d7b31c2111ed4adb3d96624437b85fc8157137..5e859a17a4edcc2e8e09145f6a34d59a5c568b71 100644 (file)
@@ -6,11 +6,11 @@
 # This is free software: you are free to change and redistribute it.
 # There is NO WARRANTY, to the extent permitted by law.
 
-ACLOCAL_AMFLAGS = -I m4
+ACLOCAL_AMFLAGS = -I m4 -I common/m4
 
 AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src \
               -I$(builddir) -I$(srcdir) -DPKGDATADIR=\"$(pkgdatadir)\"
-AM_CFLAGS = $(GLIB_CFLAGS)
+AM_CFLAGS = $(LIBGLIB_CFLAGS)
 AM_YFLAGS = -d -t
 
 bin_PROGRAMS = gob2
@@ -20,7 +20,8 @@ EXTRA_DIST = COPYING.generated-code examples/GNOME_Foo_SomeInterface.idl \
              examples/gtk-button-count.gob examples/my-glade-main.c \
              examples/my-glade.glade examples/my-glade.gob gob2.spec \
              src/treefuncs.c src/treefuncs.h src/treefuncs.stamp \
-             src/treefuncs.def src/generate_treefuncs.pl
+             src/treefuncs.def src/generate_treefuncs.pl \
+             t/test.gob t/str.gob
 
 CLEANFILES =
 DISTCLEANFILES =
@@ -34,7 +35,7 @@ noinst_HEADERS = src/main.h src/treefuncs.h src/out.h src/util.h src/checks.h
 
 gob2_SOURCES = src/main.c src/main.h src/treefuncs.c src/out.c src/util.c \
                src/checks.c src/parse.y src/lexer.l
-gob2_LDADD = $(GLIB_LIBS) @LEXLIB@
+gob2_LDADD = $(LIBGLIB_LIBS) @LEXLIB@
 $(gob2_OBJECTS): src/treefuncs.h
 
 man_MANS = doc/gob2.1
@@ -84,3 +85,5 @@ uninstall-gob2-html:
 
 m4dir = $(datadir)/aclocal
 dist_m4_DATA = gob2.m4
+
+include $(top_srcdir)/common/snippet/autotest.mk
diff --git a/atlocal.in b/atlocal.in
new file mode 100644 (file)
index 0000000..d169bd9
--- /dev/null
@@ -0,0 +1,12 @@
+: "${CC=@CC@}"
+: "${CXX=@CXX@}"
+: "${CPPFLAGS=@CPPFLAGS@}"
+: "${CFLAGS=@CFLAGS@}"
+: "${CXXFLAGS=@CXXFLAGS@}"
+: "${LDFLAGS=@LDFLAGS@}"
+: "${GTK_CFLAGS=@GTK_CFLAGS@}"
+: "${GTK_LIBS=@GTK_LIBS@}"
+: "${LIBGOBJECT_CFLAGS=@LIBGOBJECT_CFLAGS@}"
+: "${LIBGOBJECT_LIBS=@LIBGOBJECT_LIBS@}"
+: "${HAVE_GOBJECT=@HAVE_GOBJECT@}"
+: "${HAVE_GTK2=@HAVE_GTK2@}"
diff --git a/bootstrap b/bootstrap
new file mode 100755 (executable)
index 0000000..f9cbd41
--- /dev/null
+++ b/bootstrap
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+argv0=$0
+
+err () { printf '%s: %s\n' "$argv0" "$@" 1>&2; }
+die () { err "$@"; exit 1; }
+
+: "${AUTORECONF=autoreconf}"
+: "${GIT=git}"
+
+$GIT submodule update --init || err "Failed to update submodules from git."
+
+# Punt some automake-generated files so that Gentoo's wrapper script
+# doesn'# try to detect the automake version in use.
+rm -f Makefile.in aclocal.m4
+$AUTORECONF -fis
diff --git a/common b/common
new file mode 160000 (submodule)
index 0000000..9ade2c8
--- /dev/null
+++ b/common
@@ -0,0 +1 @@
+Subproject commit 9ade2c8c042ab15030d7bbb49fa97ae692a10e4f
index f78cf395d4086217fb9a7eed88feb700bed25c52..1d66b9fa42ee2749fc7fcd49ca0aa03d43ad2a15 100644 (file)
@@ -14,6 +14,7 @@ AM_INIT_AUTOMAKE([-Wall subdir-objects dist-xz])
 AM_SILENT_RULES([yes])
 
 AC_PROG_CC
+AC_PROG_CXX
 AC_PROG_LEX
 AC_PROG_YACC
 
@@ -23,7 +24,18 @@ AM_CONDITIONAL([HAVE_PERL], [$PERL -e 'my $x = 42; exit $x'; test $? = 42])
 
 LT_INIT
 
-PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.4.0])
+DX_LIB_GLIB2
 
-AC_CONFIG_FILES([Makefile gob2.spec doc/gob2.1])
+dnl Dependencies for test suite
+DX_LIB_GLIB2([], [gobject], [HAVE_GOBJECT=true], [HAVE_GOBJECT=false])
+AC_SUBST([HAVE_GOBJECT])
+
+DX_LIB_GTK2([], [HAVE_GTK2=true], [HAVE_GTK2=false])
+AC_SUBST([HAVE_GTK2])
+
+AC_CONFIG_TESTDIR([.], [t:.])
+DX_PROG_AUTOTEST
+AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = x"yes"])
+
+AC_CONFIG_FILES([Makefile gob2.spec doc/gob2.1 atlocal])
 AC_OUTPUT
diff --git a/src/str_test.c b/src/str_test.c
deleted file mode 100644 (file)
index 12a1be9..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "str.h"
-
-int
-main (void)
-{
-  g_type_init ();
-
-  int the_answer = 42;
-  char *stupid_pointer = "ug";
-
-  // This works fine.
-  Str *test_good = (Str *) (str_new ("%d", the_answer));
-  test_good = test_good;
-
-  // This gets a warning thanks to our function attribute.
-  Str *test_bad = (Str *) (str_new ("%d", stupid_pointer));
-  test_bad = test_bad;
-
-  return 0;
-}
similarity index 100%
rename from src/str.gob
rename to t/str.gob
similarity index 100%
rename from src/test.gob
rename to t/test.gob
diff --git a/tests/general.at b/tests/general.at
new file mode 100644 (file)
index 0000000..355f09e
--- /dev/null
@@ -0,0 +1,68 @@
+dnl Copyright © 2019 Nick Bowler
+dnl License GPLv2+: GNU General Public License version 2 or any later version.
+dnl This is free software: you are free to change and redistribute it.
+dnl There is NO WARRANTY, to the extent permitted by law.
+
+AT_SETUP([test.gob compilation])
+
+AT_CHECK([gob2 "$abs_top_srcdir/t/test.gob"])
+AT_CHECK([$HAVE_GTK2 || exit 77])
+TEST_COMPILE_GOBJECT([$GTK_CFLAGS test-object.c], [0], [], [ignore])
+
+AT_CLEANUP
+
+AT_SETUP([test.gob C++ compilation])
+
+AT_CHECK([gob2 --for-cpp "$abs_top_srcdir/t/test.gob"])
+AT_CHECK([$HAVE_GTK2 || exit 77])
+TEST_COMPILEXX_GOBJECT([$GTK_CFLAGS test-object.cc], [0], [], [ignore])
+
+AT_CLEANUP
+
+AT_SETUP([str.gob])
+
+AT_DATA([main.c],
+[[#include "str.h"
+
+int main(void)
+{
+  g_type_init ();
+
+  int the_answer = 42;
+  char *stupid_pointer = "ug";
+
+  /* This works fine. */
+  Str *test_good = (Str *) (str_new ("%d", the_answer));
+  test_good = test_good;
+
+  /* This gets a warning thanks to our function attribute. */
+  Str *test_bad = (Str *) (str_new ("%d", stupid_pointer));
+  test_bad = test_bad;
+
+  return 0;
+}
+]])
+
+str_gob=$abs_top_srcdir/t/str.gob
+AT_CHECK([gob2 "$str_gob"])
+TEST_COMPILE_GOBJECT([str.c], [0], [], [stderr])
+mv stderr str_stderr
+
+# Check for correct diagnostic messages on the target lines...
+AT_CHECK([awk '/want a string/ { print NR }' "$str_gob" >str_lines])
+total=0
+exec 3<str_lines
+while read l <&3; do
+  AS_VAR_ARITH([total], [1 + $total])
+  AT_CHECK([awk -v line="$l" -v file="$str_gob" -NF : \
+    '$1 == file && $2 == line { exit 42 }' str_stderr], [42])
+done
+exec 3<&-
+AT_CHECK([test x"$total" = x"2"])
+
+TEST_COMPILE_GOBJECT([main.c], [0], [], [stderr])
+AT_CHECK([awk -NF : '$1 == "main.c" && $2 == "15" { exit 42 }' stderr], [42])
+
+AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main str.o main.o])
+
+AT_CLEANUP
diff --git a/testsuite.at b/testsuite.at
new file mode 100644 (file)
index 0000000..97c0253
--- /dev/null
@@ -0,0 +1,24 @@
+AT_COPYRIGHT([Copyright © 2019 Nick Bowler
+License GPLv2+: GNU General Public License version 2 or any later version.
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.])
+
+dnl Compile a C source file with default cflags for libgobject.  The test
+dnl group is skipped if libgobject was not enabled at configure time.  The
+dnl first argument contains extra compiler flags, which must include the
+dnl source file name.  The remaining arguments correspond to the remaining
+dnl arguments of AT_CHECK (e.g., the 2nd argument to TEST_COMPILE_GOBJECT
+dnl is the 2nd argument of AT_CHECK -- the expected exit status).
+m4_define([TEST_COMPILE_GOBJECT], [AT_CHECK([$HAVE_GOBJECT || exit 77
+$CC $CPPFLAGS $CFLAGS $LIBGOBJECT_CFLAGS -c $1], m4_shift($@))])
+
+dnl Same as TEST_COMPILE_GOBJECT, except that the C++ compiler is used.
+m4_define([TEST_COMPILEXX_GOBJECT], [AT_CHECK([$HAVE_GOBJECT || exit 77
+$CXX $CPPFLAGS $CXXFLAGS $LIBGOBJECT_CFLAGS -c $1], m4_shift($@))])
+
+AT_INIT
+AT_COLOR_TESTS
+
+AT_TESTED([gob2])
+
+m4_include([tests/general.at])