Rombobjörn

summaryrefslogtreecommitdiff
path: root/testsuite/run_tests
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/run_tests')
-rwxr-xr-xtestsuite/run_tests132
1 files changed, 132 insertions, 0 deletions
diff --git a/testsuite/run_tests b/testsuite/run_tests
new file mode 100755
index 0000000..06e9c4c
--- /dev/null
+++ b/testsuite/run_tests
@@ -0,0 +1,132 @@
+#!/bin/sh
+
+# Comfignat's testsuite
+# Copyright 2013 - 2014 B. Persson, Bjorn@Rombobeorn.se
+#
+# This material is provided as is, with absolutely no warranty expressed
+# or implied. Any use is at your own risk.
+#
+# Permission is hereby granted to use or copy this testsuite
+# for any purpose, provided the above notices are retained on all copies.
+# Permission to modify the code and to distribute modified code is granted,
+# provided the above notices are retained, and a notice that the code was
+# modified is included with the above copyright notice.
+
+
+# It is hoped that this program will work in any Posix-compliant shell.
+
+set -e
+
+# Get the command line parameters.
+outer_srcdir="$1"
+outer_builddir="$2"
+
+testsuitedir="${outer_srcdir}"/testsuite
+
+# Initialize counters.
+passed=0
+failed=0
+
+# The testcases should use their own build directories, not the one of the Make
+# process that invoked the testsuite.
+Comfignat_overriding_absolute_builddir=
+Comfignat_overriding_absolute_objdir=
+Comfignat_overriding_absolute_stagedir=
+
+# variables that the testcases need:
+export file_list # absolute pathname of list of expected files
+export srcdir # testcase's source directory relative to testrundir
+export builddir # testcase's build directory relative to testrundir
+export relative_builddir # testcase's build directory relative to srcdir
+export dirgpr="${testsuitedir}"/test_directories.gpr
+
+
+pass () {
+ # Report the current testcase as passed.
+ echo "${test_name}: PASSED"
+ passed=$((passed + 1))
+}
+
+
+fail () {
+ # Report the current testcase as failed.
+ # Parameters:
+ # 1: a message about what went wrong
+ # 2: the name of a file with details about the error
+ echo "${test_name}: FAILED"
+ echo "$1"
+ cat "$2"
+ echo
+ failed=$((failed + 1))
+}
+
+
+# Clean out any old test results.
+rm -Rf "${outer_builddir}"/testruns
+
+for source_directory in "${testsuitedir}"/sources/* ; do
+ for location_file in "${testsuitedir}"/locations/* ; do
+ for input_script in "${testsuitedir}"/inputs/* ; do
+
+ # Compose the name of the combined testcase.
+ test_name=$(basename "${source_directory}")+$(basename "${location_file}")+$(basename "${input_script}")
+ testrundir="${outer_builddir}"/testruns/"${test_name}"
+ file_list="${testrundir}"/files.expected
+ mkdir -p "${testrundir}"
+ cd "${testrundir}"
+
+ # Get the source and build directory names.
+ . "${location_file}"
+ mkdir -p "${srcdir}"
+ if [ "${relative_builddir}" != . ] ; then
+ echo "${builddir}" >>files.expected
+ fi
+
+ # Populate the source directory.
+ cp -RHp "${source_directory}"/* "${srcdir}"
+ cp -p "${outer_srcdir}"/comfignat.* "${srcdir}"
+ find "${srcdir}" >>files.expected
+
+ # Run the testcase in a child process.
+ # The child process first loads the function library and then runs the
+ # input script.
+ if sh -e -c ". ${testsuitedir}/library; . ${input_script}" >output 2>&1 ; then
+
+ # Check that the expected files and no others are present.
+ # Sort the list of expected files and remove duplicates.
+ LC_COLLATE=C sort -u -o files.expected files.expected
+ # List all files in the build directory except for the directory
+ # where intermediate files are suposed to be. List the files in the
+ # source directory separately if the directories are separate. Sort
+ # the combined list the same way as the list of expected files is
+ # sorted. Then compare the lists.
+ if ( find "${builddir}" | grep -v ^"${builddir}"/obj ; test "${relative_builddir}" != . && find "${srcdir}" ) | LC_COLLATE=C sort | diff files.expected - >files.diff ; then
+
+ # Check that the source files haven't been mangled.
+ cd "${source_directory}"
+ find . -type f ! -exec cmp -s "{}" "${testrundir}/${srcdir}/{}" \; -print >> "${testrundir}"/changed_sources
+ cd "${outer_srcdir}"
+ for file in comfignat.* ; do
+ if ! cmp -s ${file} "${testrundir}/${srcdir}/${file}" ; then
+ echo ${file} >> "${testrundir}"/changed_sources
+ fi
+ done
+ if [ -s "${testrundir}"/changed_sources ] ; then
+ fail "Changed soure files:" "${testrundir}"/changed_sources
+ else
+ pass
+ fi
+ else
+ fail "Difference from the list of expected files:" files.diff
+ fi
+ else
+ fail "Error code: $?" output
+ fi
+
+ done
+ done
+done
+
+echo
+echo "passed: ${passed}, failed: ${failed}"
+exit ${failed}