Blame SOURCES/result-file.patch

e965a0
diff -u b/src/journal.sh b/src/journal.sh
e965a0
--- b/src/journal.sh
e965a0
+++ b/src/journal.sh
e965a0
@@ -115,12 +115,13 @@
e965a0
     export __INTERNAL_METAFILE_INDENT_LEVEL=0
e965a0
     __INTERNAL_PHASE_TYPE=()
e965a0
     __INTERNAL_PHASE_NAME=()
e965a0
-    export __INTERNAL_PRESISTENT_DATA="$BEAKERLIB_DIR/PersistentData"
e965a0
+    export __INTERNAL_PERSISTENT_DATA="$BEAKERLIB_DIR/PersistentData"
e965a0
+    export __INTERNAL_TEST_RESULTS="$BEAKERLIB_DIR/TestResults"
e965a0
     export __INTERNAL_JOURNAL_OPEN=''
e965a0
     __INTERNAL_PersistentDataLoad
e965a0
     export __INTERNAL_PHASES_FAILED=0
e965a0
     export __INTERNAL_PHASES_PASSED=0
e965a0
-    export __INTERNAL_PHASES_SKIPED=0
e965a0
+    export __INTERNAL_PHASES_SKIPPED=0
e965a0
     export __INTERNAL_PHASES_WORST_RESULT='PASS'
e965a0
     export __INTERNAL_TEST_STATE=0
e965a0
     __INTERNAL_PHASE_TXTLOG_START=()
e965a0
@@ -249,6 +250,7 @@
e965a0
 
e965a0
     echo "#End of metafile" >> $__INTERNAL_BEAKERLIB_METAFILE
e965a0
     __INTERNAL_JournalXMLCreate
e965a0
+    __INTERNAL_TestResultsSave
e965a0
 }
e965a0
 
e965a0
 
e965a0
@@ -346,11 +348,11 @@
e965a0
 
e965a0
 __INTERNAL_update_journal_txt() {
e965a0
   local textfile
e965a0
-  local duration=$(($__INTERNAL_TIMESTAMP - $__INTERNAL_STARTTIME))
e965a0
   local endtime
e965a0
+  __INTERNAL_DURATION=$(($__INTERNAL_TIMESTAMP - $__INTERNAL_STARTTIME))
e965a0
   printf -v endtime "%($__INTERNAL_TIMEFORMAT_LONG)T %s" $__INTERNAL_TIMESTAMP "(still running)"
e965a0
   [[ -n "$__INTERNAL_ENDTIME" ]] && printf -v endtime "%($__INTERNAL_TIMEFORMAT_LONG)T" $__INTERNAL_ENDTIME
e965a0
-  local sed_patterns="0,/    Test finished : /s/^(    Test finished : ).*\$/\1$endtime/;0,/    Test duration : /s/^(    Test duration : ).*\$/\1$duration seconds/"
e965a0
+  local sed_patterns="0,/    Test finished : /s/^(    Test finished : ).*\$/\1$endtime/;0,/    Test duration : /s/^(    Test duration : ).*\$/\1$__INTERNAL_DURATION seconds/"
e965a0
   for textfile in "$__INTERNAL_BEAKERLIB_JOURNAL_COLORED" "$__INTERNAL_BEAKERLIB_JOURNAL_TXT"; do
e965a0
     sed -r -i "$sed_patterns" "$textfile"
e965a0
   done
e965a0
@@ -439,6 +441,43 @@
e965a0
     return 0
e965a0
 }
e965a0
 
e965a0
+
e965a0
+# Creation of TestResults file
e965a0
+# Each line of the file contains TESTRESULT_VAR=$RESULT_VALUE
e965a0
+# so the file can be sourced afterwards
e965a0
+__INTERNAL_TestResultsSave(){
e965a0
+    # Set exit code of the test according to worst phase result
e965a0
+    case "$__INTERNAL_PHASES_WORST_RESULT" in
e965a0
+    PASS)
e965a0
+        __TESTRESULT_RESULT_ECODE="0"
e965a0
+        ;;
e965a0
+    WARN)
e965a0
+        __TESTRESULT_RESULT_ECODE="10"
e965a0
+        ;;
e965a0
+    FAIL)
e965a0
+        __TESTRESULT_RESULT_ECODE="20"
e965a0
+        ;;
e965a0
+    *)
e965a0
+        __TESTRESULT_RESULT_ECODE="30"
e965a0
+        ;;
e965a0
+    esac
e965a0
+
e965a0
+    cat > "$__INTERNAL_TEST_RESULTS" <
e965a0
+# This is a result file of the test in a 'sourceable' form.
e965a0
+# Description of individual variables can be found in beakerlib man page.
e965a0
+TESTRESULT_RESULT_STRING=$__INTERNAL_PHASES_WORST_RESULT
e965a0
+TESTRESULT_RESULT_ECODE=$__TESTRESULT_RESULT_ECODE
e965a0
+TESTRESULT_PHASES_PASSED=$__INTERNAL_PHASES_PASSED
e965a0
+TESTRESULT_PHASES_FAILED=$__INTERNAL_PHASES_FAILED
e965a0
+TESTRESULT_PHASES_SKIPPED=$__INTERNAL_PHASES_SKIPPED
e965a0
+TESTRESULT_ASSERTS_FAILED=$__INTERNAL_TEST_STATE
e965a0
+TESTRESULT_STARTTIME=$__INTERNAL_STARTTIME
e965a0
+TESTRESULT_ENDTIME=$__INTERNAL_ENDTIME
e965a0
+TESTRESULT_DURATION=$__INTERNAL_DURATION
e965a0
+TESTRESULT_BEAKERLIB_DIR=$BEAKERLIB_DIR
e965a0
+EOF
e965a0
+}
e965a0
+
e965a0
 # backward compatibility
e965a0
 rlCreateLogFromJournal(){
e965a0
     rlLogWarning "rlCreateLogFromJournal is obsoleted by rlJournalPrintText"
e965a0
@@ -891,29 +930,29 @@
e965a0
 }
e965a0
 
e965a0
 
e965a0
-# whenever any of the persistend variable is touched,
e965a0
+# whenever any of the persistent variable is touched,
e965a0
 # functions __INTERNAL_PersistentDataLoad and __INTERNAL_PersistentDataSave
e965a0
 # should be called before and after that respectively.
e965a0
 
e965a0
 __INTERNAL_PersistentDataSave() {
e965a0
-  cat > "$__INTERNAL_PRESISTENT_DATA" <
e965a0
+  cat > "$__INTERNAL_PERSISTENT_DATA" <
e965a0
 __INTERNAL_STARTTIME=$__INTERNAL_STARTTIME
e965a0
 __INTERNAL_TEST_STATE=$__INTERNAL_TEST_STATE
e965a0
 __INTERNAL_PHASES_PASSED=$__INTERNAL_PHASES_PASSED
e965a0
 __INTERNAL_PHASES_FAILED=$__INTERNAL_PHASES_FAILED
e965a0
-__INTERNAL_PHASES_SKIPED=$__INTERNAL_PHASES_SKIPED
e965a0
+__INTERNAL_PHASES_SKIPPED=$__INTERNAL_PHASES_SKIPPED
e965a0
 __INTERNAL_JOURNAL_OPEN=$__INTERNAL_JOURNAL_OPEN
e965a0
 __INTERNAL_PHASES_WORST_RESULT=$__INTERNAL_PHASES_WORST_RESULT
e965a0
 EOF
e965a0
-declare -p __INTERNAL_PHASE_FAILED >> $__INTERNAL_PRESISTENT_DATA
e965a0
-declare -p __INTERNAL_PHASE_PASSED >> $__INTERNAL_PRESISTENT_DATA
e965a0
-declare -p __INTERNAL_PHASE_STARTTIME >> $__INTERNAL_PRESISTENT_DATA
e965a0
-declare -p __INTERNAL_PHASE_TXTLOG_START >> $__INTERNAL_PRESISTENT_DATA
e965a0
-declare -p __INTERNAL_PHASE_METRICS >> $__INTERNAL_PRESISTENT_DATA
e965a0
+declare -p __INTERNAL_PHASE_FAILED >> $__INTERNAL_PERSISTENT_DATA
e965a0
+declare -p __INTERNAL_PHASE_PASSED >> $__INTERNAL_PERSISTENT_DATA
e965a0
+declare -p __INTERNAL_PHASE_STARTTIME >> $__INTERNAL_PERSISTENT_DATA
e965a0
+declare -p __INTERNAL_PHASE_TXTLOG_START >> $__INTERNAL_PERSISTENT_DATA
e965a0
+declare -p __INTERNAL_PHASE_METRICS >> $__INTERNAL_PERSISTENT_DATA
e965a0
 }
e965a0
 
e965a0
 __INTERNAL_PersistentDataLoad() {
e965a0
-  [[ -r "$__INTERNAL_PRESISTENT_DATA" ]] && . "$__INTERNAL_PRESISTENT_DATA"
e965a0
+  [[ -r "$__INTERNAL_PERSISTENT_DATA" ]] && . "$__INTERNAL_PERSISTENT_DATA"
e965a0
 }
e965a0
 
e965a0
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
e965a0
only in patch2:
e965a0
unchanged:
e965a0
--- a/src/beakerlib.sh
e965a0
+++ b/src/beakerlib.sh
e965a0
@@ -96,6 +96,48 @@ See the BKRDOC section for more information about Automated documentation genera
e965a0
 
e965a0
 =for comment beakerlib-manual-footer
e965a0
 
e965a0
+=head1 OUTPUT FILES
e965a0
+
e965a0
+Location of test results related output files can be configured by setting BEAKERLIB_DIR variable before running the test. If it is not set, temporary directory is created.
e965a0
+
e965a0
+=head2 journal.txt
e965a0
+
e965a0
+Journal in human readable form.
e965a0
+
e965a0
+=head2 journal.xml
e965a0
+
e965a0
+Journal in XML format, requires python. This dependency can be avoided if the test is run with variable BEAKERLIB_JOURNAL set to 0 in which case journal.xml is not created.
e965a0
+
e965a0
+=head3 XSLT
e965a0
+
e965a0
+XML journal can be transformed through XSLT template. Which template is used is configurable by setting BEAKERLIB_JOURNAL variable. Value can be either filename in which case beakerlib will try to use $INSTALL_DIR/xslt-template/$filename (e.g.: /usr/share/beakerlib/xstl-templates/xunit.xsl) or it can be path to a template anywhere on the system.
e965a0
+
e965a0
+=head2 TestResults
e965a0
+
e965a0
+Overall results of the test in a 'sourceable' form. Each line contains a pair VAR=VALUE. All variable names have 'TESTRESULT_' prefix.
e965a0
+
e965a0
+=head3 List of variables:
e965a0
+
e965a0
+TESTRESULT_RESULT_STRING - Result of the test in a string, e.g.: PASS, FAIL, WARN.
e965a0
+
e965a0
+TESTRESULT_RESULT_ECODE - Result of the test as an integer, 0 equals to PASS.
e965a0
+
e965a0
+TESTRESULT_PHASES_PASSED - Number of phases that ended with PASS.
e965a0
+
e965a0
+TESTRESULT_PHASES_FAILED - Number of phases that ended with non-PASS result.
e965a0
+
e965a0
+TESTRESULT_PHASES_SKIPPED - Number of skipped phases.
e965a0
+
e965a0
+TESTRESULT_ASSERTS_FAILED - Number of asserts that ended with non-PASS result in the whole test.
e965a0
+
e965a0
+TESTRESULT_STARTTIME - Time when test started in seconds since epoch.
e965a0
+
e965a0
+TESTRESULT_ENDTIME - Time when test ended in seconds since epoch.
e965a0
+
e965a0
+TESTRESULT_DURATION - Duration of the test run in seconds.
e965a0
+
e965a0
+TESTRESULT_BEAKERLIB_DIR - Directory with test results files.
e965a0
+
e965a0
 =head1 EXAMPLES
e965a0
 
e965a0
 =head2 Simple