Merge branch 'test-protocols' into tap-testsuite-work
[platform/upstream/automake.git] / tests / color2.test
index 26df9b2..96eac46 100755 (executable)
 TERM=ansi
 export TERM
 
-red='\e[0;31m'
-grn='\e[0;32m'
-lgn='\e[1;32m'
-blu='\e[1;34m'
-std='\e[m'
+esc='\e'
+# Escape `[' for grep, below.
+red="$esc\[0;31m"
+grn="$esc\[0;32m"
+lgn="$esc\[1;32m"
+blu="$esc\[1;34m"
+mgn="$esc\[0;35m"
+std="$esc\[m"
 
 # Check that grep can parse nonprinting characters.
 # BSD 'grep' works from a pipe, but not a seekable file.
@@ -54,7 +57,7 @@ END
 cat >Makefile.am <<'END'
 AUTOMAKE_OPTIONS = color-tests
 TESTS = $(check_SCRIPTS)
-check_SCRIPTS = pass fail skip xpass xfail
+check_SCRIPTS = pass fail skip xpass xfail error
 XFAIL_TESTS = xpass xfail
 END
 
@@ -73,34 +76,68 @@ cat >skip <<END
 exit 77
 END
 
+cat >error <<END
+#! /bin/sh
+exit 99
+END
+
 cp fail xfail
 cp pass xpass
-chmod +x pass fail skip xpass xfail
+chmod +x pass fail skip xpass xfail error
 
 $ACLOCAL
-$AUTOMAKE
 $AUTOCONF
-./configure
+$AUTOMAKE --add-missing
 
 test_color ()
 {
   # Not a useless use of cat; see above comments about grep.
-  cat stdout | grep ": pass" | $FGREP "$grn"
-  cat stdout | grep ": fail" | $FGREP "$red"
-  cat stdout | grep ": xfail" | $FGREP "$lgn"
-  cat stdout | grep ": xpass" | $FGREP "$red"
-  cat stdout | grep ": skip" | $FGREP "$blu"
+  cat stdout | grep "^${grn}PASS${std}: .*pass"
+  cat stdout | grep "^${red}FAIL${std}: .*fail"
+  cat stdout | grep "^${blu}SKIP${std}: .*skip"
+  cat stdout | grep "^${lgn}XFAIL${std}: .*xfail"
+  cat stdout | grep "^${red}XPASS${std}: .*xpass"
+  # The old serial testsuite driver doesn't distinguish between failures
+  # and hard errors.
+  if test x"$parallel_tests" = x"yes"; then
+    cat stdout | grep "^${mgn}ERROR${std}: .*error"
+  else
+    cat stdout | grep "^${red}FAIL${std}: .*error"
+  fi
+  :
 }
 
 test_no_color ()
 {
-  # Not a useless use of cat; see above comments about grep.
-  cat stdout | grep ": pass" | $FGREP "$grn" && Exit 1
-  cat stdout | grep ": fail" | $FGREP "$red" && Exit 1
-  cat stdout | grep ": xfail" | $FGREP "$lgn" && Exit 1
-  cat stdout | grep ": xpass" | $FGREP "$red" && Exit 1
-  cat stdout | grep ": skip" | $FGREP "$blu" && Exit 1
-  :
+  # With make implementations that, like Solaris make, in case of errors
+  # print the whole failing recipe on standard output, we should content
+  # ourselves with a laxer check, to avoid false positives.
+  # Keep this in sync with lib/am/check.am:$(am__color_tests).
+  if $FGREP '= Xalways || test -t 1 ' stdout; then
+    # Extra verbose make, resort to laxer checks.
+    # Note that we also want to check that the testsuite summary is
+    # not unduly colorized.
+    (
+      set +e # In case some grepped regex below isn't matched.
+      # Not a useless use of cat; see above comments about grep.
+      cat stdout | grep "TOTAL.*:"
+      cat stdout | grep "PASS.*:"
+      cat stdout | grep "FAIL.*:"
+      cat stdout | grep "SKIP.*:"
+      cat stdout | grep "XFAIL.*:"
+      cat stdout | grep "XPASS.*:"
+      cat stdout | grep "ERROR.*:"
+      cat stdout | grep 'test.*expected'
+      cat stdout | grep 'test.*not run'
+      cat stdout | grep '===='
+      cat stdout | grep '[Ss]ee .*test-suite\.log'
+      cat stdout | grep '[Tt]estsuite summary'
+    ) | grep "$esc" && Exit 1
+    : For shells with broken 'set -e'
+  else
+    cat stdout | grep "$esc" && Exit 1
+    : For shells with broken 'set -e'
+  fi
 }
 
 cat >expect-make <<'END'
@@ -109,12 +146,31 @@ eval spawn $env(MAKE) -e check
 expect eof
 END
 
-MAKE=$MAKE expect -f expect-make >stdout \
-  || { cat stdout; Exit 1; }
-cat stdout
-test_color
+for vpath in false :; do
+
+  if $vpath; then
+    mkdir build
+    cd build
+    srcdir=..
+  else
+    srcdir=.
+  fi
+
+  $srcdir/configure
+
+  MAKE=$MAKE expect -f $srcdir/expect-make >stdout \
+    || { cat stdout; Exit 1; }
+  cat stdout
+  test_color
+
+  AM_COLOR_TESTS=no MAKE=$MAKE expect -f $srcdir/expect-make >stdout \
+    || { cat stdout; Exit 1; }
+  cat stdout
+  test_no_color
+
+  $MAKE distclean
+  cd $srcdir
+
+done
 
-AM_COLOR_TESTS=no MAKE=$MAKE expect -f expect-make >stdout \
-  || { cat stdout; Exit 1; }
-cat stdout
-test_no_color
+: