Skip to content

Commit d2c2581

Browse files
committed
Flag for live logging
1 parent 48209a0 commit d2c2581

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ addons:
1818
script:
1919
- mkdir tests
2020
- cd tests
21-
- ../src/test/tpkg/run-one.sh 400-static-analysis
21+
# - ../src/test/tpkg/run-all.sh
22+
- ../src/test/tpkg/run-one.sh 400-static-analysis -V

src/test/tpkg/tpkg

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ TPKG_BASE="."
1313
TPKG_ARGS=""
1414
TPKG_CURRENT=`pwd`
1515
TPKG_QUIET=0 # only output err() msgs
16+
TPKG_VERBOSE=0 # Show live output of test execution
1617
TPKG_KEEP=0 # tpkg create doesn't remove dir/
1718
TPKG_PASS=0 # how much must succeed
1819
TPKG_LOG=0 # don't log
@@ -73,6 +74,14 @@ function out() {
7374
fi
7475
}
7576

77+
function write_result() {
78+
if [[ $TPKG_VERBOSE -gt 0 ]]; then
79+
tee -a $1
80+
else
81+
cat >> $1
82+
fi
83+
}
84+
7685
function epoch() {
7786
# make this sorta portable allthough not needed now
7887
epoch=0
@@ -89,9 +98,9 @@ function epoch() {
8998
function post() {
9099
if [ -f "${dsc_post}" ]; then
91100
err "[log] Executing post script: ${dsc_post} ${TPKG_ARGS}"
92-
echo "--------- Start Post Output ------------------ " | tee -a result.$dsc_basename
93-
${SHELL} ${dsc_post} ${TPKG_ARGS} | tee -a result.$dsc_basename
94-
echo "----------- End Post Output ------------------ " | tee -a result.$dsc_basename
101+
echo "--------- Start Post Output ------------------ " | write_result result.$dsc_basename
102+
${SHELL} ${dsc_post} ${TPKG_ARGS} | write_result result.$dsc_basename
103+
echo "----------- End Post Output ------------------ " | write_result result.$dsc_basename
95104
result=$?
96105
if [ $result -ne 0 ]; then
97106
err "[warning] Post-script executed with errors: $result."
@@ -102,9 +111,9 @@ function post() {
102111
function pre() {
103112
if [ -f "${dsc_pre}" ]; then
104113
err "[log] Executing pre script: ${dsc_pre} ${TPKG_ARGS}"
105-
echo "--------- Start Pre Output ------------------- " | tee -a result.$dsc_basename
106-
${SHELL} ${dsc_pre} ${TPKG_ARGS} | tee -a result.$dsc_basename
107-
echo "----------- End Pre Output ------------------- " | tee -a result.$dsc_basename
114+
echo "--------- Start Pre Output ------------------- " | write_result result.$dsc_basename
115+
${SHELL} ${dsc_pre} ${TPKG_ARGS} | write_result result.$dsc_basename
116+
echo "----------- End Pre Output ------------------- " | write_result result.$dsc_basename
108117
result=$?
109118
if [ $result -ne 0 ]; then
110119
err "[warning] Pre-script executed with errors: $result."
@@ -179,6 +188,7 @@ function usage() {
179188
out " -h\t\tshow this help"
180189
out " -v\t\tshow version"
181190
out " -q\t\tonly print errors"
191+
out " -V\t\tshow live output when executing tests"
182192
out " -l\t\tlog test name to syslog when starting the test (using logger)"
183193
out " -p PRI\tlog using PRI as priority"
184194
out " -k\t\tdon't remove test directory when creating/executing a tpkg package"
@@ -407,7 +417,7 @@ function extract_tpkg_to { # <dir>
407417

408418
### MAIN
409419
# check the arguments
410-
while getopts ":vhkqb:a:n:lp:df" o
420+
while getopts ":vhkqVb:a:n:lp:df" o
411421
do case "$o" in
412422
b) TPKG_BASE="$OPTARG";;
413423
h) usage; exit 0;;
@@ -422,6 +432,7 @@ do case "$o" in
422432
fi
423433
;;
424434
q) TPKG_QUIET=1;;
435+
V) TPKG_VERBOSE=`expr $TPKG_VERBOSE + 1`;;
425436
k) TPKG_KEEP=1;;
426437
n) TPKG_PASS=$OPTARG
427438
if [ $TPKG_PASS -eq 0 ]; then
@@ -838,16 +849,17 @@ fi
838849
tpkg_log "Starting test: '$dsc_basename'"
839850

840851
epoch # run before pre()
841-
echo "BaseName: $dsc_basename" | tee result.$dsc_basename
842-
echo "Description: $dsc_description" | tee -a result.$dsc_basename
843-
echo "DateRunStart: $epoch " | tee -a result.$dsc_basename
844-
echo "--------------- Test Output ------------------" | tee -a result.$dsc_basename
852+
: > result.$dsc_basename
853+
echo "BaseName: $dsc_basename" | write_result result.$dsc_basename
854+
echo "Description: $dsc_description" | write_result result.$dsc_basename
855+
echo "DateRunStart: $epoch " | write_result result.$dsc_basename
856+
echo "--------------- Test Output ------------------" | write_result result.$dsc_basename
845857

846858
pre
847859

848860
out "[log] Executing test"
849861

850-
( ${SHELL} $dsc_test ${TPKG_ARGS} 2>&1 ) | tee -a result.$dsc_basename
862+
( ${SHELL} $dsc_test ${TPKG_ARGS} 2>&1 ) | write_result result.$dsc_basename
851863
test_result=$?
852864
epoch # would like to run after post, but that is not possible :-(
853865
if [ $test_result -ne 0 ]; then

0 commit comments

Comments
 (0)