[gjs/wip/ptomato/tests: 3/12] build: Use Automake test driver with TAP output



commit e3a9a19aa758184b9d4f2514b609779403181afc
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Oct 22 23:21:41 2016 -0700

    build: Use Automake test driver with TAP output
    
    For better integration with the build system and nicer output, use
    Automake's TAP driver and gtester's TAP output mode.
    
    There are a few things going on in this commit:
    
    - We use the significant-to-Automake variable TESTS instead of
      TEST_PROGS. TESTS contains whatever is in check_PROGRAMS plus whatever
      else we put into it (our test script.)
    
    - TESTS_ENVIRONMENT is also significant to Automake, but should not be
      set within Automake, instead the AM_TESTS_ENVIRONMENT variable should
      be used so that the developer can override TESTS_ENVIRONMENT from the
      command line. This variable consists of a sequence of commands and
      needs to end with a semicolon. (So we can stuff XVFB_START in there
      too.)
    
    - We need to put the test invocation in a separate script since gtester
      doesn't pass the --tap option on to its test binary. As long as we're
      making a separate script, we may as well put the run-with-dbus
      invocation in there too.

 Makefile-insttest.am         |    2 +-
 Makefile-test.am             |   76 ++++++++++++++++++++++++-----------------
 Makefile.am                  |    5 ++-
 configure.ac                 |    2 +
 installed-tests/gjs-unit.cpp |   25 ++++++++++---
 test/run-test                |    9 +++++
 6 files changed, 78 insertions(+), 41 deletions(-)
---
diff --git a/Makefile-insttest.am b/Makefile-insttest.am
index bb13b6b..125bd88 100644
--- a/Makefile-insttest.am
+++ b/Makefile-insttest.am
@@ -21,7 +21,7 @@ if BUILDOPT_INSTALL_TESTS
 gjsinsttest_PROGRAMS += jsunit
 endif
 
-TEST_PROGS += jsunit
+check_PROGRAMS += jsunit
 
 TEST_INTROSPECTION_GIRS =
 
diff --git a/Makefile-test.am b/Makefile-test.am
index 7aff2cd..3b574e1 100644
--- a/Makefile-test.am
+++ b/Makefile-test.am
@@ -1,6 +1,9 @@
-EXTRA_DIST += test/test-bus.conf
+EXTRA_DIST +=                  \
+       test/test-bus.conf      \
+       test/run-test           \
+       $(NULL)
 
-TEST_PROGS_OPTIONS = 2>test_user_data/logs/stderr.log
+SKIPPED_TESTS =
 
 if XVFB_TESTS
 XVFB_INVOCATION = $(XVFB) -ac -noreset -screen 0 1024x768x16
@@ -16,32 +19,30 @@ ${XVFB_INVOCATION} -help 2>/dev/null 1>&2 \
        && { ${XVFB} :$$XID -nolisten tcp -auth /dev/null >/dev/null 2>&1 & \
                trap "kill -15 $$! " 0 HUP INT QUIT TRAP USR1 PIPE TERM ; } \
        || { echo "Gtk+Tests:ERROR: Failed to start Xvfb environment for X11 target tests."; exit 1; } \
-       && DISPLAY=:$$XID && export DISPLAY &&
+       && export DISPLAY=:$$XID;
 else
 XVFB_START =
 endif
 
-if DBUS_TESTS
-LOG_COMPILER = $(DBUS_RUN_SESSION)
-AM_LOG_FLAGS = --config-file=$(srcdir)/test/test-bus.conf --
-RUN_WITH_DBUS = $(LOG_COMPILER) $(AM_LOG_FLAGS)
-else
-RUN_WITH_DBUS =
-TEST_PROGS_OPTIONS += -s /js/GDBus
+if !DBUS_TESTS
+SKIPPED_TESTS += /js/GDBus
 endif
 
 if !ENABLE_GTK
-TEST_PROGS_OPTIONS += -s /js/Gtk
+SKIPPED_TESTS += /js/Gtk
+endif
+
+if !ENABLE_CAIRO
+SKIPPED_TESTS += /js/Cairo
 endif
 
-GTESTER = ${XVFB_START} ${TESTS_ENVIRONMENT} ${RUN_WITH_DBUS} gtester
 clean-local: test-user-data-clean
 
 test-user-data-clean:
        -rm -fr $(builddir)/test_user_data
 
 ########################################################################
-TEST_PROGS += gjs-tests
+check_PROGRAMS += gjs-tests
 
 gjs_tests_CPPFLAGS =                           \
        $(AM_CPPFLAGS)                          \
@@ -106,32 +107,43 @@ CLEANFILES +=                                             \
        mock-js-resources.c                             \
        $(NULL)
 
-check-local: gjs-tests
-       $(MKDIR_P) test_user_data/logs
-       @test -z "${TEST_PROGS}" || ${GTESTER} --verbose ${TEST_PROGS} ${TEST_PROGS_OPTIONS}
-
 # GJS_PATH is empty here since we want to force the use of our own
-# resources
-TESTS_ENVIRONMENT =                                                    \
-       TOP_SRCDIR=$(abs_top_srcdir)                                    \
-       TOP_BUILDDIR=$(abs_top_builddir)                                \
-       XDG_DATA_HOME=test_user_data                                    \
-       GJS_DEBUG_OUTPUT=test_user_data/logs/gjs.log                    \
-       GJS_USE_UNINSTALLED_FILES=1                                     \
-       GJS_TEST_TIMEOUT=420                                            \
-       GJS_PATH= \
-       LD_LIBRARY_PATH="$(LD_LIBRARY_PATH):$(FIREFOX_JS_LIBDIR)"       \
-       G_FILENAME_ENCODING=latin1      # ensure filenames are not utf8 \
+# resources. G_FILENAME_ENCODING ensures filenames are not UTF-8.
+AM_TESTS_ENVIRONMENT =                                         \
+       $(MKDIR_P) test_user_data/logs;                         \
+       export TOP_SRCDIR="$(abs_top_srcdir)";                  \
+       export TOP_BUILDDIR="$(abs_top_builddir)";              \
+       export GJS_DEBUG_OUTPUT=test_user_data/logs/gjs.log;    \
+       export GJS_USE_UNINSTALLED_FILES=1;                     \
+       export GJS_TEST_SKIP="$(SKIPPED_TESTS)";                \
+       export GJS_PATH=;                                       \
+       export XDG_DATA_HOME=test_user_data;                    \
+       export G_FILENAME_ENCODING=latin1;                      \
+       $(XVFB_START)                                           \
        $(NULL)
 
 simple_tests = test/testCommandLine.sh
 EXTRA_DIST += $(simple_tests)
-TESTS = $(simple_tests)
+TESTS += $(simple_tests)
+
+LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/tap-driver.sh
+
+if DBUS_TESTS
+LOG_COMPILER = $(DBUS_RUN_SESSION)
+AM_LOG_FLAGS = --config-file=$(srcdir)/test/test-bus.conf -- $(top_srcdir)/test/run-test
+else
+LOG_COMPILER = $(top_srcdir)/test/run-test
+AM_LOG_FLAGS =
+endif !DBUS_TESTS
+
+TEST_EXTENSIONS = .sh
+SH_LOG_COMPILER = sh
 
 if CODE_COVERAGE_ENABLED
-TESTS_ENVIRONMENT += \
-       GJS_UNIT_COVERAGE_OUTPUT=lcov \
-       GJS_UNIT_COVERAGE_PREFIX=resource:///org/gnome/gjs/
+AM_TESTS_ENVIRONMENT +=                                                \
+       export GJS_UNIT_COVERAGE_OUTPUT=lcov;                           \
+       export GJS_UNIT_COVERAGE_PREFIX=resource:///org/gnome/gjs/;     \
+       $(NULL)
 endif
 
 CODE_COVERAGE_IGNORE_PATTERN = */include/*
diff --git a/Makefile.am b/Makefile.am
index c0df6c2..e3da6a5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,8 +11,8 @@ dist_gjsjs_DATA =
 BUILT_SOURCES =
 CLEANFILES =
 EXTRA_DIST =
-TEST_PROGS =
-check_PROGRAMS = $(TEST_PROGS)
+check_PROGRAMS =
+TESTS = $(check_PROGRAMS)
 INTROSPECTION_GIRS =
 ## ACLOCAL_AMFLAGS can be removed for Automake 1.13
 ACLOCAL_AMFLAGS = -I m4
@@ -23,6 +23,7 @@ MAINTAINERCLEANFILES =                                        \
        $(GITIGNORE_MAINTAINERCLEANFILES_TOPLEVEL)      \
        $(GITIGNORE_MAINTAINERCLEANFILES_MAKEFILE_IN)   \
        $(GITIGNORE_MAINTAINERCLEANFILES_M4_LIBTOOL)    \
+       tap-driver.sh                                   \
        $(NULL)
 GITIGNOREFILES = INSTALL m4
 
diff --git a/configure.ac b/configure.ac
index afcebe0..8c041f5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -14,6 +14,7 @@ AX_IS_RELEASE([git-directory])
 AC_CONFIG_SRCDIR([gjs/console.cpp])
 AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_HEADERS([config.h])
+AC_REQUIRE_AUX_FILE([tap-driver.sh])
 
 AC_DEFINE([GJS_VERSION], pkg_int_version, [The gjs version as an integer])
 
@@ -39,6 +40,7 @@ LT_INIT([disable-static])
 AC_PROG_MKDIR_P
 AC_PROG_LN_S
 AC_PROG_SED
+AC_PROG_AWK
 
 AX_COMPILER_FLAGS
 
diff --git a/installed-tests/gjs-unit.cpp b/installed-tests/gjs-unit.cpp
index 034273f..a2075fe 100644
--- a/installed-tests/gjs-unit.cpp
+++ b/installed-tests/gjs-unit.cpp
@@ -35,21 +35,26 @@
 #include "gjs/coverage.h"
 #include "gjs/mem.h"
 
+static const char *skip;
+
 typedef struct {
     const char *coverage_prefix;
     const char *coverage_output_path;
     char       *filename;
+    char       *test_name;
 } GjsTestData;
 
 static GjsTestData *
 gjs_unit_test_data_new(const char *coverage_prefix,
                        const char *coverage_output_path,
-                       char       *filename)
+                       char       *filename,
+                       char       *test_name)
 {
     GjsTestData *data = (GjsTestData *) g_new0(GjsTestData, 1);
     data->coverage_prefix = coverage_prefix;
     data->coverage_output_path = coverage_output_path;
     data->filename = filename;
+    data->test_name = test_name;
     return data;
 }
 
@@ -58,6 +63,7 @@ gjs_unit_test_data_free(gpointer test_data, gpointer user_data)
 {
     GjsTestData *data = (GjsTestData *) test_data;
     g_free(data->filename);
+    g_free(data->test_name);
     g_free(data);
 }
 
@@ -118,6 +124,12 @@ test(GjsTestJSFixture *fix,
 
     GjsTestData *data = (GjsTestData *) test_data;
 
+    if (skip && strstr(skip, data->test_name)) {
+        g_test_message("Skipping %s", data->test_name);
+        g_test_skip("due to GJS_TEST_SKIP environment variable");
+        return;
+    }
+
     success = gjs_context_eval_file(fix->context, data->filename, &code, &error);
     if (!success)
         g_error("%s", error->message);
@@ -179,6 +191,7 @@ main(int argc, char **argv)
 
     const char *coverage_prefix = g_getenv("GJS_UNIT_COVERAGE_PREFIX");
     const char *coverage_output_directory = g_getenv("GJS_UNIT_COVERAGE_OUTPUT");
+    skip = g_getenv("GJS_TEST_SKIP");
 
     all_tests = read_all_dir_sorted(js_test_dir);
     for (iter = all_tests; iter; iter = iter->next) {
@@ -192,20 +205,20 @@ main(int argc, char **argv)
             g_free(name);
             continue;
         }
-        if (g_str_has_prefix (name, "testCairo") && g_getenv ("GJS_TEST_SKIP_CAIRO"))
-            continue;
 
         /* pretty print, drop 'test' prefix and '.js' suffix from test name */
         test_name = g_strconcat("/js/", name + 4, NULL);
         test_name[strlen(test_name)-3] = '\0';
 
         file_name = g_build_filename(js_test_dir, name, NULL);
-        test_data = gjs_unit_test_data_new(coverage_prefix, coverage_output_directory, file_name);
+        test_data = gjs_unit_test_data_new(coverage_prefix,
+                                           coverage_output_directory, file_name,
+                                           test_name);
         g_test_add(test_name, GjsTestJSFixture, test_data, setup, test, teardown);
         g_free(name);
-        g_free(test_name);
         all_registered_test_data = g_slist_prepend(all_registered_test_data, test_data);
-        /* not freeing file_name or test_data yet as it's needed while running the test */
+        /* not freeing file_name, test_name, or test_data yet as it's needed
+         * while running the test */
     }
     g_free(js_test_dir);
     g_slist_free(all_tests);
diff --git a/test/run-test b/test/run-test
new file mode 100755
index 0000000..028ffd3
--- /dev/null
+++ b/test/run-test
@@ -0,0 +1,9 @@
+#!/bin/sh -e
+# Run a GTester binary with TAP output
+
+if test -z "$1"; then
+    echo "Need a test-binary filename!"
+    exit 1
+fi
+
+"$1" --tap --keep-going --verbose


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]