[vala/wip/valadate: 22/63] Add Valadate test harness



commit 58c61e7b2d6d55b510b4ca5e7cc92a26196ef40b
Author: chebizarro gmail com <chebizarro gmail com>
Date:   Sat Jul 9 06:38:49 2016 -0700

    Add Valadate test harness

 Makefile.am                              |    9 +-
 build-aux/glib-tap.mk                    |  134 ++++++
 build-aux/tap-driver.sh                  |  652 ++++++++++++++++++++++++++++++
 build-aux/tap-test                       |    5 +
 configure.ac                             |    3 +
 m4/glibtests.m4                          |   28 ++
 tests/Makefile.am                        |  332 ++--------------
 tests/asynchronous/bug595755.vala        |    1 +
 tests/asynchronous/bug596861.vala        |    2 +-
 tests/{ => control-flow}/namespaces.vala |    0
 tests/dbus/arrays.test                   |    2 +-
 tests/dbus/async-errors.test             |    2 +-
 tests/dbus/async.test                    |    2 +-
 tests/dbus/basic-types.test              |    2 +-
 tests/dbus/bug602003.test                |    2 +-
 tests/dbus/dicts.test                    |    2 +-
 tests/dbus/errors.test                   |    2 +-
 tests/dbus/filedescriptor.test           |    2 +-
 tests/dbus/signals.test                  |    2 +-
 tests/dbus/structs.test                  |    2 +-
 tests/delegates/bug659778.vala           |   12 +-
 tests/valatests.vala                     |  302 ++++++++++++++
 valadate/Makefile.am                     |   79 ++++
 valadate/assembly.vala                   |   24 ++
 valadate/module.vala                     |   58 +++
 valadate/test.vala                       |   41 ++
 valadate/testcase.vala                   |  204 ++++++++++
 valadate/testexplorer.vala               |   95 +++++
 valadate/testfixture.vala                |   32 ++
 valadate/testresult.vala                 |   38 ++
 valadate/testrunner.vala                 |  136 +++++++
 31 files changed, 1892 insertions(+), 315 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 813b3fc..1b4b2eb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,10 +9,11 @@ SUBDIRS = \
        codegen \
        compiler \
        vapi \
-       tests \
+       valadate \
        doc \
        gobject-introspection \
        vapigen \
+       tests \
        $(NULL)
 
 if ENABLE_UNVERSIONED
@@ -31,10 +32,6 @@ bootstrap: all
        find $(top_srcdir) -name "*.vala.stamp" | xargs rm -f
        $(MAKE) $(AM_MAKEFLAGS) all VALAC=$(abs_top_builddir)/compiler/valac$(EXEEXT) V=$V
 
-.PHONY: test
-test:
-       cd tests && $(MAKE) $(AM_MAKEFLAGS) check
-
 #if ENABLE_COVERAGE
 .PHONY: coverage coverage-report
 coverage:
@@ -91,6 +88,8 @@ EXTRA_DIST = \
        .version \
        build-aux/git-version-gen \
        build-aux/gitlog-to-changelog \
+       build-aux/glib-tap.mk \
+       build-aux/tap-driver.sh \
        $(NULL)
 
 DISTCLEANFILES = version.h
diff --git a/build-aux/glib-tap.mk b/build-aux/glib-tap.mk
new file mode 100644
index 0000000..bf6ac50
--- /dev/null
+++ b/build-aux/glib-tap.mk
@@ -0,0 +1,134 @@
+# GLIB - Library of useful C routines
+
+TESTS_ENVIRONMENT= \
+       G_TEST_SRCDIR="$(abs_srcdir)"           \
+       G_TEST_BUILDDIR="$(abs_builddir)"       \
+       G_DEBUG=gc-friendly                     \
+       MALLOC_CHECK_=2                         \
+       MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256))
+LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/build-aux/tap-driver.sh
+LOG_COMPILER = $(top_srcdir)/build-aux/tap-test
+
+NULL =
+
+# initialize variables for unconditional += appending
+BUILT_SOURCES =
+BUILT_EXTRA_DIST =
+CLEANFILES = *.log *.trs
+DISTCLEANFILES =
+MAINTAINERCLEANFILES =
+EXTRA_DIST =
+TESTS =
+
+installed_test_LTLIBRARIES =
+installed_test_PROGRAMS =
+installed_test_SCRIPTS =
+nobase_installed_test_DATA =
+
+noinst_LTLIBRARIES =
+noinst_PROGRAMS =
+noinst_SCRIPTS =
+noinst_DATA =
+
+check_LTLIBRARIES =
+check_PROGRAMS =
+check_SCRIPTS =
+check_DATA =
+
+# We support a fairly large range of possible variables.  It is expected that all types of files in a test 
suite
+# will belong in exactly one of the following variables.
+#
+# First, we support the usual automake suffixes, but in lowercase, with the customary meaning:
+#
+#   test_programs, test_scripts, test_data, test_ltlibraries
+#
+# The above are used to list files that are involved in both uninstalled and installed testing.  The
+# test_programs and test_scripts are taken to be actual testcases and will be run as part of the test suite.
+# Note that _data is always used with the nobase_ automake variable name to ensure that installed test data 
is
+# installed in the same way as it appears in the package layout.
+#
+# In order to mark a particular file as being only for one type of testing, use 'installed' or 'uninstalled',
+# like so:
+#
+#   installed_test_programs, uninstalled_test_programs
+#   installed_test_scripts, uninstalled_test_scripts
+#   installed_test_data, uninstalled_test_data
+#   installed_test_ltlibraries, uninstalled_test_ltlibraries
+#
+# Additionally, we support 'extra' infixes for programs and scripts.  This is used for support 
programs/scripts
+# that should not themselves be run as testcases (but exist to be used from other testcases):
+#
+#   test_extra_programs, installed_test_extra_programs, uninstalled_test_extra_programs
+#   test_extra_scripts, installed_test_extra_scripts, uninstalled_test_extra_scripts
+#
+# Additionally, for _scripts and _data, we support the customary dist_ prefix so that the named script or 
data
+# file automatically end up in the tarball.
+#
+#   dist_test_scripts, dist_test_data, dist_test_extra_scripts
+#   dist_installed_test_scripts, dist_installed_test_data, dist_installed_test_extra_scripts
+#   dist_uninstalled_test_scripts, dist_uninstalled_test_data, dist_uninstalled_test_extra_scripts
+#
+# Note that no file is automatically disted unless it appears in one of the dist_ variables.  This follows 
the
+# standard automake convention of not disting programs scripts or data by default.
+#
+# test_programs, test_scripts, uninstalled_test_programs and uninstalled_test_scripts (as well as their 
disted
+# variants) will be run as part of the in-tree 'make check'.  These are all assumed to be runnable under
+# gtester.  That's a bit strange for scripts, but it's possible.
+
+TESTS += $(test_programs) $(test_scripts) $(uninstalled_test_programs) $(uninstalled_test_scripts) \
+         $(dist_test_scripts) $(dist_uninstalled_test_scripts)
+
+# Note: build even the installed-only targets during 'make check' to ensure that they still work.
+# We need to do a bit of trickery here and manage disting via EXTRA_DIST instead of using dist_ prefixes to
+# prevent automake from mistreating gmake functions like $(wildcard ...) and $(addprefix ...) as if they were
+# filenames, including removing duplicate instances of the opening part before the space, eg. '$(addprefix'.
+all_test_programs     = $(test_programs) $(uninstalled_test_programs) $(installed_test_programs) \
+                        $(test_extra_programs) $(uninstalled_test_extra_programs) 
$(installed_test_extra_programs)
+all_test_scripts      = $(test_scripts) $(uninstalled_test_scripts) $(installed_test_scripts) \
+                        $(test_extra_scripts) $(uninstalled_test_extra_scripts) 
$(installed_test_extra_scripts)
+all_dist_test_scripts = $(dist_test_scripts) $(dist_uninstalled_test_scripts) $(dist_installed_test_scripts) 
\
+                        $(dist_test_extra_scripts) $(dist_uninstalled_test_extra_scripts) 
$(dist_installed_test_extra_scripts)
+all_test_scripts     += $(all_dist_test_scripts)
+EXTRA_DIST           += $(all_dist_test_scripts)
+all_test_data         = $(test_data) $(uninstalled_test_data) $(installed_test_data)
+all_dist_test_data    = $(dist_test_data) $(dist_uninstalled_test_data) $(dist_installed_test_data)
+all_test_data        += $(all_dist_test_data)
+EXTRA_DIST           += $(all_dist_test_data)
+all_test_ltlibs       = $(test_ltlibraries) $(uninstalled_test_ltlibraries) $(installed_test_ltlibraries)
+
+if ENABLE_ALWAYS_BUILD_TESTS
+noinst_LTLIBRARIES += $(all_test_ltlibs)
+noinst_PROGRAMS += $(all_test_programs)
+noinst_SCRIPTS += $(all_test_scripts)
+noinst_DATA += $(all_test_data)
+else
+check_LTLIBRARIES += $(all_test_ltlibs)
+check_PROGRAMS += $(all_test_programs)
+check_SCRIPTS += $(all_test_scripts)
+check_DATA += $(all_test_data)
+endif
+
+if ENABLE_INSTALLED_TESTS
+installed_test_PROGRAMS += $(test_programs) $(installed_test_programs) \
+                          $(test_extra_programs) $(installed_test_extra_programs)
+installed_test_SCRIPTS += $(test_scripts) $(installed_test_scripts) \
+                          $(test_extra_scripts) $(test_installed_extra_scripts)
+installed_test_SCRIPTS += $(dist_test_scripts) $(dist_test_extra_scripts) \
+                          $(dist_installed_test_scripts) $(dist_installed_test_extra_scripts)
+nobase_installed_test_DATA += $(test_data) $(installed_test_data)
+nobase_installed_test_DATA += $(dist_test_data) $(dist_installed_test_data)
+installed_test_LTLIBRARIES += $(test_ltlibraries) $(installed_test_ltlibraries)
+installed_testcases = $(test_programs) $(installed_test_programs) \
+                      $(test_scripts) $(installed_test_scripts) \
+                      $(dist_test_scripts) $(dist_installed_test_scripts)
+
+installed_test_meta_DATA = $(installed_testcases:=.test)
+
+%.test: %$(EXEEXT) Makefile
+       $(AM_V_GEN) (echo '[Test]' > $@.tmp; \
+       echo 'Type=session' >> $@.tmp; \
+       echo 'Exec=$(installed_testdir)/$<' >> $@.tmp; \
+       mv $@.tmp $@)
+
+CLEANFILES += $(installed_test_meta_DATA)
+endif
diff --git a/build-aux/tap-driver.sh b/build-aux/tap-driver.sh
new file mode 100755
index 0000000..19aa531
--- /dev/null
+++ b/build-aux/tap-driver.sh
@@ -0,0 +1,652 @@
+#! /bin/sh
+# Copyright (C) 2011-2013 Free Software Foundation, Inc.
+#
+# 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 2, 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 <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# This file is maintained in Automake, please report
+# bugs to <bug-automake gnu org> or send patches to
+# <automake-patches gnu org>.
+
+scriptversion=2011-12-27.17; # UTC
+
+# Make unconditional expansion of undefined variables an error.  This
+# helps a lot in preventing typo-related bugs.
+set -u
+
+me=tap-driver.sh
+
+fatal ()
+{
+  echo "$me: fatal: $*" >&2
+  exit 1
+}
+
+usage_error ()
+{
+  echo "$me: $*" >&2
+  print_usage >&2
+  exit 2
+}
+
+print_usage ()
+{
+  cat <<END
+Usage:
+  tap-driver.sh --test-name=NAME --log-file=PATH --trs-file=PATH
+                [--expect-failure={yes|no}] [--color-tests={yes|no}]
+                [--enable-hard-errors={yes|no}] [--ignore-exit]
+                [--diagnostic-string=STRING] [--merge|--no-merge]
+                [--comments|--no-comments] [--] TEST-COMMAND
+The \`--test-name', \`--log-file' and \`--trs-file' options are mandatory.
+END
+}
+
+# TODO: better error handling in option parsing (in particular, ensure
+# TODO: $log_file, $trs_file and $test_name are defined).
+test_name= # Used for reporting.
+log_file=  # Where to save the result and output of the test script.
+trs_file=  # Where to save the metadata of the test run.
+expect_failure=0
+color_tests=0
+merge=0
+ignore_exit=0
+comments=0
+diag_string='#'
+while test $# -gt 0; do
+  case $1 in
+  --help) print_usage; exit $?;;
+  --version) echo "$me $scriptversion"; exit $?;;
+  --test-name) test_name=$2; shift;;
+  --log-file) log_file=$2; shift;;
+  --trs-file) trs_file=$2; shift;;
+  --color-tests) color_tests=$2; shift;;
+  --expect-failure) expect_failure=$2; shift;;
+  --enable-hard-errors) shift;; # No-op.
+  --merge) merge=1;;
+  --no-merge) merge=0;;
+  --ignore-exit) ignore_exit=1;;
+  --comments) comments=1;;
+  --no-comments) comments=0;;
+  --diagnostic-string) diag_string=$2; shift;;
+  --) shift; break;;
+  -*) usage_error "invalid option: '$1'";;
+  esac
+  shift
+done
+
+test $# -gt 0 || usage_error "missing test command"
+
+case $expect_failure in
+  yes) expect_failure=1;;
+    *) expect_failure=0;;
+esac
+
+if test $color_tests = yes; then
+  init_colors='
+    color_map["red"]="" # Red.
+    color_map["grn"]="" # Green.
+    color_map["lgn"]="" # Light green.
+    color_map["blu"]="" # Blue.
+    color_map["mgn"]="" # Magenta.
+    color_map["std"]=""     # No color.
+    color_for_result["ERROR"] = "mgn"
+    color_for_result["PASS"]  = "grn"
+    color_for_result["XPASS"] = "red"
+    color_for_result["FAIL"]  = "red"
+    color_for_result["XFAIL"] = "lgn"
+    color_for_result["SKIP"]  = "blu"'
+else
+  init_colors=''
+fi
+
+# :; is there to work around a bug in bash 3.2 (and earlier) which
+# does not always set '$?' properly on redirection failure.
+# See the Autoconf manual for more details.
+:;{
+  (
+    # Ignore common signals (in this subshell only!), to avoid potential
+    # problems with Korn shells.  Some Korn shells are known to propagate
+    # to themselves signals that have killed a child process they were
+    # waiting for; this is done at least for SIGINT (and usually only for
+    # it, in truth).  Without the `trap' below, such a behaviour could
+    # cause a premature exit in the current subshell, e.g., in case the
+    # test command it runs gets terminated by a SIGINT.  Thus, the awk
+    # script we are piping into would never seen the exit status it
+    # expects on its last input line (which is displayed below by the
+    # last `echo $?' statement), and would thus die reporting an internal
+    # error.
+    # For more information, see the Autoconf manual and the threads:
+    # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
+    # <http://mail.opensolaris.org/pipermail/ksh93-integration-discuss/2009-February/004121.html>
+    trap : 1 3 2 13 15
+    if test $merge -gt 0; then
+      exec 2>&1
+    else
+      exec 2>&3
+    fi
+    "$@"
+    echo $?
+  ) | LC_ALL=C ${AM_TAP_AWK-awk} \
+        -v me="$me" \
+        -v test_script_name="$test_name" \
+        -v log_file="$log_file" \
+        -v trs_file="$trs_file" \
+        -v expect_failure="$expect_failure" \
+        -v merge="$merge" \
+        -v ignore_exit="$ignore_exit" \
+        -v comments="$comments" \
+        -v diag_string="$diag_string" \
+'
+# FIXME: the usages of "cat >&3" below could be optimized when using
+# FIXME: GNU awk, and/on on systems that supports /dev/fd/.
+
+# Implementation note: in what follows, `result_obj` will be an
+# associative array that (partly) simulates a TAP result object
+# from the `TAP::Parser` perl module.
+
+## ----------- ##
+##  FUNCTIONS  ##
+## ----------- ##
+
+function fatal(msg)
+{
+  print me ": " msg | "cat >&2"
+  exit 1
+}
+
+function abort(where)
+{
+  fatal("internal error " where)
+}
+
+# Convert a boolean to a "yes"/"no" string.
+function yn(bool)
+{
+  return bool ? "yes" : "no";
+}
+
+function add_test_result(result)
+{
+  if (!test_results_index)
+    test_results_index = 0
+  test_results_list[test_results_index] = result
+  test_results_index += 1
+  test_results_seen[result] = 1;
+}
+
+# Whether the test script should be re-run by "make recheck".
+function must_recheck()
+{
+  for (k in test_results_seen)
+    if (k != "XFAIL" && k != "PASS" && k != "SKIP")
+      return 1
+  return 0
+}
+
+# Whether the content of the log file associated to this test should
+# be copied into the "global" test-suite.log.
+function copy_in_global_log()
+{
+  for (k in test_results_seen)
+    if (k != "PASS")
+      return 1
+  return 0
+}
+
+# FIXME: this can certainly be improved ...
+function get_global_test_result()
+{
+    if ("ERROR" in test_results_seen)
+      return "ERROR"
+    if ("FAIL" in test_results_seen || "XPASS" in test_results_seen)
+      return "FAIL"
+    all_skipped = 1
+    for (k in test_results_seen)
+      if (k != "SKIP")
+        all_skipped = 0
+    if (all_skipped)
+      return "SKIP"
+    return "PASS";
+}
+
+function stringify_result_obj(result_obj)
+{
+  if (result_obj["is_unplanned"] || result_obj["number"] != testno)
+    return "ERROR"
+
+  if (plan_seen == LATE_PLAN)
+    return "ERROR"
+
+  if (result_obj["directive"] == "TODO")
+    return result_obj["is_ok"] ? "XPASS" : "XFAIL"
+
+  if (result_obj["directive"] == "SKIP")
+    return result_obj["is_ok"] ? "SKIP" : COOKED_FAIL;
+
+  if (length(result_obj["directive"]))
+      abort("in function stringify_result_obj()")
+
+  return result_obj["is_ok"] ? COOKED_PASS : COOKED_FAIL
+}
+
+function decorate_result(result)
+{
+  color_name = color_for_result[result]
+  if (color_name)
+    return color_map[color_name] "" result "" color_map["std"]
+  # If we are not using colorized output, or if we do not know how
+  # to colorize the given result, we should return it unchanged.
+  return result
+}
+
+function report(result, details)
+{
+  if (result ~ /^(X?(PASS|FAIL)|SKIP|ERROR)/)
+    {
+      msg = ": " test_script_name
+      add_test_result(result)
+    }
+  else if (result == "#")
+    {
+      msg = " " test_script_name ":"
+    }
+  else
+    {
+      abort("in function report()")
+    }
+  if (length(details))
+    msg = msg " " details
+  # Output on console might be colorized.
+  print decorate_result(result) msg
+  # Log the result in the log file too, to help debugging (this is
+  # especially true when said result is a TAP error or "Bail out!").
+  print result msg | "cat >&3";
+}
+
+function testsuite_error(error_message)
+{
+  report("ERROR", "- " error_message)
+}
+
+function handle_tap_result()
+{
+  details = result_obj["number"];
+  if (length(result_obj["description"]))
+    details = details " " result_obj["description"]
+
+  if (plan_seen == LATE_PLAN)
+    {
+      details = details " # AFTER LATE PLAN";
+    }
+  else if (result_obj["is_unplanned"])
+    {
+       details = details " # UNPLANNED";
+    }
+  else if (result_obj["number"] != testno)
+    {
+       details = sprintf("%s # OUT-OF-ORDER (expecting %d)",
+                         details, testno);
+    }
+  else if (result_obj["directive"])
+    {
+      details = details " # " result_obj["directive"];
+      if (length(result_obj["explanation"]))
+        details = details " " result_obj["explanation"]
+    }
+
+  report(stringify_result_obj(result_obj), details)
+}
+
+# `skip_reason` should be empty whenever planned > 0.
+function handle_tap_plan(planned, skip_reason)
+{
+  planned += 0 # Avoid getting confused if, say, `planned` is "00"
+  if (length(skip_reason) && planned > 0)
+    abort("in function handle_tap_plan()")
+  if (plan_seen)
+    {
+      # Error, only one plan per stream is acceptable.
+      testsuite_error("multiple test plans")
+      return;
+    }
+  planned_tests = planned
+  # The TAP plan can come before or after *all* the TAP results; we speak
+  # respectively of an "early" or a "late" plan.  If we see the plan line
+  # after at least one TAP result has been seen, assume we have a late
+  # plan; in this case, any further test result seen after the plan will
+  # be flagged as an error.
+  plan_seen = (testno >= 1 ? LATE_PLAN : EARLY_PLAN)
+  # If testno > 0, we have an error ("too many tests run") that will be
+  # automatically dealt with later, so do not worry about it here.  If
+  # $plan_seen is true, we have an error due to a repeated plan, and that
+  # has already been dealt with above.  Otherwise, we have a valid "plan
+  # with SKIP" specification, and should report it as a particular kind
+  # of SKIP result.
+  if (planned == 0 && testno == 0)
+    {
+      if (length(skip_reason))
+        skip_reason = "- "  skip_reason;
+      report("SKIP", skip_reason);
+    }
+}
+
+function extract_tap_comment(line)
+{
+  if (index(line, diag_string) == 1)
+    {
+      # Strip leading `diag_string` from `line`.
+      line = substr(line, length(diag_string) + 1)
+      # And strip any leading and trailing whitespace left.
+      sub("^[ \t]*", "", line)
+      sub("[ \t]*$", "", line)
+      # Return what is left (if any).
+      return line;
+    }
+  return "";
+}
+
+# When this function is called, we know that line is a TAP result line,
+# so that it matches the (perl) RE "^(not )?ok\b".
+function setup_result_obj(line)
+{
+  # Get the result, and remove it from the line.
+  result_obj["is_ok"] = (substr(line, 1, 2) == "ok" ? 1 : 0)
+  sub("^(not )?ok[ \t]*", "", line)
+
+  # If the result has an explicit number, get it and strip it; otherwise,
+  # automatically assing the next progresive number to it.
+  if (line ~ /^[0-9]+$/ || line ~ /^[0-9]+[^a-zA-Z0-9_]/)
+    {
+      match(line, "^[0-9]+")
+      # The final `+ 0` is to normalize numbers with leading zeros.
+      result_obj["number"] = substr(line, 1, RLENGTH) + 0
+      line = substr(line, RLENGTH + 1)
+    }
+  else
+    {
+      result_obj["number"] = testno
+    }
+
+  if (plan_seen == LATE_PLAN)
+    # No further test results are acceptable after a "late" TAP plan
+    # has been seen.
+    result_obj["is_unplanned"] = 1
+  else if (plan_seen && testno > planned_tests)
+    result_obj["is_unplanned"] = 1
+  else
+    result_obj["is_unplanned"] = 0
+
+  # Strip trailing and leading whitespace.
+  sub("^[ \t]*", "", line)
+  sub("[ \t]*$", "", line)
+
+  # This will have to be corrected if we have a "TODO"/"SKIP" directive.
+  result_obj["description"] = line
+  result_obj["directive"] = ""
+  result_obj["explanation"] = ""
+
+  if (index(line, "#") == 0)
+    return # No possible directive, nothing more to do.
+
+  # Directives are case-insensitive.
+  rx = "[ \t]*#[ \t]*([tT][oO][dD][oO]|[sS][kK][iI][pP])[ \t]*"
+
+  # See whether we have the directive, and if yes, where.
+  pos = match(line, rx "$")
+  if (!pos)
+    pos = match(line, rx "[^a-zA-Z0-9_]")
+
+  # If there was no TAP directive, we have nothing more to do.
+  if (!pos)
+    return
+
+  # Let`s now see if the TAP directive has been escaped.  For example:
+  #  escaped:     ok \# SKIP
+  #  not escaped: ok \\# SKIP
+  #  escaped:     ok \\\\\# SKIP
+  #  not escaped: ok \ # SKIP
+  if (substr(line, pos, 1) == "#")
+    {
+      bslash_count = 0
+      for (i = pos; i > 1 && substr(line, i - 1, 1) == "\\"; i--)
+        bslash_count += 1
+      if (bslash_count % 2)
+        return # Directive was escaped.
+    }
+
+  # Strip the directive and its explanation (if any) from the test
+  # description.
+  result_obj["description"] = substr(line, 1, pos - 1)
+  # Now remove the test description from the line, that has been dealt
+  # with already.
+  line = substr(line, pos)
+  # Strip the directive, and save its value (normalized to upper case).
+  sub("^[ \t]*#[ \t]*", "", line)
+  result_obj["directive"] = toupper(substr(line, 1, 4))
+  line = substr(line, 5)
+  # Now get the explanation for the directive (if any), with leading
+  # and trailing whitespace removed.
+  sub("^[ \t]*", "", line)
+  sub("[ \t]*$", "", line)
+  result_obj["explanation"] = line
+}
+
+function get_test_exit_message(status)
+{
+  if (status == 0)
+    return ""
+  if (status !~ /^[1-9][0-9]*$/)
+    abort("getting exit status")
+  if (status < 127)
+    exit_details = ""
+  else if (status == 127)
+    exit_details = " (command not found?)"
+  else if (status >= 128 && status <= 255)
+    exit_details = sprintf(" (terminated by signal %d?)", status - 128)
+  else if (status > 256 && status <= 384)
+    # We used to report an "abnormal termination" here, but some Korn
+    # shells, when a child process die due to signal number n, can leave
+    # in $? an exit status of 256+n instead of the more standard 128+n.
+    # Apparently, both behaviours are allowed by POSIX (2008), so be
+    # prepared to handle them both.  See also Austing Group report ID
+    # 0000051 <http://www.austingroupbugs.net/view.php?id=51>
+    exit_details = sprintf(" (terminated by signal %d?)", status - 256)
+  else
+    # Never seen in practice.
+    exit_details = " (abnormal termination)"
+  return sprintf("exited with status %d%s", status, exit_details)
+}
+
+function write_test_results()
+{
+  print ":global-test-result: " get_global_test_result() > trs_file
+  print ":recheck: "  yn(must_recheck()) > trs_file
+  print ":copy-in-global-log: " yn(copy_in_global_log()) > trs_file
+  for (i = 0; i < test_results_index; i += 1)
+    print ":test-result: " test_results_list[i] > trs_file
+  close(trs_file);
+}
+
+BEGIN {
+
+## ------- ##
+##  SETUP  ##
+## ------- ##
+
+'"$init_colors"'
+
+# Properly initialized once the TAP plan is seen.
+planned_tests = 0
+
+COOKED_PASS = expect_failure ? "XPASS": "PASS";
+COOKED_FAIL = expect_failure ? "XFAIL": "FAIL";
+
+# Enumeration-like constants to remember which kind of plan (if any)
+# has been seen.  It is important that NO_PLAN evaluates "false" as
+# a boolean.
+NO_PLAN = 0
+EARLY_PLAN = 1
+LATE_PLAN = 2
+
+testno = 0     # Number of test results seen so far.
+bailed_out = 0 # Whether a "Bail out!" directive has been seen.
+
+# Whether the TAP plan has been seen or not, and if yes, which kind
+# it is ("early" is seen before any test result, "late" otherwise).
+plan_seen = NO_PLAN
+
+## --------- ##
+##  PARSING  ##
+## --------- ##
+
+is_first_read = 1
+
+while (1)
+  {
+    # Involutions required so that we are able to read the exit status
+    # from the last input line.
+    st = getline
+    if (st < 0) # I/O error.
+      fatal("I/O error while reading from input stream")
+    else if (st == 0) # End-of-input
+      {
+        if (is_first_read)
+          abort("in input loop: only one input line")
+        break
+      }
+    if (is_first_read)
+      {
+        is_first_read = 0
+        nextline = $0
+        continue
+      }
+    else
+      {
+        curline = nextline
+        nextline = $0
+        $0 = curline
+      }
+    # Copy any input line verbatim into the log file.
+    print | "cat >&3"
+    # Parsing of TAP input should stop after a "Bail out!" directive.
+    if (bailed_out)
+      continue
+
+    # TAP test result.
+    if ($0 ~ /^(not )?ok$/ || $0 ~ /^(not )?ok[^a-zA-Z0-9_]/)
+      {
+        testno += 1
+        setup_result_obj($0)
+        handle_tap_result()
+      }
+    # TAP plan (normal or "SKIP" without explanation).
+    else if ($0 ~ /^1\.\.[0-9]+[ \t]*$/)
+      {
+        # The next two lines will put the number of planned tests in $0.
+        sub("^1\\.\\.", "")
+        sub("[^0-9]*$", "")
+        handle_tap_plan($0, "")
+        continue
+      }
+    # TAP "SKIP" plan, with an explanation.
+    else if ($0 ~ /^1\.\.0+[ \t]*#/)
+      {
+        # The next lines will put the skip explanation in $0, stripping
+        # any leading and trailing whitespace.  This is a little more
+        # tricky in truth, since we want to also strip a potential leading
+        # "SKIP" string from the message.
+        sub("^[^#]*#[ \t]*(SKIP[: \t][ \t]*)?", "")
+        sub("[ \t]*$", "");
+        handle_tap_plan(0, $0)
+      }
+    # "Bail out!" magic.
+    # Older versions of prove and TAP::Harness (e.g., 3.17) did not
+    # recognize a "Bail out!" directive when preceded by leading
+    # whitespace, but more modern versions (e.g., 3.23) do.  So we
+    # emulate the latter, "more modern" behaviour.
+    else if ($0 ~ /^[ \t]*Bail out!/)
+      {
+        bailed_out = 1
+        # Get the bailout message (if any), with leading and trailing
+        # whitespace stripped.  The message remains stored in `$0`.
+        sub("^[ \t]*Bail out![ \t]*", "");
+        sub("[ \t]*$", "");
+        # Format the error message for the
+        bailout_message = "Bail out!"
+        if (length($0))
+          bailout_message = bailout_message " " $0
+        testsuite_error(bailout_message)
+      }
+    # Maybe we have too look for dianogtic comments too.
+    else if (comments != 0)
+      {
+        comment = extract_tap_comment($0);
+        if (length(comment))
+          report("#", comment);
+      }
+  }
+
+## -------- ##
+##  FINISH  ##
+## -------- ##
+
+# A "Bail out!" directive should cause us to ignore any following TAP
+# error, as well as a non-zero exit status from the TAP producer.
+if (!bailed_out)
+  {
+    if (!plan_seen)
+      {
+        testsuite_error("missing test plan")
+      }
+    else if (planned_tests != testno)
+      {
+        bad_amount = testno > planned_tests ? "many" : "few"
+        testsuite_error(sprintf("too %s tests run (expected %d, got %d)",
+                                bad_amount, planned_tests, testno))
+      }
+    if (!ignore_exit)
+      {
+        # Fetch exit status from the last line.
+        exit_message = get_test_exit_message(nextline)
+        if (exit_message)
+          testsuite_error(exit_message)
+      }
+  }
+
+write_test_results()
+
+exit 0
+
+} # End of "BEGIN" block.
+'
+
+# TODO: document that we consume the file descriptor 3 :-(
+} 3>"$log_file"
+
+test $? -eq 0 || fatal "I/O or internal error"
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/build-aux/tap-test b/build-aux/tap-test
new file mode 100755
index 0000000..481e333
--- /dev/null
+++ b/build-aux/tap-test
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+# run a GTest in tap mode. The test binary is passed as $1
+
+$1 -k --tap
diff --git a/configure.ac b/configure.ac
index a448018..6cff8b4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -105,6 +105,8 @@ AM_CONDITIONAL(HAVE_WEASYPRINT, [test x$WEASYPRINT = xweasyprint])
 AC_CHECK_PROG([HELP2MAN], [help2man], [help2man])
 AM_CONDITIONAL([HAVE_HELP2MAN], [test x$HELP2MAN = xhelp2man])
 
+GLIB_TESTS
+
 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
 
 AC_CONFIG_FILES([Makefile
@@ -115,6 +117,7 @@ AC_CONFIG_FILES([Makefile
            codegen/Makefile
            compiler/Makefile
            vapi/Makefile
+           valadate/Makefile
            tests/Makefile
            doc/Makefile
            doc/manual/Makefile
diff --git a/m4/glibtests.m4 b/m4/glibtests.m4
new file mode 100644
index 0000000..7d5920a
--- /dev/null
+++ b/m4/glibtests.m4
@@ -0,0 +1,28 @@
+dnl GLIB_TESTS
+dnl
+
+AC_DEFUN([GLIB_TESTS],
+[
+  AC_ARG_ENABLE(installed-tests,
+                AS_HELP_STRING([--enable-installed-tests],
+                               [Enable installation of some test cases]),
+                [case ${enableval} in
+                  yes) ENABLE_INSTALLED_TESTS="1"  ;;
+                  no)  ENABLE_INSTALLED_TESTS="" ;;
+                  *) AC_MSG_ERROR([bad value ${enableval} for --enable-installed-tests]) ;;
+                 esac])
+  AM_CONDITIONAL([ENABLE_INSTALLED_TESTS], test "$ENABLE_INSTALLED_TESTS" = "1")
+  AC_ARG_ENABLE(always-build-tests,
+                AS_HELP_STRING([--enable-always-build-tests],
+                               [Enable always building tests during 'make all']),
+                [case ${enableval} in
+                  yes) ENABLE_ALWAYS_BUILD_TESTS="1"  ;;
+                  no)  ENABLE_ALWAYS_BUILD_TESTS="" ;;
+                  *) AC_MSG_ERROR([bad value ${enableval} for --enable-always-build-tests]) ;;
+                 esac])
+  AM_CONDITIONAL([ENABLE_ALWAYS_BUILD_TESTS], test "$ENABLE_ALWAYS_BUILD_TESTS" = "1")
+  if test "$ENABLE_INSTALLED_TESTS" = "1"; then
+    AC_SUBST(installed_test_metadir, [${datadir}/installed-tests/]AC_PACKAGE_NAME)
+    AC_SUBST(installed_testdir, [${libexecdir}/installed-tests/]AC_PACKAGE_NAME)
+  fi
+])
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2a2f4d4..1e8de9c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,302 +1,48 @@
-NULL =
-
-AM_CPPFLAGS = \
-       $(GLIB_CFLAGS) \
-       $(NULL)
-AM_LDFLAGS = \
-       $(GLIB_LIBS) \
+include $(top_srcdir)/Makefile.common
+include $(top_srcdir)/build-aux/glib-tap.mk
+
+test_programs = valactests-0
+
+valactests_0_VALAFLAGS = \
+       --vapidir $(top_srcdir)/valadate \
+       --vapidir $(top_srcdir)/vapi \
+       --pkg valadate \
+       --pkg gio-2.0 \
+       --pkg config \
+       --library valactests-0 \
+       -g \
        $(NULL)
 
-BUILT_SOURCES = \
-       $(NULL)
-noinst_PROGRAMS = \
-       $(NULL)
+valactests_0_SOURCES = \
+       valatests.vala
 
-TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT) CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' 
$(srcdir)/testrunner.sh
-
-TESTS = \
-       basic-types/integers.vala \
-       basic-types/escape-chars.vala \
-       basic-types/floats.vala \
-       basic-types/strings.vala \
-       basic-types/arrays.vala \
-       basic-types/pointers.vala \
-       basic-types/sizeof.vala \
-       basic-types/bug571486.vala \
-       basic-types/bug591552.vala \
-       basic-types/bug595751.vala \
-       basic-types/bug596637.vala \
-       basic-types/bug596785.vala \
-       basic-types/bug632322.vala \
-       basic-types/bug643612.vala \
-       basic-types/bug644046.vala \
-       basic-types/bug647222.vala \
-       basic-types/bug648364.vala \
-       basic-types/bug650993.vala \
-       basic-types/bug652380.vala \
-       basic-types/bug655908.vala \
-       basic-types/bug659975.vala \
-       basic-types/bug678791.vala \
-       basic-types/bug686336.vala \
-       basic-types/bug729907.vala \
-       basic-types/bug731017.vala \
-       basic-types/bug756376.vala \
-       basic-types/bug761307.vala \
-       basic-types/bug771626.test \
-       basic-types/bug777697.test \
-       chainup/class-base.vala \
-       chainup/class-base-foo.vala \
-       chainup/class-object.vala \
-       chainup/class-this.vala \
-       chainup/class-this-foo.vala \
-       chainup/no-chainup.vala \
-       chainup/struct-base.vala \
-       chainup/struct-base-foo.vala \
-       chainup/struct-this.vala \
-       chainup/struct-this-foo.vala \
-       pointers/bug590641.vala \
-       namespaces.vala \
-       methods/lambda.vala \
-       methods/closures.vala \
-       methods/prepostconditions.vala \
-       methods/symbolresolution.vala \
-       methods/bug595538.vala \
-       methods/bug596726.vala \
-       methods/bug597426.vala \
-       methods/bug598738.vala \
-       methods/bug599892.vala \
-       methods/bug613483.vala \
-       methods/bug620673.vala \
-       methods/bug622570.vala \
-       methods/bug626783.vala \
-       methods/bug639054.vala \
-       methods/bug642350.vala \
-       methods/bug642885.vala \
-       methods/bug642899.vala \
-       methods/bug646345.vala \
-       methods/bug648030.test \
-       methods/bug648320.vala \
-       methods/bug649562.vala \
-       methods/bug652098.vala \
-       methods/bug653391.vala \
-       methods/bug653908.vala \
-       methods/bug663210.vala \
-       methods/bug710862.vala \
-       methods/bug723009.vala \
-       methods/bug723195.vala \
-       methods/bug726347.vala \
-       methods/bug736235.vala \
-       methods/bug737222.vala \
-       methods/bug743877.vala \
-       methods/bug771964.vala \
-       methods/bug774060.vala \
-       methods/bug775466.test \
-       methods/generics.vala \
-       methods/printf-invalid.test \
-       methods/printf-constructor.vala \
-       methods/printf-constructor-invalid.test \
-       control-flow/break.vala \
-       control-flow/expressions-conditional.vala \
-       control-flow/for.vala \
-       control-flow/foreach.vala \
-       control-flow/nested-conditional.vala \
-       control-flow/switch.vala \
-       control-flow/sideeffects.vala \
-       control-flow/bug628336.vala \
-       control-flow/bug639482.vala \
-       control-flow/bug652549.vala \
-       control-flow/bug661985.vala \
-       control-flow/bug665904.vala \
-       control-flow/bug691514.vala     \
-       enums/enums.vala \
-       enums/flags.vala \
-       enums/bug673879.vala \
-       enums/bug763831.vala \
-       enums/bug780050.vala \
-       structs/structs.vala \
-       structs/gvalue.vala \
-       structs/bug530605.vala \
-       structs/bug572091.vala \
-       structs/bug583603.vala \
-       structs/bug595587.vala \
-       structs/bug596144.vala \
-       structs/bug603056.vala \
-       structs/bug606202.vala \
-       structs/bug609642.vala \
-       structs/bug613513.vala \
-       structs/bug613825.vala \
-       structs/bug621176.vala \
-       structs/bug622422.vala \
-       structs/bug623092.vala \
-       structs/bug651441.vala \
-       structs/bug654646.vala \
-       structs/bug654753.vala \
-       structs/bug656693.vala \
-       structs/bug657378.vala \
-       structs/bug658048.vala \
-       structs/bug660426.vala \
-       structs/bug661945.vala \
-       structs/bug667890.vala \
-       structs/bug669580.vala \
-       structs/bug685177.vala \
-       structs/bug686190.vala \
-       structs/bug690380.vala \
-       structs/bug694140.vala \
-       structs/bug749952.vala \
-       structs/bug775761.vala \
-       structs/bug777194.vala \
-       delegates/casting.vala \
-       delegates/delegates.vala \
-       delegates/reference_transfer.vala \
-       delegates/bug539166.vala \
-       delegates/bug595610.vala \
-       delegates/bug595639.vala \
-       delegates/bug638415.vala \
-       delegates/bug639751.vala \
-       delegates/bug659778.vala \
-       delegates/bug683925.vala \
-       delegates/bug703804.vala \
-       delegates/bug761360.vala \
-       delegates/bug772204.test \
-       objects/chainup.vala \
-       objects/classes.vala \
-       objects/generics.vala \
-       objects/fields.vala \
-       objects/interfaces.vala \
-       objects/methods.vala \
-       objects/properties.vala \
-       objects/regex.vala \
-       objects/signals.vala \
-       objects/test-025.vala \
-       objects/test-026.vala \
-       objects/test-029.vala \
-       objects/test-034.vala \
-       objects/bug566909.vala \
-       objects/bug588203.vala \
-       objects/bug589928.vala \
-       objects/bug593260.vala \
-       objects/bug596621.vala \
-       objects/bug597155.vala \
-       objects/bug597161.vala \
-       objects/bug603491.test \
-       objects/bug613486.vala \
-       objects/bug613840.vala \
-       objects/bug620675.vala \
-       objects/bug620706.vala \
-       objects/bug624594.vala \
-       objects/bug626038.vala \
-       objects/bug628639.vala \
-       objects/bug631267.vala \
-       objects/bug634782.vala \
-       objects/bug641418-1.test \
-       objects/bug641418-2.test \
-       objects/bug641418-3.test \
-       objects/bug641828.vala \
-       objects/bug642809.vala \
-       objects/bug643711.vala \
-       objects/bug644938.vala \
-       objects/bug646362.vala \
-       objects/bug646792.vala \
-       objects/bug647018.vala \
-       objects/bug653138.vala \
-       objects/bug654702.vala \
-       objects/bug663134.vala \
-       objects/bug664529.vala \
-       objects/bug667668.vala \
-       objects/bug681356.vala \
-       objects/bug683646.vala \
-       objects/bug695671.vala \
-       objects/bug701978.vala \
-       objects/bug702736.vala \
-       objects/bug702846.vala \
-       objects/bug751338.vala \
-       objects/bug758816.vala \
-       objects/bug760031.test \
-       objects/bug764481.vala \
-       objects/bug767092.test \
-       objects/bug768823.test \
-       objects/bug773956-1.test \
-       objects/bug773956-2.test \
-       objects/bug615830-1.test \
-       objects/bug615830-2.test \
-       objects/bug766739.vala \
-       objects/bug778632.vala \
-       objects/bug779038-1.test \
-       objects/bug779038-2.test \
-       objects/bug779038-3.test \
-       objects/bug779219.vala \
-       objects/bug779955.vala \
-       errors/errors.vala \
-       errors/bug567181.vala \
-       errors/bug579101.vala \
-       errors/bug596228.vala \
-       errors/bug623049.vala \
-       errors/bug639589.vala \
-       errors/bug651145.vala \
-       errors/bug778224.vala \
-       asynchronous/bug595735.vala \
-       asynchronous/bug595755.vala \
-       asynchronous/bug596177.vala \
-       asynchronous/bug596861.vala \
-       asynchronous/bug597294.vala \
-       asynchronous/bug598677.vala \
-       asynchronous/bug598697.vala \
-       asynchronous/bug598698.vala \
-       asynchronous/bug599568.vala \
-       asynchronous/bug600827.vala \
-       asynchronous/bug601558.vala \
-       asynchronous/bug613484.vala \
-       asynchronous/bug620740.vala \
-       asynchronous/bug639591.vala \
-       asynchronous/bug640721.vala \
-       asynchronous/bug641182.vala \
-       asynchronous/bug646945.vala \
-       asynchronous/bug652252.vala \
-       asynchronous/bug653861.vala \
-       asynchronous/bug654336.vala \
-       asynchronous/bug654337.vala \
-       asynchronous/bug659886.vala \
-       asynchronous/bug661961.vala \
-       asynchronous/bug710103.vala \
-       asynchronous/bug742621.vala \
-       asynchronous/bug762819.vala \
-       asynchronous/bug777242.vala \
-       asynchronous/closures.vala \
-       asynchronous/generator.vala \
-       asynchronous/yield.vala \
-       dbus/basic-types.test \
-       dbus/arrays.test \
-       dbus/structs.test \
-       dbus/errors.test \
-       dbus/async.test \
-       dbus/async-errors.test \
-       dbus/enum-string-marshalling.vala \
-       dbus/signals.test \
-       dbus/filedescriptor.test \
-       dbus/filedescriptor-errors.test \
-       dbus/dicts.test \
-       dbus/bug596862.vala \
-       dbus/bug602003.test \
-       dbus/rawvariants.test \
-       gir/bug651773.test \
-       gir/bug667751.test \
-       gir/bug742012.test \
-       gir/array-fixed-length.test \
-       annotations/deprecated.vala \
-       annotations/description.vala \
+valactests_0_LDADD = \
+       $(GLIB_LIBS) \
+       $(GMODULE_LIBS) \
+       -lgio-2.0 \
+       -lm \
+       $(top_srcdir)/valadate/libvaladate.la \
        $(NULL)
 
-NON_NULL_TESTS = \
-       nullability/bug611223.vala \
+valactests_0_CPPFLAGS = \
+       -I$(top_srcdir)/valadate \
+       $(GLIB_CPPFLAGS) \
+       $(GMODULE_CPPFLAGS) \
+       -fPIE \
        $(NULL)
 
-check-TESTS: $(TESTS) $(NON_NULL_TESTS)
-       @EXEEXT=$(EXEEXT) EXEEXT=$(EXEEXT) CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' 
$(srcdir)/testrunner.sh $(TESTS)
-       @EXEEXT=$(EXEEXT) EXEEXT=$(EXEEXT) CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' 
VALAFLAGS="--enable-experimental-non-null" $(srcdir)/testrunner.sh $(NON_NULL_TESTS)
-
-EXTRA_DIST = \
-       testrunner.sh \
-       $(TESTS) \
-       $(NON_NULL_TESTS) \
+valactests_0_CFLAGS = \
+       -I$(top_srcdir)/valadate \
+       $(GLIB_CFLAGS) \
+       $(GMODULE_CFLAGS) \
+       -pie \
+       -g \
        $(NULL)
 
+CLEANFILES += \
+       *.gir \
+       *.stamp \
+       $(valactests_0_SOURCES:.vala=.c) \
+       *.vapi \
+       rm -R .tests \
+       $(NULL)
diff --git a/tests/asynchronous/bug595755.vala b/tests/asynchronous/bug595755.vala
index ac9bbd5..bf5098b 100644
--- a/tests/asynchronous/bug595755.vala
+++ b/tests/asynchronous/bug595755.vala
@@ -9,3 +9,4 @@ class Foo : Object {
 
 void main () {
 }
+
diff --git a/tests/asynchronous/bug596861.vala b/tests/asynchronous/bug596861.vala
index f73ccfa..873f4b2 100644
--- a/tests/asynchronous/bug596861.vala
+++ b/tests/asynchronous/bug596861.vala
@@ -15,5 +15,5 @@ async int foo () throws Error {
        return 0;
 }
 
-void main() {
+void main () {
 }
diff --git a/tests/namespaces.vala b/tests/control-flow/namespaces.vala
similarity index 100%
rename from tests/namespaces.vala
rename to tests/control-flow/namespaces.vala
diff --git a/tests/dbus/arrays.test b/tests/dbus/arrays.test
index fa884ca..5098d30 100644
--- a/tests/dbus/arrays.test
+++ b/tests/dbus/arrays.test
@@ -68,7 +68,7 @@ void main () {
 
        // server ready, spawn client
        Pid client_pid;
-       Process.spawn_async (null, { "test", "/dbus/arrays/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, 
null, out client_pid);
+       Process.spawn_async (null, { "arrays.client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out 
client_pid);
        ChildWatch.add (client_pid, client_exit);
 
        main_loop = new MainLoop ();
diff --git a/tests/dbus/async-errors.test b/tests/dbus/async-errors.test
index 4c9483f..28c0626 100644
--- a/tests/dbus/async-errors.test
+++ b/tests/dbus/async-errors.test
@@ -102,7 +102,7 @@ void main () {
 
        // server ready, spawn client
        Pid client_pid;
-       Process.spawn_async (null, { "test", "/dbus/async-errors/client" }, null, 
SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
+       Process.spawn_async (null, { "async-errors.client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out 
client_pid);
        ChildWatch.add (client_pid, client_exit);
 
        main_loop = new MainLoop ();
diff --git a/tests/dbus/async.test b/tests/dbus/async.test
index cb6a541..3989d44 100644
--- a/tests/dbus/async.test
+++ b/tests/dbus/async.test
@@ -83,7 +83,7 @@ void main () {
 
        // server ready, spawn client
        Pid client_pid;
-       Process.spawn_async (null, { "test", "/dbus/async/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, 
null, out client_pid);
+       Process.spawn_async (null, { "async.client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out 
client_pid);
        ChildWatch.add (client_pid, client_exit);
 
        main_loop = new MainLoop ();
diff --git a/tests/dbus/basic-types.test b/tests/dbus/basic-types.test
index 9b183f7..c9fac9f 100644
--- a/tests/dbus/basic-types.test
+++ b/tests/dbus/basic-types.test
@@ -74,7 +74,7 @@ void main () {
 
        // server ready, spawn client
        Pid client_pid;
-       Process.spawn_async (null, { "test", "/dbus/basic-types/client" }, null, 
SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
+       Process.spawn_async (null, { "basic-types.client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out 
client_pid);
        ChildWatch.add (client_pid, client_exit);
 
        main_loop = new MainLoop ();
diff --git a/tests/dbus/bug602003.test b/tests/dbus/bug602003.test
index ceb2327..bd1b802 100644
--- a/tests/dbus/bug602003.test
+++ b/tests/dbus/bug602003.test
@@ -46,7 +46,7 @@ void main () {
 
        // server ready, spawn client
        Pid client_pid;
-       Process.spawn_async (null, { "test", "/dbus/bug602003/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, 
null, out client_pid);
+       Process.spawn_async (null, { "bug602003.client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out 
client_pid);
        ChildWatch.add (client_pid, client_exit);
 
        main_loop = new MainLoop ();
diff --git a/tests/dbus/dicts.test b/tests/dbus/dicts.test
index 1e7037e..d5a8b62 100644
--- a/tests/dbus/dicts.test
+++ b/tests/dbus/dicts.test
@@ -64,7 +64,7 @@ void main () {
 
        // server ready, spawn client
        Pid client_pid;
-       Process.spawn_async (null, { "test", "/dbus/dicts/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, 
null, out client_pid);
+       Process.spawn_async (null, { "dicts.client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out 
client_pid);
        ChildWatch.add (client_pid, client_exit);
 
        main_loop = new MainLoop ();
diff --git a/tests/dbus/errors.test b/tests/dbus/errors.test
index 9088fb4..3b57864 100644
--- a/tests/dbus/errors.test
+++ b/tests/dbus/errors.test
@@ -85,7 +85,7 @@ void main () {
 
        // server ready, spawn client
        Pid client_pid;
-       Process.spawn_async (null, { "test", "/dbus/errors/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, 
null, out client_pid);
+       Process.spawn_async (null, { "errors.client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out 
client_pid);
        ChildWatch.add (client_pid, client_exit);
 
        main_loop = new MainLoop ();
diff --git a/tests/dbus/filedescriptor.test b/tests/dbus/filedescriptor.test
index 3eeb9ef..6629dad 100644
--- a/tests/dbus/filedescriptor.test
+++ b/tests/dbus/filedescriptor.test
@@ -76,7 +76,7 @@ void main () {
 
        // server ready, spawn client
        Pid client_pid;
-       Process.spawn_async (null, { "test", "/dbus/filedescriptor/client" }, null, 
SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
+       Process.spawn_async (null, { "filedescriptor.client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out 
client_pid);
        ChildWatch.add (client_pid, client_exit);
 
        main_loop = new MainLoop ();
diff --git a/tests/dbus/signals.test b/tests/dbus/signals.test
index e46320b..2f6aa2b 100644
--- a/tests/dbus/signals.test
+++ b/tests/dbus/signals.test
@@ -57,7 +57,7 @@ void main () {
 
        // server ready, spawn client
        Pid client_pid;
-       Process.spawn_async (null, { "test", "/dbus/signals/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, 
null, out client_pid);
+       Process.spawn_async (null, { "signals.client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out 
client_pid);
        ChildWatch.add (client_pid, client_exit);
 
        main_loop = new MainLoop ();
diff --git a/tests/dbus/structs.test b/tests/dbus/structs.test
index d23dd84..0080061 100644
--- a/tests/dbus/structs.test
+++ b/tests/dbus/structs.test
@@ -81,7 +81,7 @@ void main () {
 
        // server ready, spawn client
        Pid client_pid;
-       Process.spawn_async (null, { "test", "/dbus/structs/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, 
null, out client_pid);
+       Process.spawn_async (null, { "structs.client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out 
client_pid);
        ChildWatch.add (client_pid, client_exit);
 
        main_loop = new MainLoop ();
diff --git a/tests/delegates/bug659778.vala b/tests/delegates/bug659778.vala
index e73e3c1..dfafae1 100644
--- a/tests/delegates/bug659778.vala
+++ b/tests/delegates/bug659778.vala
@@ -2,10 +2,10 @@ delegate G DoSomething<G>(G g);
 
 void do_something<G> (DoSomething<G> f) {}
 
-enum TE {
+enum TEP {
        T;
        public void f() {
-               do_something<TE> ((x) => {
+               do_something<TEP> ((x) => {
                        switch (this) {
                        case T:
                                return T;
@@ -15,7 +15,7 @@ enum TE {
         });
        }
        public void g(int i) {
-               do_something<TE> ((x) => {
+               do_something<TEP> ((x) => {
                        switch (this) {
                        case T:
                                i++;
@@ -29,11 +29,11 @@ enum TE {
 
 class Test {
        public void f() {
-               do_something<TE> (g);
+               do_something<TEP> (g);
                do_something<int> (h);
        }
        [CCode (instance_pos = -1)]
-       private TE g(TE i) {
+       private TEP g(TEP i) {
                return i;
        }
        [CCode (instance_pos = -1)]
@@ -43,7 +43,7 @@ class Test {
 }
 
 int main() {
-       TE t = TE.T;
+       TEP t = TEP.T;
        t.f ();
        t.g (0);
        Test t2 = new Test ();
diff --git a/tests/valatests.vala b/tests/valatests.vala
new file mode 100644
index 0000000..a28a463
--- /dev/null
+++ b/tests/valatests.vala
@@ -0,0 +1,302 @@
+namespace Vala.Tests {
+       
+       /**
+        * Vala.TestFixture
+        * 
+        * Searchs all of the sub directories in the current directory for
+        * *.vala or *.test files, compiles and runs them.
+        * 
+        * If the test is a self contained application (has its own main entry
+        * point), it will compile and run it. The test is deemed succesful if
+        * it compiles and runs without error.
+        * 
+        * If the test is a collection of {@ref Valadate.TestCase}s then it
+        * compiles the test and runs it. The test results will be appeneded to
+        * the TestFixture's. Not yet implemented.
+        * 
+        * If the test is a .test file it will be parsed, the components
+        * assembled, compiled and run.  The test is deemed succesful if
+        * it compiles and runs without error.
+        * 
+        * The tests can be run against the system compiler or the one in the
+        * source tree. This can be used to verify if a patch or other change
+        * to the compiler either fixes a bug or causes a regression (or both)
+        */
+       
+       public class Fixture : Valadate.TestCase {
+               
+               private delegate void CommandCallback(Subprocess process, size_t err, string buffer);
+               
+               private SubprocessLauncher launcher =
+                       new SubprocessLauncher(GLib.SubprocessFlags.STDOUT_PIPE | 
GLib.SubprocessFlags.STDERR_PIPE);
+               
+               private const string VALAFLAGS = """--pkg gio-2.0 --pkg valadate
+                        --main main --save-temps --disable-warnings 
+                         -X -pie -X -fPIE -X -g -X -O0 -X -pipe -X -lm 
+                         -X -Wno-discarded-qualifiers -X -Wno-incompatible-pointer-types
+                         -X -Wno-deprecated-declarations -X -Werror=return-type
+                         -X -Werror=init-self -X -Werror=implicit -X -Werror=sequence-point
+                         -X -Werror=return-type -X -Werror=uninitialized -X -Werror=pointer-arith
+                         -X -Werror=int-to-pointer-cast -X -Werror=pointer-to-int-cast""";
+               
+               private const string GIRHEADER ="""
+                       <?xml version="1.0"?>
+                       <repository version="1.2"
+                                               xmlns="http://www.gtk.org/introspection/core/1.0";
+                                               xmlns:c="http://www.gtk.org/introspection/c/1.0";
+                                               xmlns:glib="http://www.gtk.org/introspection/glib/1.0";>
+                               <include name="GLib" version="2.0"/>
+                               <include name="GObject" version="2.0"/>
+                               <c:include name="test.h"/>
+                               <namespace name="Test"
+                                                        version="1.2"
+                                                        c:identifier-prefixes="Test"
+                                                        c:symbol-prefixes="test">
+                                       %s
+                               </namespace>
+                               </repository>
+               """;
+
+               private File testdir;
+               private File buildir;
+               private File vapidir;
+               private File valadatedir;
+               private File valac;
+               private File vapigen;
+               private File tempdir;
+
+               private string vapidirs;
+
+
+               public Fixture() {
+                       load_tests();
+               }
+
+               ~Fixture() {
+                       delete_tempdir();
+               }
+
+               private void load_tests() {
+                       try {
+                               testdir = File.new_for_path(GLib.Environment.get_current_dir());
+                               buildir = testdir.get_parent();
+                               vapidir = buildir.get_child("vapi");
+                               valadatedir = buildir.get_child("valadate");
+                               valac = buildir.get_child("compiler").get_child("valac");
+                               vapigen = buildir.get_child("vapigen").get_child("vapigen");
+                               tempdir = testdir.get_child(".tests");
+                               delete_tempdir();
+                               tempdir.make_directory();
+
+                               vapidirs = "--vapidir %s --vapidir %s".printf(vapidir.get_path(), 
valadatedir.get_path());
+
+                               launcher.set_cwd(tempdir.get_path());
+
+                               var enumerator = testdir.enumerate_children (FileAttribute.STANDARD_NAME, 0);
+                               FileInfo file_info;
+                               while ((file_info = enumerator.next_file ()) != null) {
+                                       if (file_info.get_file_type() == GLib.FileType.DIRECTORY) {
+                                               var subdir = testdir.get_child(file_info.get_name());
+                                               load_tests_from_dir(subdir);
+                                       }
+                               }
+                       } catch (Error e) {
+                               stderr.printf ("Error: %s\n", e.message);
+                       }
+               }
+
+               private void delete_tempdir() throws Error {
+                       if (tempdir == null || !tempdir.query_exists())
+                               return;
+                               
+                       var enumerator = tempdir.enumerate_children (FileAttribute.STANDARD_NAME, 0);
+                       FileInfo file_info;
+                       while ((file_info = enumerator.next_file ()) != null) {
+                               if (file_info.get_file_type() == GLib.FileType.REGULAR) {
+                                       var file = tempdir.get_child(file_info.get_name());
+                                       file.delete();
+                               }
+                       }
+                       tempdir.delete();
+               }
+
+               private void load_tests_from_dir(File directory) throws Error {
+                       var enumerator = directory.enumerate_children (FileAttribute.STANDARD_NAME, 0);
+                       FileInfo file_info;
+                       while ((file_info = enumerator.next_file ()) != null) {
+                               string fname = file_info.get_name();
+
+                               if (file_info.get_file_type() == GLib.FileType.DIRECTORY) {
+                                       load_tests_from_dir(directory.get_child(fname));
+                                       continue;
+                               }
+
+                               File testfile = directory.get_child(fname);
+                               string testname = 
testfile.get_basename().substring(0,testfile.get_basename().last_index_of("."));
+
+                               if(fname.has_suffix(".vala")) {
+                                       string command = "%s %s %s %s".printf(valac.get_path(), vapidirs, 
VALAFLAGS, testfile.get_path());
+                                       string binary = 
testfile.get_basename().substring(0,testfile.get_basename().last_index_of("."));
+
+                                       add_test(testname,
+                                        ()=> {
+                                               try {
+                                                       run_command(command);
+                                                       if(tempdir.get_child(binary).query_exists())
+                                                               run_command("./%s".printf(binary));
+                                                       else
+                                                               Test.fail();
+                                               } catch (Error e) {
+                                                       Test.fail();
+                                                       stdout.printf ("%s", e.message);
+                                               }});
+                                       continue;
+                               }
+                               
+                               if(fname.has_suffix(".test")) {
+                                       add_test(testname,
+                                        ()=> {
+                                               try {
+                                                       parse_test(testfile);
+                                               } catch (Error e) {
+                                                       Test.fail();
+                                                       stdout.printf ("%s", e.message);
+                                               }});
+                               }
+                       }
+               }
+
+               private void default_callback(Subprocess process, size_t err, string buffer) {
+                       if (err > 0) {
+                               Test.fail();
+                               stdout.printf ("%s", buffer);
+                               process.force_exit();
+                       }
+               }
+
+               private void run_command(string command, CommandCallback callback = default_callback) throws 
Error {
+                       string[] args;
+                       Shell.parse_argv(command, out args);
+
+                       var process = launcher.spawnv(args);
+                       var stderr_pipe = process.get_stderr_pipe();
+
+                       uint8 buffer[1028];
+                       var err = stderr_pipe.read(buffer);
+                       
+                       callback(process, err, (string)buffer);
+
+               }
+
+               private void parse_test(File testfile) throws Error {
+                       
+                       var stream = new DataInputStream(testfile.read());
+                       string testname = 
testfile.get_basename().substring(0,testfile.get_basename().last_index_of("."));
+                       
+                       string line = stream.read_line(null);
+                       
+                       string packages = "";
+                       
+                       if (line.has_prefix("Packages:")) {
+                               packages = line.split(":")[1];
+                               packages = string.joinv(" --pkg ", packages.split(" "));
+                               line = stream.read_line(null);
+                       }
+                       switch (line) {
+                               
+                               case "D-Bus":
+                                       var clientfile = tempdir.get_child(testname + ".client.vala");
+                                       var serverfile = tempdir.get_child(testname + ".server.vala");
+                                       var client = clientfile.create(FileCreateFlags.NONE);
+                                       var client_stream = new DataOutputStream (client);
+                                       var server = serverfile.create(FileCreateFlags.NONE);
+                                       var server_stream = new DataOutputStream (server);
+                                       
+                                       while ((line = stream.read_line (null)) != "Program: client") { }
+                                       
+                                       while ((line = stream.read_line (null)) != "Program: server") {
+                                               client_stream.put_string(line + "\n");
+                                       }
+
+                                       while ((line = stream.read_line (null)) != null) {
+                                               server_stream.put_string(line + "\n");
+                                       }
+
+                                       string command = "%s %s %s %s %s".printf(valac.get_path(), vapidirs, 
packages, VALAFLAGS, clientfile.get_path());
+                                       
+                                       run_command(command);
+
+                                       command = "%s %s %s %s %s".printf(valac.get_path(), vapidirs, 
packages, VALAFLAGS, serverfile.get_path());
+
+                                       run_command(command);
+
+                                       string binary = 
serverfile.get_basename().substring(0,serverfile.get_basename().last_index_of("."));
+
+                                       command = "./" + binary;
+
+                                       run_command(command);
+
+                                       break;
+
+                               case "GIR":
+
+                                       string gir = "";
+                                       string vapi = "/* %s.vapi generated by lt-vapigen, do not modify. 
*/\n\n".printf(testname);
+                                       vapi += "[CCode (cprefix = \"Test\", gir_namespace = \"Test\", 
gir_version = \"1.2\", lower_case_cprefix = \"test_\")]";
+                                       vapi += "\nnamespace Test {";
+
+                                       while ((line = stream.read_line (null)) != "Input:") { }
+
+                                       while ((line = stream.read_line (null)) != "Output:") {
+                                               gir += line + "\n";
+                                       }
+
+                                       stream.read_line (null);
+
+                                       while ((line = stream.read_line (null)) != null) {
+                                               if(line.length > 0)
+                                                       vapi += "\n\t" + line;
+                                       }
+
+                                       vapi += "\n}\n";
+
+                                       var girfile = tempdir.get_child(testname + ".gir");
+                                       var girstream = girfile.create(FileCreateFlags.NONE);
+                                       girstream.write(GIRHEADER.printf(gir).data);
+
+                                       string command = "%s %s --library %s %s".printf(vapigen.get_path(), 
vapidirs, testname, girfile.get_path());
+                               
+                                       run_command(command);
+
+                                       uint8[] contents;
+                                       File file = tempdir.get_child(testname+".vapi");
+                                       file.load_contents (null, out contents, null);
+
+                                       if(strcmp(vapi, (string)contents) != 0)
+                                               Test.fail();
+                               
+                                       break;
+
+                               case "Invalid Code":
+                                       
+                                       var invalidfile = tempdir.get_child(testname + ".vala");
+                                       var invalid_stream = new DataOutputStream 
(invalidfile.create(FileCreateFlags.NONE));
+
+                                       while ((line = stream.read_line (null)) != null) {
+                                               invalid_stream.put_string(line + "\n");
+                                       }
+
+                                       string command = "%s %s %s %s %s".printf(valac.get_path(), vapidirs, 
packages, VALAFLAGS, invalidfile.get_path());
+
+                                       run_command(command, (p,e,b) => {
+                                               if (e <= 0)
+                                                       Test.fail();
+                                       });
+                                       break;
+
+                               default :
+                                       break;
+                       }
+               }
+       }
+}
diff --git a/valadate/Makefile.am b/valadate/Makefile.am
new file mode 100644
index 0000000..829e268
--- /dev/null
+++ b/valadate/Makefile.am
@@ -0,0 +1,79 @@
+include $(top_srcdir)/Makefile.common
+
+
+lib_LTLIBRARIES = \
+       libvaladate.la
+       $(NULL)
+
+libvaladate_la_SOURCES = \
+       assembly.vala \
+       module.vala \
+       test.vala \
+       testcase.vala \
+       testexplorer.vala \
+       testfixture.vala \
+       testresult.vala \
+       testrunner.vala \
+       $(NULL)
+
+libvaladate_la_VALAFLAGS = \
+       --vapidir $(top_srcdir)/vapi \
+       --vapidir $(top_srcdir)/gee \
+       --vapidir $(top_srcdir)/vala \
+       --pkg gio-2.0 \
+       --pkg gmodule-2.0 \
+       --pkg vala \
+       --pkg gee \
+       --library valadate \
+       --vapi valadate.vapi \
+       -H valadate.h \
+       -g \
+       $(NULL)
+
+
+libvaladate_la_CFLAGS = \
+       $(GLIB_CFLAGS) \
+       $(GMODULE_CFLAGS) \
+       -I$(top_srcdir)/vala \
+       $(NULL)
+
+libvaladate_la_CPPFLAGS = \
+       $(GLIB_CPPFLAGS) \
+       $(GMODULE_CPPFLAGS) \
+       -I$(top_srcdir)/vala \
+       -I$(top_srcdir)/gee \
+       $(NULL)
+
+
+libvaladate_la_LDFLAGS = \
+       -export-dynamic \
+       -shared \
+       $(NULL)
+
+libvaladate_la_LIBADD = \
+       $(top_builddir)/vala/libvalacore.la \
+       $(COVERAGE_LIBS) \
+       $(GLIB_LIBS) \
+       $(GMODULE_LIBS) \
+       $(NULL)
+
+libvaladateincludedir = $(includedir)/vala@PACKAGE_SUFFIX@
+
+libvaladateinclude_HEADERS = \
+       valadate.h \
+       $(NULL)
+
+EXTRA_DIST = $(libvaladate_la_VALASOURCES) valadate.vapi valadate.vala.stamp
+
+CLEANFILES = \
+       $(libvaladate_la_SOURCES:.vala=.c) \
+       valadate.vapi \
+       valadate.h \
+       $(NULL)
+       
+
+MAINTAINERCLEANFILES = \
+       valadate.vapi \
+       valadate.h \
+       $(libvaladate_la_SOURCES:.vala=.c) \
+       $(NULL)
diff --git a/valadate/assembly.vala b/valadate/assembly.vala
new file mode 100644
index 0000000..e68e607
--- /dev/null
+++ b/valadate/assembly.vala
@@ -0,0 +1,24 @@
+/*
+ * Valadate - Unit testing library for GObject-based libraries.
+ * Copyright (C) 20016  Chris Daley <chebizarro gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ * 
+ * Authors:
+ *     Chris Daley <chebizarro gmail com>
+ */
+
+[CCode (gir_namespace = "Valadate", gir_version = "1.0")]
+namespace Valadate { }
diff --git a/valadate/module.vala b/valadate/module.vala
new file mode 100644
index 0000000..a4e9421
--- /dev/null
+++ b/valadate/module.vala
@@ -0,0 +1,58 @@
+/*
+ * Valadate - Unit testing library for GObject-based libraries.
+ * Copyright (C) 20016  Chris Daley <chebizarro gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Authors:
+ *     Chris Daley <chebizarro gmail com>
+ */
+
+namespace Valadate {
+
+       public class Module : Object {
+               
+               private string lib_path;
+               private GLib.Module module;
+
+               public Module (string libpath) {
+                       lib_path = libpath;
+               } 
+               
+               public void load_module() throws Error
+                       requires(lib_path != null)
+               {
+                       //if (!File.new_for_path(lib_path).query_exists())
+                               //throw new Error.MODULE("Module: %s does not exist", lib_path);
+                       
+                       module = GLib.Module.open (lib_path, ModuleFlags.BIND_LOCAL);
+                       //if (module == null)
+                               //throw new Error.MODULE(GLib.Module.error());
+                       module.make_resident();
+               }
+               
+               internal void* get_method(string method_name) throws Error {
+                       void* function;
+                       if(module.symbol (method_name, out function))
+                               if (function != null)
+                                       return function;
+                       //throw new Error.METHOD(GLib.Module.error());
+                       return null;
+               }
+
+               
+       }
+
+}
diff --git a/valadate/test.vala b/valadate/test.vala
new file mode 100644
index 0000000..e769737
--- /dev/null
+++ b/valadate/test.vala
@@ -0,0 +1,41 @@
+/*
+ * Valadate - Unit testing library for GObject-based libraries.
+ * Copyright (C) 20016  Chris Daley <chebizarro gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Authors:
+ *     Chris Daley <chebizarro gmail com>
+ */
+namespace Valadate {
+       
+       /**
+        * The Test interface is implemented by TestCase and TestSuite.
+        * It is the base interface for all runnable Tests.
+        */
+    public interface Test : Object {
+               /**
+                * Runs the Tests and collects the results in a TestResult 
+                *
+                * @param result the TestResult object used to store the results of the Test
+                */
+               public abstract TestResult run (TestResult? result = null);
+
+               public delegate void TestMethod ();
+
+
+    }
+
+}
diff --git a/valadate/testcase.vala b/valadate/testcase.vala
new file mode 100644
index 0000000..5a8f517
--- /dev/null
+++ b/valadate/testcase.vala
@@ -0,0 +1,204 @@
+/* 
+ * Valadate - Unit testing library for GObject-based libraries.
+ *
+ * testcase.vala
+ * Copyright (C) 2016 Chris Daley
+ * Copyright (C) 2009-2012 Julien Peeters
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Authors:
+ *     Chris Daley <chebizarro gmail com>
+ *     Julien Peeters <contact julienpeeters fr>
+ */
+
+namespace Valadate {
+       
+       public delegate void AsyncBegin(AsyncReadyCallback callback);
+       public delegate void AsyncFinish(AsyncResult result) throws GLib.Error;
+
+       
+       public abstract class TestCase : Object, Test, TestFixture {
+
+               public GLib.TestSuite _suite;
+
+               public GLib.TestSuite suite {
+                       get {
+                               if (_suite == null)
+                                       _suite = new GLib.TestSuite (this.name);
+                               return _suite;
+                       }
+               }
+
+               public string name {get;set;} 
+
+               private Adaptor[] adaptors = new Adaptor[0];
+
+               private HashTable<string, Adaptor> tests =
+                       new HashTable<string, Adaptor> (str_hash, str_equal);
+
+               
+               construct {
+                       name = this.get_type().name();
+               }
+
+               public void add_test (string name, owned Test.TestMethod test)
+                       requires (name.contains("/") != true)
+               {
+                       var adaptor = new Adaptor (name, (owned)test, this);
+                       this.adaptors += adaptor;
+
+                       this.tests.insert(name, adaptor);
+
+                       this.suite.add (new GLib.TestCase (adaptor.name,
+                                                                                          adaptor.set_up,
+                                                                                          adaptor.run,
+                                                                                          adaptor.tear_down 
));
+               }
+
+
+               public void add_async_test (
+                       string name,
+                       owned AsyncBegin async_begin,
+                       owned AsyncFinish async_finish,
+                       int timeout = 200)
+               {
+                       var adaptor = new Adaptor (name, () => { }, this);
+                       adaptor.is_async = true;
+                       adaptor.async_begin = (owned)async_begin;
+                       adaptor.async_finish = (owned)async_finish;
+                       adaptor.async_timeout = timeout;
+                       this.adaptors += adaptor;
+
+                       this.tests.insert(name, adaptor);
+
+                       this.suite.add (new GLib.TestCase (
+                               adaptor.name,
+                               adaptor.set_up,
+                               adaptor.run,
+                               adaptor.tear_down,
+                               sizeof(Adaptor)));
+
+               }
+
+
+               /**
+                * Runs the Tests and collects the results in a TestResult 
+                *
+                * @param result the TestResult object used to store the results of the Test
+                */
+               public virtual TestResult run(TestResult? result = null) {
+                       return result;
+               }
+
+               public virtual TestResult run_test(Test test, TestResult? result = null) {
+                       return result;
+               }
+
+               public virtual void set_up () {}
+
+               public virtual void tear_down () {}
+
+               private class Adaptor {
+                       [CCode (notify = false)]
+                       public string name { get; private set; }
+                       public int async_timeout { get; set; }
+
+                       private Test.TestMethod test;
+                       private TestCase test_case;
+
+                       public bool is_async = false;
+                       public AsyncBegin async_begin;
+                       public AsyncFinish async_finish;
+
+                       public Adaptor (string name,
+                                                       owned Test.TestMethod test,
+                                                       TestCase test_case) {
+                               this.name = name;
+                               this.test = (owned)test;
+                               this.test_case = test_case;
+                       }
+
+                       public void set_up (void* fixture) {
+                               GLib.set_printerr_handler (printerr_func_stack_trace);
+                               Log.set_default_handler (log_func_stack_trace);
+                               this.test_case.set_up ();
+                       }
+
+                       private static void printerr_func_stack_trace (string? text) {
+                               if (text == null || str_equal (text, ""))
+                                       return;
+
+                               stderr.printf (text);
+
+                               /* Print a stack trace since we've hit some major issue */
+                               GLib.on_error_stack_trace ("libtool --mode=execute gdb");
+                       }
+
+                       private void log_func_stack_trace (
+                               string? log_domain,
+                               LogLevelFlags log_levels,
+                               string message) {
+                               Log.default_handler (log_domain, log_levels, message);
+
+                               /* Print a stack trace for any message at the warning level or above */
+                               if ((log_levels & (
+                                       LogLevelFlags.LEVEL_WARNING |
+                                       LogLevelFlags.LEVEL_ERROR |
+                                       LogLevelFlags.LEVEL_CRITICAL)) != 0) {
+                                       GLib.on_error_stack_trace ("libtool --mode=execute gdb");
+                               }
+                       }
+
+                       public void run (void* fixture) {
+                               if (this.is_async) {
+                                       try     {
+                                               assert( wait_for_async (async_timeout, this.async_begin, 
this.async_finish) );
+                                       }
+                                       catch (GLib.Error err) {
+                                               message(@"Got exception while excuting asynchronous test: 
$(err.message)");
+                                               GLib.Test.fail();
+                                       }
+                               } else {
+                                       this.test();
+                               }
+                       }
+
+
+                       public void tear_down (void* fixture) {
+                               this.test_case.tear_down ();
+                       }
+                       
+                       public bool wait_for_async(int timeout, AsyncBegin async_function, AsyncFinish 
async_finish) throws GLib.Error {
+                               var loop = new MainLoop(MainContext.default(), true);
+                               AsyncResult? result = null;
+                               // Plan the async function
+                               async_function((o, r) => { result = r; loop.quit(); });
+                               // Plan timeout
+                               var t1 = Timeout.add(timeout, () => { loop.quit(); return false; });
+                               // Run the loop if it was not quit yet.
+                               if(loop.is_running())
+                                       loop.run();
+                               // Cancel timer
+                               Source.remove(t1);
+                               // Check the outcome
+                               if(result == null)
+                                       return false;
+                               async_finish(result);
+                               return true;
+                       }
+               }
+       }
+}
diff --git a/valadate/testexplorer.vala b/valadate/testexplorer.vala
new file mode 100644
index 0000000..97e76a9
--- /dev/null
+++ b/valadate/testexplorer.vala
@@ -0,0 +1,95 @@
+/*
+ * Valadate - Unit testing library for GObject-based libraries.
+ * Copyright (C) 20016  Chris Daley <chebizarro gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ * 
+ * Authors:
+ *     Chris Daley <chebizarro gmail com>
+ */
+ 
+namespace Valadate {
+       
+       internal class TestExplorer : Vala.CodeVisitor {
+               
+               private Vala.Class testcase;
+               private Test[] tests;
+               private TestCase current_test;
+               private weak Module module;
+
+               internal delegate void* Constructor(); 
+               internal delegate void TestMethod(TestCase self);
+               
+               public TestExplorer(Module module) {
+                       this.module = module;
+               }
+               
+               public Test[] get_tests() {
+                       return tests;
+               }
+               
+               public override void visit_class(Vala.Class class) {
+                       
+                       if (class.get_full_name() == "Valadate.TestCase") {
+                               testcase = class;
+                               return;
+                       }
+
+                       if (testcase != null &&
+                               class.is_subtype_of(testcase) &&
+                               class.is_abstract != true ) {
+
+                               string cname = Vala.Symbol.camel_case_to_lower_case(
+                                       class.default_construction_method.get_full_name().replace(".","_"));
+
+                               unowned Constructor meth = (Constructor)module.get_method(cname);
+                               current_test = meth() as TestCase;
+                               current_test.name = class.get_full_name().replace("."," ");
+                               
+                               foreach(var method in class.get_methods()) {
+                                       if( method.name.has_prefix("test_") &&
+                                               method.has_result != true &&
+                                               method.get_parameters().size == 0
+                                       ) {
+                                               unowned TestMethod testmethod = null;
+                                               string mname = Vala.Symbol.camel_case_to_lower_case(
+                                                       method.get_full_name()
+                                                       .replace(".","_")
+                                               );
+
+                                               testmethod = (TestMethod)module.get_method(mname);
+
+                                               if (testmethod != null)
+                                                       
current_test.add_test(method.name.substring(5).replace("_"," "), ()=> {testmethod(current_test); });
+
+                                               
+                                       }
+                               }
+
+                               tests += current_test;
+
+                               class.accept_children(this);
+
+                       }
+               }
+
+               public override void visit_namespace(Vala.Namespace ns) {
+                       ns.accept_children(this);
+               }
+               
+               
+       }
+       
+}
diff --git a/valadate/testfixture.vala b/valadate/testfixture.vala
new file mode 100644
index 0000000..6bcebd1
--- /dev/null
+++ b/valadate/testfixture.vala
@@ -0,0 +1,32 @@
+/*
+ * Valadate - Unit testing library for GObject-based libraries.
+ * Copyright (C) 20016  Chris Daley <chebizarro gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Authors:
+ *     Chris Daley <chebizarro gmail com>
+ */
+namespace Valadate {
+
+    public interface TestFixture : Object {
+
+               public abstract void set_up ();
+
+               public abstract void tear_down ();
+
+    }
+
+}
diff --git a/valadate/testresult.vala b/valadate/testresult.vala
new file mode 100644
index 0000000..e43c9fc
--- /dev/null
+++ b/valadate/testresult.vala
@@ -0,0 +1,38 @@
+/*
+ * Valadate - Unit testing library for GObject-based libraries.
+ * Copyright (C) 20016  Chris Daley <chebizarro gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Authors:
+ *     Chris Daley <chebizarro gmail com>
+ */
+namespace Valadate {
+
+    public interface TestResult : Object {
+
+               public abstract int error_count {get;internal set;}
+               public abstract int failure_count {get;internal set;}
+               public abstract int run_count {get;internal set;}
+
+               public abstract void add_error(Test test);
+
+               public abstract void add_failure(Test test);
+
+               public abstract void report();
+
+    }
+
+}
diff --git a/valadate/testrunner.vala b/valadate/testrunner.vala
new file mode 100644
index 0000000..53f064c
--- /dev/null
+++ b/valadate/testrunner.vala
@@ -0,0 +1,136 @@
+/*
+ * Valadate - Unit testing library for GObject-based libraries.
+ * Copyright (C) 20016  Chris Daley <chebizarro gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ * 
+ * Authors:
+ *     Chris Daley <chebizarro gmail com>
+ */
+
+namespace Valadate {
+
+       public errordomain RunError {
+               MODULE,
+               GIR,
+               TESTS,
+               METHOD
+       }
+
+
+       public class TestRunner : Object {
+
+               private Vala.CodeContext context;
+               private Module module;
+               private string path;
+               private Test[] _tests;
+               
+               public Test[] tests {
+                       get {
+                               return _tests;
+                       }
+               }
+
+               public TestRunner(string path) {
+                       this.path = path;
+               }
+
+               public void load() throws RunError {
+                       string girdir = Path.get_dirname(path).replace(".libs", "");
+                       
+                       string girname = Path.get_basename(path);
+                       if(girname.has_prefix("lt-"))
+                               girname = girname.substring(3);
+                       
+                       string girfile = girdir + GLib.Path.DIR_SEPARATOR_S + girname + ".vapi";
+                       
+                       try {
+                               module = new Module(path);
+                               module.load_module();
+                               load_test_plan(girfile);
+
+                       } catch (Error e) {
+                               throw new RunError.MODULE(e.message);
+                       }
+               }
+
+               internal void load_test_plan(string girpath) {
+                       if (!FileUtils.test (girpath, FileTest.EXISTS))
+                               return;
+                       
+                       context = new Vala.CodeContext ();
+                       Vala.CodeContext.push (context);
+
+                       context.report.enable_warnings = false;
+                       context.report.set_verbose_errors (false);
+                       context.verbose_mode = false;
+                       
+                       File currdir = File.new_for_path(GLib.Environment.get_current_dir());
+                       File valadatedir = currdir.get_parent().get_child("valadate");
+                       File vapidir = currdir.get_parent().get_child("vapi");
+                       
+                       context.vapi_directories = {valadatedir.get_path(), vapidir.get_path()};
+                       
+                       context.add_external_package ("glib-2.0");
+                       context.add_external_package ("gobject-2.0");
+                       context.add_external_package ("gio-2.0");
+                       context.add_external_package ("gmodule-2.0");
+                       context.add_external_package ("valadate");
+                       
+                       context.add_source_file (new Vala.SourceFile (context, Vala.SourceFileType.PACKAGE, 
girpath));
+                       
+                       var parser = new Vala.Parser ();
+                       parser.parse (context);
+                       
+                       context.check ();
+               
+                       var testexplorer = new TestExplorer(module);
+                       context.accept(testexplorer);
+                       _tests = testexplorer.get_tests();
+                       
+               }
+
+
+
+               public static int main (string[] args) {
+
+                       var runner = new TestRunner(args[0]);
+
+                       GLib.Test.init(ref args);
+
+                       try {
+                               runner.load();
+                       } catch (RunError err) {
+                               message(err.message);
+                               return -1;
+                       }
+
+                       foreach (Test test in runner.tests)
+                               GLib.TestSuite.get_root().add_suite(((TestCase)test).suite);
+
+                       GLib.Test.run ();
+                       
+                       runner = null;
+                       
+                       return 0;
+                       
+               }
+
+       
+       }
+
+
+
+}


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