Просмотр исходного кода

tests: enhance output of grep and test fails

Git-Dch: Ignore
David Kalnischkies лет назад: 11
Родитель
Сommit
e52aad5208

+ 45 - 27
test/integration/framework

@@ -77,12 +77,6 @@ if [ $MSGLEVEL -le 2 ]; then
 	msgnmsg() { true; }
 	msgtest() { true; }
 	msgpass() { printf " ${CPASS}P${CNORMAL}"; }
-	msgskip() { printf " ${CWARNING}S${CNORMAL}" >&2; }
-	if [ -n "$CFAIL" ]; then
-		msgfail() { printf " ${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
-	else
-		msgfail() { printf " ###FAILED###" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
-	fi
 fi
 if [ $MSGLEVEL -le 3 ]; then
 	msginfo() { true; }
@@ -1228,6 +1222,36 @@ testmarkedauto() {
 	aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
 }
 
+msgfailoutput() {
+	local MSG="$1"
+	local OUTPUT="$2"
+	shift 2
+	echo >&2
+	if [ "$1" = 'grep' ]; then
+		while [ -n "$2" ]; do shift; done
+		echo "#### Complete file: $1 ####"
+		cat >&2 "$1" || true
+		echo '#### grep output ####'
+	elif [ "$1" = 'test' ]; then
+		# doesn't support ! or non-file flags
+		msgfailoutputstatfile() {
+			local FILEFLAGS='^-[bcdefgGhkLOprsStuwx]$'
+			if expr match "$1" "$FILEFLAGS" >/dev/null; then
+				echo "#### stat(2) of file: $2 ####"
+				stat "$2" || true
+			fi
+		}
+		msgfailoutputstatfile "$2" "$3"
+		while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
+			shift 3
+			msgfailoutputstatfile "$2" "$3"
+		done
+		echo '#### test output ####'
+	fi
+	cat >&2 $OUTPUT
+	msgfail "$MSG"
+}
+
 testsuccess() {
 	if [ "$1" = '--nomsg' ]; then
 		shift
@@ -1237,10 +1261,10 @@ testsuccess() {
 	local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
 	if "$@" >${OUTPUT} 2>&1; then
 		if expr match "$1" '^apt.*' >/dev/null; then
-			if grep -q -E '^[WE]: ' "$OUTPUT"; then
-				echo >&2
-				cat >&2 $OUTPUT
-				msgfail 'successful run, but output contains warnings/errors'
+			if grep -q -E ' runtime error: ' "$OUTPUT"; then
+				msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
+			elif grep -q -E '^[WE]: ' "$OUTPUT"; then
+				msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
 			else
 				msgpass
 			fi
@@ -1249,9 +1273,7 @@ testsuccess() {
 		fi
 	else
 		local EXITCODE=$?
-		echo >&2
-		cat >&2 $OUTPUT
-		msgfail "exitcode $EXITCODE"
+		msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
 	fi
 	aptautotest 'testsuccess' "$@"
 }
@@ -1264,14 +1286,12 @@ testwarning() {
 	local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
 	if "$@" >${OUTPUT} 2>&1; then
 		if expr match "$1" '^apt.*' >/dev/null; then
-			if grep -q -E '^E: ' "$OUTPUT"; then
-				echo >&2
-				cat >&2 $OUTPUT
-				msgfail 'successful run, but output contains errors'
+			if grep -q -E ' runtime error: ' "$OUTPUT"; then
+				msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
+			elif grep -q -E '^E: ' "$OUTPUT"; then
+				msgfailoutput 'successful run, but output contains errors' "$OUTPUT" "$@"
 			elif ! grep -q -E '^W: ' "$OUTPUT"; then
-				echo >&2
-				cat >&2 $OUTPUT
-				msgfail 'successful run, but output contains no warnings'
+				msgfailoutput 'successful run, but output contains no warnings' "$OUTPUT" "$@"
 			else
 				msgpass
 			fi
@@ -1295,16 +1315,14 @@ testfailure() {
 	local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
 	if "$@" >${OUTPUT} 2>&1; then
 		local EXITCODE=$?
-		echo >&2
-		cat >&2 $OUTPUT
-		msgfail "exitcode $EXITCODE"
+		msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
 	else
 		local EXITCODE=$?
 		if expr match "$1" '^apt.*' >/dev/null; then
-			if ! grep -q -E '^E: ' "$OUTPUT"; then
-				echo >&2
-				cat >&2 $OUTPUT
-				msgfail "run failed with exitcode ${EXITCODE}, but with no errors"
+			if grep -q -E ' runtime error: ' "$OUTPUT"; then
+				msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
+			elif ! grep -q -E '^E: ' "$OUTPUT"; then
+				msgfailoutput "run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
 			else
 				msgpass
 			fi

+ 5 - 1
test/integration/run-tests

@@ -46,7 +46,11 @@ for testcase in $(run-parts --list $DIR | grep '/test-'); do
 	if ! ${testcase}; then
 		FAIL=$((FAIL+1))
 		FAILED_TESTS="$FAILED_TESTS $(basename $testcase)"
-		echo >&2 "$(basename $testcase) ... FAIL"
+		if [ "$MSGLEVEL" -le 2 ]; then
+			printf >&2 "\n${CHIGH}Running $(basename $testcase) -> FAILED${CRESET}"
+		else
+			echo >&2 "${CHIGH}Running $(basename $testcase) -> FAILED${CRESET}"
+		fi
 	else
 		PASS=$((PASS+1))
 	fi

+ 5 - 5
test/integration/test-apt-get-clean

@@ -26,10 +26,10 @@ touch rootdir/var/cache/apt/archives/foo_4_all.deb
 
 testsuccess aptget clean
 
-testsuccess test ! -e rootdir/var/lib/apt/lists/partial/http.debian.net_debian_dists_sid_main_i18n_Translation-en
-testsuccess test ! -e rootdir/var/cache/apt/archives/foo_1_all.deb
-testsuccess test ! -e rootdir/var/cache/apt/archives/foo_2_all.deb
-testsuccess test ! -e rootdir/var/cache/apt/archives/foo_3_all.deb
-testsuccess test ! -e rootdir/var/cache/apt/archives/foo_4_all.deb
+testfailure test -e rootdir/var/lib/apt/lists/partial/http.debian.net_debian_dists_sid_main_i18n_Translation-en
+testfailure test -e rootdir/var/cache/apt/archives/foo_1_all.deb
+testfailure test -e rootdir/var/cache/apt/archives/foo_2_all.deb
+testfailure test -e rootdir/var/cache/apt/archives/foo_3_all.deb
+testfailure test -e rootdir/var/cache/apt/archives/foo_4_all.deb
 
 

+ 7 - 7
test/integration/test-apt-key

@@ -41,7 +41,7 @@ gpg:              unchanged: 1' aptkey --fakeroot update
 
 	testaptkeys 'pub   2048R/DBAC8DAE 2010-08-18'
 
-	testsuccess test ! -e rootdir/etc/apt/trusted.gpg
+	testfailure test -e rootdir/etc/apt/trusted.gpg
 	testsuccess aptkey --fakeroot add ./keys/rexexpired.pub
 	msgtest 'Check if trusted.gpg is created with permissions set to' '0644'
 	if [ "$(stat -c '%a' rootdir/etc/apt/trusted.gpg )" = '644' ]; then
@@ -78,7 +78,7 @@ pub   2048R/DBAC8DAE 2010-08-18'
 	cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
 	testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
 	testempty aptkey list
-	testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
+	testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
 	testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
 
 	msgtest 'Test key removal with' 'long key ID'
@@ -86,7 +86,7 @@ pub   2048R/DBAC8DAE 2010-08-18'
 	cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
 	testsuccess --nomsg aptkey --fakeroot del 5A90D141DBAC8DAE
 	testempty aptkey list
-	testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
+	testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
 	testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
 
 	msgtest 'Test key removal with' 'fingerprint'
@@ -94,7 +94,7 @@ pub   2048R/DBAC8DAE 2010-08-18'
 	cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
 	testsuccess --nomsg aptkey --fakeroot del 34A8E9D18DB320F367E8EAA05A90D141DBAC8DAE
 	testempty aptkey list
-	testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
+	testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
 	testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
 
 	msgtest 'Test key removal with' 'single key in softlink'
@@ -102,7 +102,7 @@ pub   2048R/DBAC8DAE 2010-08-18'
 	ln -s $(readlink -f ./keys/joesixpack.pub) rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
 	testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
 	testempty aptkey list
-	testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
+	testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
 	testsuccess test -L rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
 
 	cleanplate
@@ -125,7 +125,7 @@ pub   2048R/528144E2 2011-01-16'
 	testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
 	testaptkeys 'pub   2048R/528144E2 2011-01-16'
 	testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
-	testsuccess test ! -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg
+	testfailure test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg
 	testsuccess test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
 
 	msgtest 'Test key removal with' 'multiple files including key'
@@ -134,7 +134,7 @@ pub   2048R/528144E2 2011-01-16'
 	cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
 	testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
 	testaptkeys 'pub   2048R/528144E2 2011-01-16'
-	testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
+	testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
 	testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
 	testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
 

+ 1 - 1
test/integration/test-authentication-basic

@@ -18,7 +18,7 @@ testauthfailure() {
 	testfailure apthelper download-file "${1}/bash" ./downloaded/bash
 	# crappy test, but http and https output are wastely different…
 	testsuccess grep 401 rootdir/tmp/testfailure.output
-	testsuccess test ! -s ./downloaded/bash
+	testfailure test -s ./downloaded/bash
 }
 
 testauthsuccess() {

+ 1 - 1
test/integration/test-bug-738785-switch-protocol

@@ -54,7 +54,7 @@ echo "Dir::Bin::Methods \"${COPYMETHODS}\";" >> aptconfig.conf
 cd downloaded
 testequal "E: The method driver $(readlink -f './../')/rootdir/usr/lib/apt/methods/https could not be found.
 N: Is the package apt-transport-https installed?" aptget download apt -q=0
-testsuccess test ! -e apt_1.0_all.deb
+testfailure test -e apt_1.0_all.deb
 cd - >/dev/null
 
 # revert to all methods