Rombobjörn

summaryrefslogtreecommitdiff
path: root/testsuite/run_tests
blob: 57364b31c65003348b5c0630cf8547b464a6e5e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh

# Comfignat's testsuite
# Copyright 2013 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"

# 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 library            # absolute pathname of function library
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

# function library for the testcases:
library="${outer_srcdir}"/testsuite/library

# Clean out any old test results.
rm -Rf "${outer_builddir}"/testruns

for source_directory in "${outer_srcdir}"/testsuite/sources/* ; do
   for location_file in "${outer_srcdir}"/testsuite/locations/* ; do
      for input_script in "${outer_srcdir}"/testsuite/inputs/* ; do

         # Compose the name of the combined test case.
         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 test.
         if sh -e "${input_script}" >output 2>&1 ; then

            # Check that the expected files and no others are present.
            LC_COLLATE=C sort -o files.expected files.expected
            if find "${srcdir}" "${builddir}" | 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
                  verdict=FAILED
               else
                  verdict=PASSED
               fi
            else
               verdict=FAILED
            fi
         else
            # The test returned an error code.
            verdict=FAILED
         fi

         if [ ${verdict} = PASSED ] ; then
            passed=$((passed + 1))
         else
            failed=$((failed + 1))
         fi
         echo "${test_name}: ${verdict}"
      done
   done
done

echo
echo "passed: ${passed}, failed: ${failed}"
exit ${failed}