From 501f9888bff97d68adff2bfde0da7869c04d7e79 Mon Sep 17 00:00:00 2001 From: Björn Persson Date: Thu, 19 Dec 2013 01:02:34 +0100 Subject: some code to check files after tests --- testsuite/inputs/clean | 1 + testsuite/inputs/default_build | 1 + testsuite/library | 9 +++++++ testsuite/run_tests | 56 +++++++++++++++++++++++++++++++++++++++--- 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/testsuite/inputs/clean b/testsuite/inputs/clean index 6defe0e..8f443d5 100644 --- a/testsuite/inputs/clean +++ b/testsuite/inputs/clean @@ -1,4 +1,5 @@ . "${library}" common_setup +expect_configuration make make clean diff --git a/testsuite/inputs/default_build b/testsuite/inputs/default_build index 1706516..cd85823 100644 --- a/testsuite/inputs/default_build +++ b/testsuite/inputs/default_build @@ -1,3 +1,4 @@ . "${library}" common_setup +expect_configuration make diff --git a/testsuite/library b/testsuite/library index 1302625..2d16973 100644 --- a/testsuite/library +++ b/testsuite/library @@ -17,9 +17,18 @@ common_setup () { # build directory, just go to that directory. cd "${srcdir}" if [ "${relative_builddir}" != . ] ; then + echo "${builddir}"/Makefile >>"${file_list}" make configure builddir="${relative_builddir}" cd "${relative_builddir}" fi } +expect_configuration () { + # If "always" is passed, the testcase is always expected to leave a + # configuration file. If this is called without "always", a configuration + # file is expected only in a separate build directory. + if [ "$1" = always -o "${relative_builddir}" != . ] ; then + echo "${builddir}"/comfignat_configuration.mk >>"${file_list}" + fi +} diff --git a/testsuite/run_tests b/testsuite/run_tests index c559814..57364b3 100755 --- a/testsuite/run_tests +++ b/testsuite/run_tests @@ -17,40 +17,88 @@ 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 srcdir builddir relative_builddir +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}" "${builddir}" + 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 - verdict=PASSED - passed=$((passed + 1)) + + # 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}" -- cgit v1.2.3