[Asterisk-code-review] pretty print: Fix pass/fail parsing and column width (testsuite[15.5])

George Joseph asteriskteam at digium.com
Thu Jul 12 06:20:57 CDT 2018


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/9403 )

Change subject: pretty_print:  Fix pass/fail parsing and column width
......................................................................

pretty_print:  Fix pass/fail parsing and column width

Fixed the parsing ot the test result line so it accepts both old and
new style results.

Fixed calculation of column width when there is no TERM.  It now
defaults to 80 if the --term-width argument wasn't specified.

Now setting -no-color and --no-timer if TERM isn't set.

Change-Id: I7dc1d02f43ca1c115821e0096159585ab6dcd43e
---
M contrib/scripts/pretty_print
1 file changed, 21 insertions(+), 10 deletions(-)

Approvals:
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/contrib/scripts/pretty_print b/contrib/scripts/pretty_print
index 8ee22d8..b50f87d 100755
--- a/contrib/scripts/pretty_print
+++ b/contrib/scripts/pretty_print
@@ -27,9 +27,11 @@
 
 SHOW_ERRORS=0
 VERBOSE=0
-TERM_WIDTH=$(tput cols)
 NO_COLOR=0
 NO_TIMER=0
+TERM_WIDTH=0
+declare -ix test_timeout=0
+
 for a in "$@" ; do
 	OPTION_COUNT+=1
 	case "$a" in
@@ -51,7 +53,16 @@
 	esac
 done
 
-declare -ix test_timeout=0
+if [ x"$TERM" = x ] ; then
+	NO_TIMER=1
+	NO_COLOR=1
+	if [ $TERM_WIDTH -le 0 ] ; then
+		TERM_WIDTH=80
+	fi
+else
+	TERM_WIDTH=$(tput cols)
+fi
+
 
 if [ $NO_COLOR -gt 0 ] ; then
 	YELLOW=''
@@ -87,7 +98,7 @@
 	done
 }
 
-echo -e -n "Calculating...\r"
+echo -e "Calculating..."
 declare -i run=0
 declare -i runs=0
 declare -ix runnable=0
@@ -120,9 +131,9 @@
 	if [[ $run -eq 1 && $line =~ ^Tests\ to\ run:\ +([0-9]+)\ +\*\ +([0-9]+)\ +time\(s\)\ +=\ +([0-9]+)\ +Maximum.test.inactivity.time:.([-0-9-]+) ]] ; then
 		runnable=$(( ${BASH_REMATCH[1]} * $runs ))
 		export test_timeout=${BASH_REMATCH[4]}
-		printf "=%.0s" $(seq 1 ${TERM_WIDTH:-$(tput cols)}) ; echo
+		printf "=%.0s" $(seq 1 ${TERM_WIDTH}) ; echo
 		echo "${line/-1/unlimited}"
-		col=$(( ${TERM_WIDTH:-$(tput cols)} - ${#status_string} ))
+		col=$(( ${TERM_WIDTH} - ${#status_string} ))
 		printf "%-*.*s[%-12s][%s][${GREEN}%4s${NORM}][${RED}%4s${NORM}]\n" $col $col "Test" "  Test" "Status" "Pass" "Fail"
 	fi
 
@@ -130,7 +141,7 @@
 		unset buffer
 		declare -a buffer
 		(( tests++ ))
-		col=$(( ${TERM_WIDTH:-$(tput cols)} - ${#status_string} -1 ))
+		col=$(( ${TERM_WIDTH} - ${#status_string} -1 ))
 		testname=${BASH_REMATCH[1]#*/}
 		tnl=$(( ${#testname} - $col ))
 		[ $tnl -le 0 ] && tnl=0
@@ -145,11 +156,11 @@
 		fi
 	fi
 
-	if [[ $line =~ ^Test\ *\[(\'[^\']+\',)?\ *\'tests/([^\']+)\'(, \'[^\']+\')?\]\ *(passed|failed|timed\ out)$ ]] ; then
+	if [[ $line =~ ^Test\ *(\[\'[^\']+\',\ \')?tests/([^\' ]+)(\', \'[^\']+\'\])?\ *(passed|failed|timed\ out)$ ]] ; then
 		test=${BASH_REMATCH[2]}
 		_unused_arg=${BASH_REMATCH[3]}
 		status=${BASH_REMATCH[4]}
-		col=$(( ${TERM_WIDTH:-$(tput cols)} - ${#status_string} ))
+		col=$(( ${TERM_WIDTH} - ${#status_string} ))
 		et=$(( $SECONDS - $st ))
 		[ $countpid -gt 0 ] && kill $countpid
 		show=0
@@ -198,9 +209,9 @@
 
 elapsed=$(( $SECONDS - $starttime ))
 time="$(( $elapsed / 60 ))m $(( $elapsed % 60 ))s"
-printf "+%.0s" $(seq 1 ${TERM_WIDTH:-$(tput cols)}) ; echo
+printf "+%.0s" $(seq 1 ${TERM_WIDTH}) ; echo
 echo -e "Tests: $runnable   ${GREEN}Passed: $passed   ${RED}Failed: $failed   TimedOut: $timedout${NORM}   Time: $time\tLongest test: ${maxelapsed}s"
-printf "=%.0s" $(seq 1 ${TERM_WIDTH:-$(tput cols)}) ; echo
+printf "=%.0s" $(seq 1 ${TERM_WIDTH}) ; echo
 
 trap - INT ERR
 

-- 
To view, visit https://gerrit.asterisk.org/9403
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: 15.5
Gerrit-MessageType: merged
Gerrit-Change-Id: I7dc1d02f43ca1c115821e0096159585ab6dcd43e
Gerrit-Change-Number: 9403
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180712/f916c172/attachment.html>


More information about the asterisk-code-review mailing list