From 9656d604846e3a67e6e045fca0e2a04e96e93e93 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Fri, 3 Oct 2014 09:14:36 +0200 Subject: library/run: structured output in xml Generate xml output easily parse-able by xsltproc. * lib.sh (dtf_resultxml_init, dtf_resultxml_finish, dtf_resultxml_cache, dtf_die): New functions. * run.sh: Include lib.sh globally. * run.sh (run): Reuse new lib api. * tasks/initdb_old/config.sh: Typo: use DTF_TEST_DESCRIPTION. --- lib.sh | 35 +++++++++++++++++++++++++++++++++++ run | 22 +++++++++++++++++++++- tasks/initdb_old/config.sh | 2 +- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/lib.sh b/lib.sh index f86255b..a0ba819 100644 --- a/lib.sh +++ b/lib.sh @@ -3,6 +3,8 @@ . `dirname $BASH_SOURCE`/lib_pgsql.sh +dtf_die() { echo >&2 "$@"; exit 1; } + dtf_generate_results_tarball() { local dir=$(dirname $1) @@ -19,3 +21,36 @@ dtf_generate_results_tarball() export DTF_RESULT_TARBALL=$tarball } + +dtf_resultxml_cache() +{ + ___dtf_resultxml_cache+="$@ +" +} + +dtf_resultxml_init() +{ + ___dtf_resultxml_cache="" + ___dtf_resultxml_file="$1" + dtf_resultxml_cache "`date --rfc-3339=seconds`" + + if test ! -f "$___dtf_resultxml_file"; then + echo '' > "$___dtf_resultxml_file" \ + || dtf_die "can not create '$___dtf_resultxml_file'" + fi +} + +dtf_resultxml_task_result() +{ + local id="$1" + local desc="$2" + local result="$3" +} + +dtf_resultxml_finish() +{ + dtf_resultxml_cache "" + + echo "$___dtf_resultxml_cache" >> "$___dtf_resultxml_file" \ + || dtf_die "can not write to $___dtf_resultxml_file" +} diff --git a/run b/run index ae97a5b..f4d8444 100755 --- a/run +++ b/run @@ -6,11 +6,15 @@ export dtf_resultdir=${dtf_resultdir_override-/var/tmp/dtf} export dtf_srcdir=$(dirname $(readlink -f ${BASH_SOURCE[0]})) export dtf_testdir=${dtf_testdir-$dtf_srcdir} +export dtf_resultxml_file=/var/tmp/dtf.xml + export dtf_option_verbose=0 export dtf_option_force=0 export dtf_option_testids="" export dtf_option_listonly=0 +. $dtf_srcdir/lib.sh + ## F.DEFS ## info() @@ -32,6 +36,15 @@ run() export dtf_workdir=$1 export dtf_test_id=`basename $dtf_workdir` + dtf_resultxml_cache "$( cd $dtf_workdir + . ./config.sh + echo "" + echo "$DTF_TEST_ID" + echo "" + echo "$DTF_TEST_DESCRIPTION" + echo "" + )" + ( cd $dtf_workdir outlog="$dtf_resultdir/$dtf_test_id.log" @@ -41,7 +54,8 @@ run() && output_wrapper="tee $outlog" test ! -e ./config.sh -o ! -e ./config.sh \ - && echo "can not find one of {config,runtest}.sh" + && echo "can not find one of {config,runtest}.sh" \ + && exit 1 . ./config.sh @@ -142,10 +156,16 @@ done test $dtf_option_listonly -ne 1 && prepare_resultdir +dtf_resultxml_init "$dtf_resultxml_file" result=0 for i in `find $dtf_testdir -name runtest.sh`; do testdir=`dirname $i` run $testdir || result=1 + + test $result -eq 0 \ + && dtf_resultxml_cache "Success" \ + || dtf_resultxml_cache "Fail" done +dtf_resultxml_finish exit $result diff --git a/tasks/initdb_old/config.sh b/tasks/initdb_old/config.sh index f04f7ba..2386677 100644 --- a/tasks/initdb_old/config.sh +++ b/tasks/initdb_old/config.sh @@ -1,4 +1,4 @@ DTF_TEST_ID="initdb-old-syntax" -DESCRIPTION="\ +DTF_TEST_DESCRIPTION="\ Check that the old syntax 'postgresql-setup initdb' works together with following 'service start postgresql'." -- cgit