X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/2af2eb53e867bfcc0422aaf3c93c79eb2c93e9cc..2906182db398419a9c59a928b7ae73cf7c7aa307:/test/integration/run-tests?ds=sidebyside

diff --git a/test/integration/run-tests b/test/integration/run-tests
index d700cc3fc..7c0b74ce2 100755
--- a/test/integration/run-tests
+++ b/test/integration/run-tests
@@ -1,19 +1,29 @@
 #!/bin/sh
 set -e
 
-FAIL=0
-PASS=0
-ALL=0
-
-FAILED_TESTS=""
-DIR=$(readlink -f $(dirname $0))
+TESTTORUN=''
 while [ -n "$1" ]; do
 	if [ "$1" = "-q" ]; then
 		export MSGLEVEL=2
+	elif [ "$1" = "-qq" ]; then
+		export MSGLEVEL=1
 	elif [ "$1" = "-v" ]; then
 		export MSGLEVEL=4
 	elif [ "$1" = '--color=no' ]; then
 		export MSGCOLOR='NO'
+	elif [ "$1" = '--color=yes' ]; then
+		export MSGCOLOR='YES'
+	elif [ "$1" = '--color' ]; then
+		export MSGCOLOR="$(echo "$2" | tr 'a-z' 'A-Z')"
+		shift
+	elif [ "$1" = '--level' ]; then
+		export MSGLEVEL=$2
+		shift
+	elif [ "$1" = '-j' ]; then
+		APT_TEST_JOBS=$2
+		shift
+	elif [ -x "$1" ]; then
+		TESTTORUN="$1"
 	else
 		echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
 	fi
@@ -21,8 +31,8 @@ while [ -n "$1" ]; do
 done
 export MSGLEVEL="${MSGLEVEL:-3}"
 
-if [ "$MSGCOLOR" != 'NO' ]; then
-	if ! expr match "$(readlink -f /proc/$$/fd/1)" '/dev/pts/[0-9]\+' > /dev/null; then
+if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
+	if [ ! -t 1 ]; then # but check that we output to a terminal
 		export MSGCOLOR='NO'
 	fi
 fi
@@ -36,22 +46,99 @@ else
 	CRESET=''
 fi
 
-TOTAL="$(run-parts --list $DIR | grep '/test-' | wc -l)"
-for testcase in $(run-parts --list $DIR | grep '/test-'); do
-	if [ "$MSGLEVEL" -le 2 ]; then
-		echo -n "${CTEST}Testcase ${CHIGH}$(basename ${testcase})${CRESET}: "
+if [ -n "$TESTTORUN" ]; then
+	# collecting the output of one test to have it together
+	OUTPUT="$(mktemp)"
+	CURRENTTRAP="rm -f \"$OUTPUT\"; $CURRENTTRAP"
+	trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
+	{
+		if [ "$MSGLEVEL" -le 1 ]; then
+			printf "${TESTTORUN##*/}"
+		elif [ "$MSGLEVEL" -le 2 ]; then
+			printf "${CTEST}Testcase ${CHIGH}${TESTTORUN##*/}${CRESET}: "
+		else
+			printf "${CTEST}Run Testcase ${CHIGH}${TESTTORUN##*/}${CRESET}\n"
+		fi
+		if ! "$TESTTORUN"; then
+			FAIL='yes'
+			if [ "$MSGLEVEL" -le 2 ]; then
+				printf >&2 "\n${CHIGH}Running ${TESTTORUN##*/} -> FAILED${CRESET}\n"
+			elif [ "$MSGLEVEL" -le 2 ]; then
+				printf >&2 "\n${CHIGH}Running ${TESTTORUN##*/} -> FAILED${CRESET}"
+			else
+				echo >&2 "${CHIGH}Running ${TESTTORUN##*/} -> FAILED${CRESET}"
+			fi
+		else
+			if [ "$MSGLEVEL" -le 1 ]; then
+				printf " "
+			fi
+		fi
+		if [ "$MSGLEVEL" -le 1 ]; then
+			:
+		elif [ "$MSGLEVEL" -le 2 ]; then
+			echo
+		fi
+	} >"$OUTPUT" 2>&1
+	# without we end up getting stepped output 'randomly'
+	stty sane
+	cat >&2 "$OUTPUT"
+	stty sane
+	if [ "$FAIL" = 'yes' ]; then
+		exit 1
+	else
+		exit 0
+	fi
+fi
+
+FAIL=0
+PASS=0
+ALL=0
+FAILED_TESTS=""
+DIR="$(readlink -f "$(dirname "$0")")"
+cd "$DIR"
+TESTLIST="$(find . -mindepth 1 -maxdepth 1 -regex '^\./test-[^/]*$' | sort)"
+if [ -n "$APT_TEST_JOBS" ]; then
+	if [ "$MSGCOLOR" != 'NO' ]; then
+		export MSGCOLOR='ALWAYS'
+	fi
+	parallel=parallel
+	if command -v moreutils-parallel >/dev/null 2>&1; then
+		parallel=moreutils-parallel
+	fi
+	exec $parallel -j "$APT_TEST_JOBS" "./$(basename "$0")" -- $(echo "$TESTLIST")
+fi
+TOTAL="$(echo "$TESTLIST" | wc -l)"
+if [ "$MSGLEVEL" -le 1 ]; then
+	printf "${CTEST}Running testcases${CRESET}: "
+fi
+for testcase in $TESTLIST; do
+	if [ "$MSGLEVEL" -le 1 ]; then
+		printf "${testcase##*/}"
+	elif [ "$MSGLEVEL" -le 2 ]; then
+		printf "($(($ALL+1))/${TOTAL}) ${CTEST}Testcase ${CHIGH}${testcase##*/}${CRESET}: "
 	else
-		echo "${CTEST}Run Testcase ($(($ALL+1))/${TOTAL}) ${CHIGH}$(basename ${testcase})${CRESET}"
+		printf "${CTEST}Run Testcase ($(($ALL+1))/${TOTAL}) ${CHIGH}${testcase##*/}${CRESET}\n"
 	fi
 	if ! ${testcase}; then
 		FAIL=$((FAIL+1))
-		FAILED_TESTS="$FAILED_TESTS $(basename $testcase)"
-		echo >&2 "$(basename $testcase) ... FAIL"
+		FAILED_TESTS="$FAILED_TESTS ${testcase##*/}"
+		if [ "$MSGLEVEL" -le 1 ]; then
+			printf >&2 "\n${CHIGH}Running ${testcase##*/} -> FAILED${CRESET}\n"
+		elif [ "$MSGLEVEL" -le 2 ]; then
+			printf >&2 "\n${CHIGH}Running ${testcase##*/} -> FAILED${CRESET}"
+		else
+			echo >&2 "${CHIGH}Running ${testcase##*/} -> FAILED${CRESET}"
+		fi
 	else
 		PASS=$((PASS+1))
+		if [ "$MSGLEVEL" -le 1 ]; then
+			printf " "
+		fi
 	fi
 	ALL=$((ALL+1))
-	if [ "$MSGLEVEL" -le 2 ]; then
+	if [ "$MSGLEVEL" -le 1 ]; then
+		:
+	elif [ "$MSGLEVEL" -le 2 ]; then
 		echo
 	fi
 done