Feature #8894

Test suite should be able to log to file too, without losing colors on the terminal

Added by intrigeri 2015-02-12 15:46:02 . Updated 2015-03-23 02:01:37 .

Status:
Resolved
Priority:
Low
Assignee:
Category:
Test suite
Target version:
Start date:
2015-02-12
Due date:
% Done:

100%

Feature Branch:
test/8894-log-file
Type of work:
Code
Blueprint:

Starter:
Affected tool:
Deliverable for:

Description

By default the test suite logs to the terminal, with fancy colors. Fine. I can also duplicate the output with tee so that I get a log file. However, if I do that, then I lose the nice colors and the output is harder to read. Dear test suite folks, how hard would it be to add a --log-file FILE option that sends a copy of the output to a file, without losing the fancy colored output on the terminal?


Subtasks


History

#1 Updated by anonym 2015-02-12 16:11:36

  • Assignee set to intrigeri
  • QA Check set to Info Needed

What about the following? I’m not sure it will log stderr (mostly relevant witht the --debug parameter), FWIW.

--- a/run_test_suite
+++ b/run_test_suite
@@ -103,6 +103,7 @@ capture_session() {
 # main script

 CAPTURE_FILE=
+CUCUMBER_OPTS=
 VNC_VIEWER=
 VNC_SERVER=
 DEBUG=
@@ -113,7 +114,7 @@ TEMP_DIR=
 ISO=
 OLD_ISO=

-LONGOPTS="view,vnc-server-only,capture:,help,temp-dir:,keep-snapshots,retry-find,iso:,old-iso:,debug,pause-on-fail"
+LONGOPTS="view,vnc-server-only,capture:,help,temp-dir:,keep-snapshots,retry-find,iso:,old-iso:,debug,pause-on-fail,log-to-file:"
 OPTS=$(getopt -o "" --longoptions $LONGOPTS -n "${NAME}" -- "$@")
 eval set -- "$OPTS"
 while [ $# -gt 0 ]; do
@@ -133,6 +134,10 @@ while [ $# -gt 0 ]; do
         --debug)
             export DEBUG="yes"
             ;;
+        --log-to-file)
+            shift
+            CUCUMBER_OPTS="${CUCUMBER_OPTS} --out ${1}"
+            ;;
         --pause-on-fail)
             export PAUSE_ON_FAIL="yes"
             ;;
@@ -189,8 +194,10 @@ export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
 export SIKULI_HOME="/usr/share/java"
 export DISPLAY=${TARGET_DISPLAY}
 check_dependency cucumber
-if [ -z "${*}" ]; then
-    cucumber --format ExtraHooks::Pretty features
-else
-    cucumber --format ExtraHooks::Pretty features/step_definitions features/support ${*}
+
+FEATURES="${@}"
+if [ -z "${FEATURES}" ]; then
+     FEATURES="features"
 fi
+
+cucumber --format ExtraHooks::Pretty ${CUCUMBER_OPTS} features/step_definitions features/support ${FEATURES}

#2 Updated by anonym 2015-02-12 16:28:44

I missed that you wanted it to log in addition to writing to the terminal. The following patch is better, and also captures stderr FWIW:

--- a/run_test_suite
+++ b/run_test_suite
@@ -103,6 +103,7 @@ capture_session() {
 # main script

 CAPTURE_FILE=
+LOG_FILE=
 VNC_VIEWER=
 VNC_SERVER=
 DEBUG=
@@ -113,7 +114,7 @@ TEMP_DIR=
 ISO=
 OLD_ISO=

-LONGOPTS="view,vnc-server-only,capture:,help,temp-dir:,keep-snapshots,retry-find,iso:,old-iso:,debug,pause-on-fail"
+LONGOPTS="view,vnc-server-only,capture:,help,temp-dir:,keep-snapshots,retry-find,iso:,old-iso:,debug,pause-on-fail,log-to-file:"
 OPTS=$(getopt -o "" --longoptions $LONGOPTS -n "${NAME}" -- "$@")
 eval set -- "$OPTS"
 while [ $# -gt 0 ]; do
@@ -130,6 +131,10 @@ while [ $# -gt 0 ]; do
             shift
             CAPTURE_FILE="$1"
             ;;
+        --log-to-file)
+            shift
+            LOG_FILE="${1}"
+            ;;
         --debug)
             export DEBUG="yes"
             ;;
@@ -189,8 +194,15 @@ export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
 export SIKULI_HOME="/usr/share/java"
 export DISPLAY=${TARGET_DISPLAY}
 check_dependency cucumber
-if [ -z "${*}" ]; then
-    cucumber --format ExtraHooks::Pretty features
+
+FEATURES="${@}"
+if [ -z "${FEATURES}" ]; then
+    FEATURES="features" 
+fi
+CUCUMBER_COMMAND="cucumber --format ExtraHooks::Pretty features/step_definitions features/support ${FEATURES}"
+
+if [ -n "${LOG_FILE}" ]; then
+    script -q ${LOG_FILE} -c "${CUCUMBER_COMMAND}" | cat
 else
-    cucumber --format ExtraHooks::Pretty features/step_definitions features/support ${*}
+    ${CUCUMBER_COMMAND}
 fi

#3 Updated by Tails 2015-02-13 09:55:44

  • Status changed from Confirmed to In Progress

Applied in changeset commit:e024b723cdef17250cbaf2b836528878eff372df.

#4 Updated by intrigeri 2015-02-13 10:04:21

  • Assignee changed from intrigeri to anonym
  • Target version set to Tails_1.3.2
  • % Done changed from 0 to 50
  • QA Check changed from Info Needed to Ready for QA
  • Feature Branch set to test/8894-log-file

OK, that was a good basis, thanks! I’ve fixed the remaining issues I could see (exit code, control chars). Seems to work fine for me.

#5 Updated by intrigeri 2015-02-13 10:06:54

  • Type of work changed from Research to Code

#6 Updated by kytv 2015-02-13 17:31:21

The --log-to-file option should be documented in the usage function, otherwise it looks good. More importantly it works well too. :)

#7 Updated by intrigeri 2015-02-13 18:29:31

> The --log-to-file option should be documented in the usage function,

Good catch, thanks! In such a case, don’t hesitate reassigning to the branch submitter, and resetting “QA Check” to “Dev needed”.

#8 Updated by intrigeri 2015-02-13 21:09:41

  • Assignee changed from anonym to intrigeri
  • QA Check changed from Ready for QA to Dev Needed

#9 Updated by intrigeri 2015-02-14 01:19:05

  • Assignee changed from intrigeri to anonym
  • QA Check changed from Dev Needed to Ready for QA

Addressed the problem found by kytv.

#10 Updated by Tails 2015-02-25 13:34:16

Applied in changeset commit:dff4791f2ff51d78e80686fc8520f29ac02ac0d0.

#11 Updated by Tails 2015-03-16 18:29:45

  • Status changed from In Progress to Fix committed
  • % Done changed from 50 to 100

Applied in changeset commit:c9bcf2c41b7524378087e58cff6e9ae6f28b3ac4.

#12 Updated by anonym 2015-03-16 18:31:05

  • Assignee deleted (anonym)
  • QA Check changed from Ready for QA to Pass

Looks good! Merged!

#13 Updated by BitingBird 2015-03-22 11:51:54

  • Target version changed from Tails_1.3.2 to Tails_1.3.1

#14 Updated by BitingBird 2015-03-23 02:01:37

  • Status changed from Fix committed to Resolved