[libsoup] tests: use TAP, and install the tests



commit c92ef5cf5fc71d6cd6c29c87a258561b8a525d2b
Author: Dan Winship <danw gnome org>
Date:   Wed Dec 11 19:55:50 2013 +0100

    tests: use TAP, and install the tests
    
    Import glib-tap.mk to run the tests in TAP mode, and to provide rules
    to install the tests.
    
    This required some restructuring of httpd.conf-related stuff in order
    to come up with a configuration that would work for all three cases
    (srcdir==buildir, srcdir!=builddir, and installed).

 .gitignore                 |    1 +
 Makefile.am                |    4 +-
 configure.ac               |    2 +
 glib-tap.mk                |  134 +++++++++
 m4/glibtests.m4            |   28 ++
 tap-driver.sh              |  652 ++++++++++++++++++++++++++++++++++++++++++++
 tap-test                   |    5 +
 tests/Makefile.am          |   46 ++-
 tests/forms-test.c         |    2 +-
 tests/httpd.conf.22.in     |   81 +++---
 tests/httpd.conf.24.in     |   82 +++---
 tests/no-ssl-test.c        |    3 +-
 tests/ntlm-test.c          |    8 +-
 tests/resource-test.c      |    2 +-
 tests/session-test.c       |    8 +-
 tests/ssl-test.c           |    7 +-
 tests/test-utils.c         |   80 ++++--
 tests/xmlrpc-server-test.c |    2 +-
 18 files changed, 1014 insertions(+), 133 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 293106c..674fad1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -60,6 +60,7 @@ stamp-h1
 tests/*.log
 tests/*.trs
 tests/*-test
+tests/*.test
 tests/date
 tests/header-parsing
 tests/httpd.conf
diff --git a/Makefile.am b/Makefile.am
index 66992d9..c8fa95c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,7 +9,9 @@ EXTRA_DIST =                            \
        libsoup-gnome-2.4.pc.in         \
        gtk-doc.make                    \
        libsoup-zip.in                  \
-       m4/introspection.m4             \
+       glib-tap.mk                     \
+       tap-driver.sh                   \
+       tap-test                        \
        Makefile.glib
 
 DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc --enable-introspection
diff --git a/configure.ac b/configure.ac
index f60744a..defe54b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,6 +88,8 @@ GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36"
 GLIB_MAKEFILE='$(top_srcdir)/Makefile.glib'
 AC_SUBST(GLIB_MAKEFILE)
 
+GLIB_TESTS
+
 PKG_CHECK_MODULES(XML, libxml-2.0)
 AC_SUBST(XML_CFLAGS)
 AC_SUBST(XML_LIBS)
diff --git a/glib-tap.mk b/glib-tap.mk
new file mode 100644
index 0000000..c97bf3f
--- /dev/null
+++ b/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)/tap-driver.sh
+LOG_COMPILER = $(top_srcdir)/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/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/tap-driver.sh b/tap-driver.sh
new file mode 100755
index 0000000..19aa531
--- /dev/null
+++ b/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/tap-test b/tap-test
new file mode 100755
index 0000000..481e333
--- /dev/null
+++ b/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/tests/Makefile.am b/tests/Makefile.am
index f7293b1..d9ede80 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,14 +1,14 @@
+include $(top_srcdir)/glib-tap.mk
+
 AM_CPPFLAGS =          \
        -I$(top_srcdir) \
-       -DSRCDIR=\""$(abs_srcdir)"\" \
-       -DBUILDDIR=\""$(builddir)"\" \
        $(GLIB_CFLAGS)
 
 LIBS =                 \
        $(top_builddir)/libsoup/libsoup-2.4.la \
        $(GLIB_LIBS)
 
-TESTS =                                \
+test_programs =                        \
        auth-test               \
        cache-test              \
        chunk-test              \
@@ -44,13 +44,18 @@ TESTS =                             \
        xmlrpc-server-test      \
        xmlrpc-test
 
-noinst_PROGRAMS =              \
+test_extra_programs =          \
        ntlm-test-helper        \
        $(TESTS)
 
-noinst_DATA = soup-tests.gresource
+test_data =                    \
+       index.txt               \
+       soup-tests.gresource    \
+       test-cert.pem           \
+       test-key.pem            \
+       xmlrpc-server.php
 
-noinst_LTLIBRARIES = libtest.la
+noinst_LTLIBRARIES += libtest.la
 
 libtest_la_SOURCES =   \
        test-utils.c    \
@@ -74,7 +79,11 @@ httpd.conf: $(httpd_conf_in)
            -e 's,[ ]APACHE_SSL_MODULE_DIR@,$(APACHE_SSL_MODULE_DIR),' \
            $< > $@ || rm -f $@
 
-BUILT_SOURCES = httpd.conf
+BUILT_SOURCES += httpd.conf
+test_data +=                   \
+       htdigest                \
+       htpasswd                \
+       httpd.conf
 endif
 
 RESOURCES = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies 
$(srcdir)/soup-tests.gresource.xml)
@@ -82,7 +91,7 @@ RESOURCES = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-d
 soup-tests.gresource: soup-tests.gresource.xml $(RESOURCES)
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $<
 
-EXTRA_DIST =                    \
+EXTRA_DIST +=                   \
        htdigest                 \
        htpasswd                 \
        httpd.conf.22.in         \
@@ -95,10 +104,9 @@ EXTRA_DIST =                         \
        xmlrpc-server.php        \
        $(RESOURCES)
 
-DISTCLEANFILES = soup-tests.gresource httpd.conf
+DISTCLEANFILES += soup-tests.gresource httpd.conf
 
-TESTS_ENVIRONMENT = \
-       SOUP_TESTS_IN_MAKE_CHECK=1
+TESTS_ENVIRONMENT += SOUP_TESTS_IN_MAKE_CHECK=1
 
 check: start-httpd
 
@@ -113,13 +121,21 @@ endif
 .PHONY: start-httpd kill-httpd
 
 start-httpd:
-if HAVE_APACHE
-       @$(APACHE_HTTPD) -d `pwd` -f httpd.conf -k start;
+if HAVE_APACHE_2_2
+       @$(APACHE_HTTPD) -d $(abs_srcdir) -c "PidFile `pwd`/httpd.pid" -f `pwd`/httpd.conf -k start;
+endif
+if HAVE_APACHE_2_4
+       @$(APACHE_HTTPD) -d $(abs_srcdir) -c "DefaultRuntimeDir `pwd`" -c "PidFile `pwd`/httpd.pid" -f 
`pwd`/httpd.conf -k start;
 endif
 
 kill-httpd:
-if HAVE_APACHE
+if HAVE_APACHE_2_2
+       @if [ -f httpd.pid ]; then \
+               $(APACHE_HTTPD) -d $(abs_srcdir) -c "PidFile `pwd`/httpd.pid" -f `pwd`/httpd.conf -k stop; \
+       fi
+endif
+if HAVE_APACHE_2_4
        @if [ -f httpd.pid ]; then \
-               $(APACHE_HTTPD) -d `pwd` -f httpd.conf -k stop; \
+               $(APACHE_HTTPD) -d $(abs_srcdir) -c "DefaultRuntimeDir `pwd`" -c "PidFile `pwd`/httpd.pid" -f 
`pwd`/httpd.conf -k stop; \
        fi
 endif
diff --git a/tests/forms-test.c b/tests/forms-test.c
index 7a843da..da71569 100644
--- a/tests/forms-test.c
+++ b/tests/forms-test.c
@@ -135,7 +135,7 @@ do_md5_test_curl (const char *uri, const char *file, const char *md5)
        g_free (file_arg);
 }
 
-#define MD5_TEST_FILE SRCDIR "/index.txt"
+#define MD5_TEST_FILE (g_test_get_filename (G_TEST_DIST, "index.txt", NULL))
 #define MD5_TEST_FILE_BASENAME "index.txt"
 #define MD5_TEST_FILE_MIME_TYPE "text/plain"
 
diff --git a/tests/httpd.conf.22.in b/tests/httpd.conf.22.in
index de0b75f..b912ca3 100644
--- a/tests/httpd.conf.22.in
+++ b/tests/httpd.conf.22.in
@@ -3,8 +3,7 @@
 ServerName 127.0.0.1
 Listen 127.0.0.1:47524
 
-PidFile @builddir@/httpd.pid
-DocumentRoot @srcdir@
+DocumentRoot .
 
 # The tests shut down apache with "graceful-stop", because that makes
 # it close its listening socket right away. But it seems to sometimes
@@ -83,7 +82,7 @@ Listen 127.0.0.1:47527
 
     AuthType Basic
     AuthName realm1
-    AuthUserFile @srcdir@/htpasswd
+    AuthUserFile ./htpasswd
     Require valid-user
   </Proxy>
 
@@ -94,7 +93,7 @@ Listen 127.0.0.1:47527
 
     AuthType Basic
     AuthName realm1
-    AuthUserFile @srcdir@/htpasswd
+    AuthUserFile ./htpasswd
     Require valid-user
   </Proxy>
 
@@ -124,7 +123,7 @@ Listen 127.0.0.1:47528
 
     AuthType Basic
     AuthName realm1
-    AuthUserFile @srcdir@/htpasswd
+    AuthUserFile ./htpasswd
     Require user no-such-user
   </Proxy>
 
@@ -135,7 +134,7 @@ Listen 127.0.0.1:47528
 
     AuthType Basic
     AuthName realm1
-    AuthUserFile @srcdir@/htpasswd
+    AuthUserFile ./htpasswd
     Require user no-such-user
   </Proxy>
 
@@ -154,89 +153,89 @@ Listen 127.0.0.1:47528
   <VirtualHost 127.0.0.1:47525>
     SSLEngine on
 
-    SSLCertificateFile @srcdir@/test-cert.pem
-    SSLCertificateKeyFile @srcdir@/test-key.pem
+    SSLCertificateFile ./test-cert.pem
+    SSLCertificateKeyFile ./test-key.pem
 
   </VirtualHost>
 </IfModule>
 
 
 # Basic auth tests
-Alias /Basic/realm1/realm2/realm1 @srcdir@
-Alias /Basic/realm1/realm2 @srcdir@
-Alias /Basic/realm1/subdir @srcdir@
-Alias /Basic/realm1/not @srcdir@
-Alias /Basic/realm1 @srcdir@
-Alias /Basic/realm12/subdir @srcdir@
-Alias /Basic/realm12 @srcdir@
-Alias /Basic/realm2 @srcdir@
-Alias /Basic/realm3 @srcdir@
-Alias /Basic @srcdir@
+Alias /Basic/realm1/realm2/realm1 .
+Alias /Basic/realm1/realm2 .
+Alias /Basic/realm1/subdir .
+Alias /Basic/realm1/not .
+Alias /Basic/realm1 .
+Alias /Basic/realm12/subdir .
+Alias /Basic/realm12 .
+Alias /Basic/realm2 .
+Alias /Basic/realm3 .
+Alias /Basic .
 
 <Location /Basic/realm1>
   AuthType Basic
   AuthName realm1
-  AuthUserFile @srcdir@/htpasswd
+  AuthUserFile ./htpasswd
   Require user user1
 </Location>
 
 <Location /Basic/realm1/not>
   AuthType Basic
   AuthName realm1
-  AuthUserFile @srcdir@/htpasswd
+  AuthUserFile ./htpasswd
   Require user user2
 </Location>
 
 <Location /Basic/realm12>
   AuthType Basic
   AuthName realm12
-  AuthUserFile @srcdir@/htpasswd
+  AuthUserFile ./htpasswd
   Require user user1 user2
 </Location>
 
 <Location /Basic/realm1/realm2>
   AuthType Basic
   AuthName realm2
-  AuthUserFile @srcdir@/htpasswd
+  AuthUserFile ./htpasswd
   Require user user2
 </Location>
 
 <Location /Basic/realm1/realm2/realm1>
   AuthType Basic
   AuthName realm1
-  AuthUserFile @srcdir@/htpasswd
+  AuthUserFile ./htpasswd
   Require user user1
 </Location>
 
 <Location /Basic/realm2>
   AuthType Basic
   AuthName realm2
-  AuthUserFile @srcdir@/htpasswd
+  AuthUserFile ./htpasswd
   Require user user2
 </Location>
 
 <Location /Basic/realm3>
   AuthType Basic
   AuthName realm3
-  AuthUserFile @srcdir@/htpasswd
+  AuthUserFile ./htpasswd
   Require user user3
 </Location>
 
 # Digest auth tests
-Alias /Digest/realm1/realm2/realm1 @srcdir@
-Alias /Digest/realm1/realm2 @srcdir@
-Alias /Digest/realm1/subdir @srcdir@
-Alias /Digest/realm1/expire @srcdir@
-Alias /Digest/realm1/not @srcdir@
-Alias /Digest/realm1 @srcdir@
-Alias /Digest/realm2 @srcdir@
-Alias /Digest/realm3 @srcdir@
-Alias /Digest @srcdir@
+Alias /Digest/realm1/realm2/realm1 .
+Alias /Digest/realm1/realm2 .
+Alias /Digest/realm1/subdir .
+Alias /Digest/realm1/expire .
+Alias /Digest/realm1/not .
+Alias /Digest/realm1 .
+Alias /Digest/realm2 .
+Alias /Digest/realm3 .
+Alias /Digest .
 
 <Location /Digest/realm1>
   AuthType Digest
   AuthName realm1
-  AuthUserFile @srcdir@/htdigest
+  AuthUserFile ./htdigest
   AuthDigestDomain /Digest/realm1 /Digest/realm1/realm2/realm1
   Require valid-user
 </Location>
@@ -244,7 +243,7 @@ Alias /Digest @srcdir@
 <Location /Digest/realm1/expire>
   AuthType Digest
   AuthName realm1
-  AuthUserFile @srcdir@/htdigest
+  AuthUserFile ./htdigest
   AuthDigestDomain /Digest/realm1 /Digest/realm1/realm2/realm1
   AuthDigestNonceLifetime 2
   Require valid-user
@@ -253,7 +252,7 @@ Alias /Digest @srcdir@
 <Location /Digest/realm1/not>
   AuthType Digest
   AuthName realm1
-  AuthUserFile @srcdir@/htdigest
+  AuthUserFile ./htdigest
   AuthDigestDomain /Digest/realm1 /Digest/realm1/realm2/realm1
   Require user user2
 </Location>
@@ -261,7 +260,7 @@ Alias /Digest @srcdir@
 <Location /Digest/realm1/realm2>
   AuthType Digest
   AuthName realm2
-  AuthUserFile @srcdir@/htdigest
+  AuthUserFile ./htdigest
   AuthDigestDomain /Digest/realm2 /Digest/realm1/realm2
   Require valid-user
 </Location>
@@ -269,7 +268,7 @@ Alias /Digest @srcdir@
 <Location /Digest/realm1/realm2/realm1>
   AuthType Digest
   AuthName realm1
-  AuthUserFile @srcdir@/htdigest
+  AuthUserFile ./htdigest
   AuthDigestDomain /Digest/realm1 /Digest/realm1/realm2/realm1
   Require valid-user
 </Location>
@@ -277,7 +276,7 @@ Alias /Digest @srcdir@
 <Location /Digest/realm2>
   AuthType Digest
   AuthName realm2
-  AuthUserFile @srcdir@/htdigest
+  AuthUserFile ./htdigest
   AuthDigestDomain /Digest/realm2 /Digest/realm1/realm2
   Require valid-user
 </Location>
@@ -285,7 +284,7 @@ Alias /Digest @srcdir@
 <Location /Digest/realm3>
   AuthType Digest
   AuthName realm3
-  AuthUserFile @srcdir@/htdigest
+  AuthUserFile ./htdigest
   AuthDigestDomain /Digest/realm3
   Require valid-user
   # test RFC2069-style Digest
diff --git a/tests/httpd.conf.24.in b/tests/httpd.conf.24.in
index 2407ad7..850b839 100644
--- a/tests/httpd.conf.24.in
+++ b/tests/httpd.conf.24.in
@@ -3,9 +3,7 @@
 ServerName 127.0.0.1
 Listen 127.0.0.1:47524
 
-PidFile @builddir@/httpd.pid
-DefaultRuntimeDir @builddir@
-DocumentRoot @srcdir@
+DocumentRoot .
 
 # The tests shut down apache with "graceful-stop", because that makes
 # it close its listening socket right away. But it seems to sometimes
@@ -80,7 +78,7 @@ Listen 127.0.0.1:47527
   <Proxy http://127.0.0.1:47524*>
     AuthType Basic
     AuthName realm1
-    AuthUserFile @srcdir@/htpasswd
+    AuthUserFile ./htpasswd
     Require valid-user
   </Proxy>
 
@@ -88,7 +86,7 @@ Listen 127.0.0.1:47527
   <Proxy 127.0.0.1:47525>
     AuthType Basic
     AuthName realm1
-    AuthUserFile @srcdir@/htpasswd
+    AuthUserFile ./htpasswd
     Require valid-user
   </Proxy>
 
@@ -113,7 +111,7 @@ Listen 127.0.0.1:47528
   <Proxy http://127.0.0.1:47524*>
     AuthType Basic
     AuthName realm1
-    AuthUserFile @srcdir@/htpasswd
+    AuthUserFile ./htpasswd
     Require user no-such-user
   </Proxy>
 
@@ -121,7 +119,7 @@ Listen 127.0.0.1:47528
   <Proxy 127.0.0.1:47525>
     AuthType Basic
     AuthName realm1
-    AuthUserFile @srcdir@/htpasswd
+    AuthUserFile ./htpasswd
     Require user no-such-user
   </Proxy>
 
@@ -139,89 +137,89 @@ Listen 127.0.0.1:47528
   <VirtualHost 127.0.0.1:47525>
     SSLEngine on
 
-    SSLCertificateFile @srcdir@/test-cert.pem
-    SSLCertificateKeyFile @srcdir@/test-key.pem
+    SSLCertificateFile ./test-cert.pem
+    SSLCertificateKeyFile ./test-key.pem
 
   </VirtualHost>
 </IfModule>
 
 
 # Basic auth tests
-Alias /Basic/realm1/realm2/realm1 @srcdir@
-Alias /Basic/realm1/realm2 @srcdir@
-Alias /Basic/realm1/subdir @srcdir@
-Alias /Basic/realm1/not @srcdir@
-Alias /Basic/realm1 @srcdir@
-Alias /Basic/realm12/subdir @srcdir@
-Alias /Basic/realm12 @srcdir@
-Alias /Basic/realm2 @srcdir@
-Alias /Basic/realm3 @srcdir@
-Alias /Basic @srcdir@
+Alias /Basic/realm1/realm2/realm1 .
+Alias /Basic/realm1/realm2 .
+Alias /Basic/realm1/subdir .
+Alias /Basic/realm1/not .
+Alias /Basic/realm1 .
+Alias /Basic/realm12/subdir .
+Alias /Basic/realm12 .
+Alias /Basic/realm2 .
+Alias /Basic/realm3 .
+Alias /Basic .
 
 <Location /Basic/realm1>
   AuthType Basic
   AuthName realm1
-  AuthUserFile @srcdir@/htpasswd
+  AuthUserFile ./htpasswd
   Require user user1
 </Location>
 
 <Location /Basic/realm1/not>
   AuthType Basic
   AuthName realm1
-  AuthUserFile @srcdir@/htpasswd
+  AuthUserFile ./htpasswd
   Require user user2
 </Location>
 
 <Location /Basic/realm12>
   AuthType Basic
   AuthName realm12
-  AuthUserFile @srcdir@/htpasswd
+  AuthUserFile ./htpasswd
   Require user user1 user2
 </Location>
 
 <Location /Basic/realm1/realm2>
   AuthType Basic
   AuthName realm2
-  AuthUserFile @srcdir@/htpasswd
+  AuthUserFile ./htpasswd
   Require user user2
 </Location>
 
 <Location /Basic/realm1/realm2/realm1>
   AuthType Basic
   AuthName realm1
-  AuthUserFile @srcdir@/htpasswd
+  AuthUserFile ./htpasswd
   Require user user1
 </Location>
 
 <Location /Basic/realm2>
   AuthType Basic
   AuthName realm2
-  AuthUserFile @srcdir@/htpasswd
+  AuthUserFile ./htpasswd
   Require user user2
 </Location>
 
 <Location /Basic/realm3>
   AuthType Basic
   AuthName realm3
-  AuthUserFile @srcdir@/htpasswd
+  AuthUserFile ./htpasswd
   Require user user3
 </Location>
 
 # Digest auth tests
-Alias /Digest/realm1/realm2/realm1 @srcdir@
-Alias /Digest/realm1/realm2 @srcdir@
-Alias /Digest/realm1/subdir @srcdir@
-Alias /Digest/realm1/expire @srcdir@
-Alias /Digest/realm1/not @srcdir@
-Alias /Digest/realm1 @srcdir@
-Alias /Digest/realm2 @srcdir@
-Alias /Digest/realm3 @srcdir@
-Alias /Digest @srcdir@
+Alias /Digest/realm1/realm2/realm1 .
+Alias /Digest/realm1/realm2 .
+Alias /Digest/realm1/subdir .
+Alias /Digest/realm1/expire .
+Alias /Digest/realm1/not .
+Alias /Digest/realm1 .
+Alias /Digest/realm2 .
+Alias /Digest/realm3 .
+Alias /Digest .
 
 <Location /Digest/realm1>
   AuthType Digest
   AuthName realm1
-  AuthUserFile @srcdir@/htdigest
+  AuthUserFile ./htdigest
   AuthDigestDomain /Digest/realm1 /Digest/realm1/realm2/realm1
   Require valid-user
 </Location>
@@ -229,7 +227,7 @@ Alias /Digest @srcdir@
 <Location /Digest/realm1/expire>
   AuthType Digest
   AuthName realm1
-  AuthUserFile @srcdir@/htdigest
+  AuthUserFile ./htdigest
   AuthDigestDomain /Digest/realm1 /Digest/realm1/realm2/realm1
   AuthDigestNonceLifetime 2
   Require valid-user
@@ -238,7 +236,7 @@ Alias /Digest @srcdir@
 <Location /Digest/realm1/not>
   AuthType Digest
   AuthName realm1
-  AuthUserFile @srcdir@/htdigest
+  AuthUserFile ./htdigest
   AuthDigestDomain /Digest/realm1 /Digest/realm1/realm2/realm1
   Require user user2
 </Location>
@@ -246,7 +244,7 @@ Alias /Digest @srcdir@
 <Location /Digest/realm1/realm2>
   AuthType Digest
   AuthName realm2
-  AuthUserFile @srcdir@/htdigest
+  AuthUserFile ./htdigest
   AuthDigestDomain /Digest/realm2 /Digest/realm1/realm2
   Require valid-user
 </Location>
@@ -254,7 +252,7 @@ Alias /Digest @srcdir@
 <Location /Digest/realm1/realm2/realm1>
   AuthType Digest
   AuthName realm1
-  AuthUserFile @srcdir@/htdigest
+  AuthUserFile ./htdigest
   AuthDigestDomain /Digest/realm1 /Digest/realm1/realm2/realm1
   Require valid-user
 </Location>
@@ -262,7 +260,7 @@ Alias /Digest @srcdir@
 <Location /Digest/realm2>
   AuthType Digest
   AuthName realm2
-  AuthUserFile @srcdir@/htdigest
+  AuthUserFile ./htdigest
   AuthDigestDomain /Digest/realm2 /Digest/realm1/realm2
   Require valid-user
 </Location>
@@ -270,7 +268,7 @@ Alias /Digest @srcdir@
 <Location /Digest/realm3>
   AuthType Digest
   AuthName realm3
-  AuthUserFile @srcdir@/htdigest
+  AuthUserFile ./htdigest
   AuthDigestDomain /Digest/realm3
   Require valid-user
   # test RFC2069-style Digest
diff --git a/tests/no-ssl-test.c b/tests/no-ssl-test.c
index 5944b91..feffa5b 100644
--- a/tests/no-ssl-test.c
+++ b/tests/no-ssl-test.c
@@ -76,7 +76,8 @@ do_session_property_tests (void)
        soup_test_assert (ca_file == NULL, "setting ssl-use-system-ca-file set ssl-ca-file");
 
        g_object_set (G_OBJECT (session),
-                     "ssl-ca-file", SRCDIR "/test-cert.pem",
+                     "ssl-ca-file",
+                     g_test_get_filename (G_TEST_DIST, "test-cert.pem", NULL),
                      NULL);
        g_object_get (G_OBJECT (session),
                      "ssl-use-system-ca-file", &use_system,
diff --git a/tests/ntlm-test.c b/tests/ntlm-test.c
index 3987927..0fa4b47 100644
--- a/tests/ntlm-test.c
+++ b/tests/ntlm-test.c
@@ -465,7 +465,9 @@ do_winbind_ntlm_test (gconstpointer data)
        /* Samba winbind /usr/bin/ntlm_auth helper support (via a
         * helper program that emulates its interface).
         */
-       g_setenv ("SOUP_NTLM_AUTH_DEBUG", BUILDDIR "/ntlm-test-helper", TRUE);
+       g_setenv ("SOUP_NTLM_AUTH_DEBUG",
+                 g_test_get_filename (G_TEST_BUILT, "ntlm-test-helper", NULL),
+                 TRUE);
        g_unsetenv ("SOUP_NTLM_AUTH_DEBUG_NOCREDS");
        do_ntlm_tests (uri, FALSE);
 }
@@ -479,7 +481,9 @@ do_fallback_ntlm_test (gconstpointer data)
         * no cached credentials (and thus we have to fall back to
         * libsoup's built-in NTLM support).
         */
-       g_setenv ("SOUP_NTLM_AUTH_DEBUG", BUILDDIR "/ntlm-test-helper", TRUE);
+       g_setenv ("SOUP_NTLM_AUTH_DEBUG",
+                 g_test_get_filename (G_TEST_BUILT, "ntlm-test-helper", NULL),
+                 TRUE);
        g_setenv ("SOUP_NTLM_AUTH_DEBUG_NOCREDS", "1", TRUE);
        do_ntlm_tests (uri, TRUE);
 }
diff --git a/tests/resource-test.c b/tests/resource-test.c
index 50d63ab..6fcb899 100644
--- a/tests/resource-test.c
+++ b/tests/resource-test.c
@@ -155,7 +155,7 @@ do_request_file_test (gconstpointer type)
        GFile *index;
        char *uri_string;
 
-       index = g_file_new_for_path (SRCDIR "/index.txt");
+       index = g_file_new_for_path (g_test_get_filename (G_TEST_DIST, "index.txt", NULL));
        uri_string = g_file_get_uri (index);
        g_object_unref (index);
 
diff --git a/tests/session-test.c b/tests/session-test.c
index a6ce2c4..21d97a8 100644
--- a/tests/session-test.c
+++ b/tests/session-test.c
@@ -333,7 +333,13 @@ do_property_tests (void)
         * so we can only do this test if we have a real TLS backend.
         */
        if (tls_available) {
-               tlsdb = g_tls_file_database_new (SRCDIR "/test-cert.pem", NULL);
+               GError *error = NULL;
+
+               tlsdb = g_tls_file_database_new (g_test_get_filename (G_TEST_DIST,
+                                                                     "test-cert.pem",
+                                                                     NULL), &error);
+               g_assert_no_error (error);
+
                session = g_object_new (SOUP_TYPE_SESSION,
                                        SOUP_SESSION_TLS_DATABASE, tlsdb,
                                        NULL);
diff --git a/tests/ssl-test.c b/tests/ssl-test.c
index 5ef4129..753a980 100644
--- a/tests/ssl-test.c
+++ b/tests/ssl-test.c
@@ -65,7 +65,10 @@ do_one_strict_test (SoupSession *session, const char *uri,
 
        g_object_set (G_OBJECT (session),
                      SOUP_SESSION_SSL_STRICT, strict,
-                     SOUP_SESSION_SSL_CA_FILE, with_ca_list ? SRCDIR "/test-cert.pem" : "/dev/null",
+                     SOUP_SESSION_SSL_CA_FILE,
+                     (with_ca_list ?
+                      g_test_get_filename (G_TEST_DIST, "/test-cert.pem", NULL) :
+                      "/dev/null"),
                      NULL);
        /* Close existing connections with old params */
        soup_session_abort (session);
@@ -184,7 +187,7 @@ do_session_property_tests (void)
 
        use_system_changed = tlsdb_changed = ca_file_changed = FALSE;
        g_object_set (G_OBJECT (session),
-                     "ssl-ca-file", SRCDIR "/test-cert.pem",
+                     "ssl-ca-file", g_test_get_filename (G_TEST_DIST, "/test-cert.pem", NULL),
                      NULL);
        g_object_get (G_OBJECT (session),
                      "ssl-use-system-ca-file", &use_system,
diff --git a/tests/test-utils.c b/tests/test-utils.c
index 3d2546f..1d0d775 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -91,9 +91,6 @@ test_init (int argc, char **argv, GOptionEntry *entries)
        }
        g_option_context_free (opts);
 
-       if (g_getenv ("SOUP_TESTS_IN_MAKE_CHECK"))
-               debug_level = G_MAXINT;
-
        /* Exit cleanly on ^C in case we're valgrinding. */
        signal (SIGINT, quit);
 
@@ -137,30 +134,52 @@ debug_printf (int level, const char *format, ...)
 static gboolean
 apache_cmd (const char *cmd)
 {
-       const char *argv[8];
-       char *cwd, *conf;
+       GPtrArray *argv;
+       char *server_root, *cwd, *pid_file;
+#ifdef HAVE_APACHE_2_4
+       char *default_runtime_dir;
+#endif
        int status;
        gboolean ok;
 
+       server_root = g_test_build_filename (G_TEST_BUILT, "", NULL);
+
        cwd = g_get_current_dir ();
-       conf = g_build_filename (cwd, "httpd.conf", NULL);
-
-       argv[0] = APACHE_HTTPD;
-       argv[1] = "-d";
-       argv[2] = cwd;
-       argv[3] = "-f";
-       argv[4] = conf;
-       argv[5] = "-k";
-       argv[6] = cmd;
-       argv[7] = NULL;
-
-       ok = g_spawn_sync (cwd, (char **)argv, NULL, 0, NULL, NULL,
+#ifdef HAVE_APACHE_2_4
+       default_runtime_dir = g_strdup_printf ("DefaultRuntimeDir %s", cwd);
+#endif
+       pid_file = g_strdup_printf ("PidFile %s/httpd.pid", cwd);
+
+       argv = g_ptr_array_new ();
+       g_ptr_array_add (argv, APACHE_HTTPD);
+       g_ptr_array_add (argv, "-d");
+       g_ptr_array_add (argv, server_root);
+       g_ptr_array_add (argv, "-f");
+       g_ptr_array_add (argv, "httpd.conf");
+
+#ifdef HAVE_APACHE_2_4
+       g_ptr_array_add (argv, "-c");
+       g_ptr_array_add (argv, default_runtime_dir);
+#endif
+       g_ptr_array_add (argv, "-c");
+       g_ptr_array_add (argv, pid_file);
+
+       g_ptr_array_add (argv, "-k");
+       g_ptr_array_add (argv, (char *)cmd);
+       g_ptr_array_add (argv, NULL);
+
+       ok = g_spawn_sync (cwd, (char **)argv->pdata, NULL, 0, NULL, NULL,
                           NULL, NULL, &status, NULL);
        if (ok)
                ok = (status == 0);
 
+       g_free (server_root);
        g_free (cwd);
-       g_free (conf);
+       g_free (pid_file);
+#ifdef HAVE_APACHE_2_4
+       g_free (default_runtime_dir);
+#endif
+       g_ptr_array_free (argv, TRUE);
 
        return ok;
 }
@@ -208,15 +227,18 @@ soup_test_session_new (GType type, ...)
        va_list args;
        const char *propname;
        SoupSession *session;
+       char *cafile;
 
        va_start (args, type);
        propname = va_arg (args, const char *);
        session = (SoupSession *)g_object_new_valist (type, propname, args);
        va_end (args);
 
+       cafile = g_test_build_filename (G_TEST_DIST, "test-cert.pem", NULL);
        g_object_set (G_OBJECT (session),
-                     SOUP_SESSION_SSL_CA_FILE, SRCDIR "/test-cert.pem",
+                     SOUP_SESSION_SSL_CA_FILE, cafile,
                      NULL);
+       g_free (cafile);
 
        if (http_debug_level && !logger) {
                SoupLoggerLogLevel level = MIN ((SoupLoggerLogLevel)http_debug_level, SOUP_LOGGER_LOG_BODY);
@@ -246,14 +268,14 @@ test_server_new (gboolean in_own_thread, gboolean ssl)
 {
        SoupServer *server;
        GMainContext *async_context;
-       const char *ssl_cert_file, *ssl_key_file;
+       char *ssl_cert_file, *ssl_key_file;
        SoupAddress *addr;
 
        async_context = in_own_thread ? g_main_context_new () : NULL;
 
        if (ssl) {
-               ssl_cert_file = SRCDIR "/test-cert.pem";
-               ssl_key_file = SRCDIR "/test-key.pem";
+               ssl_cert_file = g_test_build_filename (G_TEST_DIST, "test-cert.pem", NULL);
+               ssl_key_file = g_test_build_filename (G_TEST_DIST, "test-key.pem", NULL);
        } else
                ssl_cert_file = ssl_key_file = NULL;
 
@@ -268,6 +290,8 @@ test_server_new (gboolean in_own_thread, gboolean ssl)
        g_object_unref (addr);
        if (async_context)
                g_main_context_unref (async_context);
+       g_free (ssl_cert_file);
+       g_free (ssl_key_file);
 
        if (!server) {
                g_printerr ("Unable to create server\n");
@@ -522,17 +546,21 @@ soup_test_register_resources (void)
 {
        static gboolean registered = FALSE;
        GResource *resource;
+       char *path;
        GError *error = NULL;
 
        if (registered)
                return;
 
-       resource = g_resource_load ("soup-tests.gresource", &error);
+       path = g_test_build_filename (G_TEST_BUILT, "soup-tests.gresource", NULL);
+       resource = g_resource_load (path, &error);
        if (!resource) {
                g_printerr ("Could not load resource soup-tests.gresource: %s\n",
                            error->message);
                exit (1);
        }
+       g_free (path);
+
        g_resources_register (resource);
        g_resource_unref (resource);
 
@@ -565,15 +593,17 @@ SoupBuffer *
 soup_test_get_index (void)
 {
        if (!index_buffer) {
-               char *contents;
+               char *path, *contents;
                gsize length;
                GError *error = NULL;
 
-               if (!g_file_get_contents (SRCDIR "/index.txt", &contents, &length, &error)) {
+               path = g_test_build_filename (G_TEST_DIST, "index.txt", NULL);
+               if (!g_file_get_contents (path, &contents, &length, &error)) {
                        g_printerr ("Could not read index.txt: %s\n",
                                    error->message);
                        exit (1);
                }
+               g_free (path);
 
                index_buffer = soup_buffer_new (SOUP_MEMORY_TAKE, contents, length);
        }
diff --git a/tests/xmlrpc-server-test.c b/tests/xmlrpc-server-test.c
index a6f2d5f..89e6e8d 100644
--- a/tests/xmlrpc-server-test.c
+++ b/tests/xmlrpc-server-test.c
@@ -280,7 +280,7 @@ do_xmlrpc_tests (gconstpointer data)
        GError *error = NULL;
        GIOChannel *child_out;
 
-       argv[0] = "./xmlrpc-test";
+       argv[0] = (char *) g_test_get_filename (G_TEST_BUILT, "xmlrpc-test", NULL);
        argv[1] = "-S";
        argv[2] = "-U";
        argv[3] = soup_uri_to_string (uri, FALSE);


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