Branch
Hash :
1349c729
Author :
Date :
2025-02-25T14:39:11
maint: doc and maintainer-check in preparation for 1.17.90. * HACKING: mention thanks to individuals. * NEWS: update for 1.17.90. * configure.ac (AC_INIT): now 1.17.90. * m4/amversion.m4 (AM_AUTOMAKE_VERSION): 1.17.90 (auto-update). * maintainer/syntax-checks.mk (sc_tests_command_subst): allow whitespace before # shell comment line. (sc_tests_plain_sleep): emphasize using $sleep without a number; only replace sleep 1 or sleep 2; longer than that would be fine. * t/tap-stderr-prefix.tap: use $sleep instead of sleep 1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
#! /bin/sh
# Copyright (C) 2025 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# TAP support:
# - The Automake TAP driver has an option that instructs it to prefix the
# test script's stderr with a given string.
. test-init.sh
plan_ later
dumpf() (
set +x
diag_string_='#' diag_ "####### Contents of $1:"
diag_ <$1
diag_string_='#' diag_ "#######"
)
cat >Makefile.am <<END || bailout_ "failed to create Makefile.am"
TESTS = all.test
END
dumpf Makefile.am
. tap-setup.sh
# Tests without --stderr-prefix. Historically, the TAP driver has not added
# a final newline to either stdout or stderr if the test program did not write
# one itself, so that is not tested here.
cat >all.test <<END || bailout_ "failed to create all.test"
#!/bin/sh
echo 1..2
echo ok 1
echo 'Bail out!' >&2
echo ok 2
END
chmod a+x all.test || bailout_ "failed to make all.test executable"
# Test without --stderr-prefix, without --merge.
command_ok_ "no merge, no prefix: make check passes" -- \
run_make -O AM_TEST_LOG_DRIVER_FLAGS= check
dumpf all.log
command_ok_ "no merge, no prefix: result counts are correct" -- \
count_test_results total=2 pass=2 fail=0 xpass=0 xfail=0 skip=0 error=0
command_ok_ "no merge, no prefix: stderr in log" -- \
grep -q '^Bail out!$' all.log
# Test without --stderr-prefix, with --merge.
command_ok_ "--merge: make check fails" -- \
run_make -e FAIL AM_TEST_LOG_DRIVER_FLAGS=--merge check
dumpf all.log
# Don't bother checking the counts -- they're meaningless due to the merged
# stderr "corrupting" the TAP output. It is sufficient to just test that
# `make check' returned non-zero.
command_ok_ "--merge: stderr in log" -- \
grep -q '^Bail out!$' all.log
# Tests with --stderr-prefix. If the final stderr line does not have a
# terminating newline, the TAP driver should still print the line with the
# prefix; a newline is also added to avoid "corrupting" the final prefixed
# stderr line with a subsequent stdout line in the log.
cat >all.test <<END || bailout_ "failed to create all.test"
#!/bin/sh
echo 1..2
echo ok 1
echo 'Bail out!' >&2
echo ok 2
printf %s 'final stderr line without newline terminator' >&2
echo "# This comment is written to stdout after the newline-less stderr line"
echo "# to ensure that a stdout line written after the final stderr line does"
echo "# not get written to the same line in the log as the final stderr line."
END
chmod a+x all.test || bailout_ "failed to make all.test executable"
# Included in the prefix:
# 1. quadrigraph for # (@%:@)
# 2. literal # (difficult to include in a Makefile variable, but easy to
# pass in a command-line make variable assignment)
# 3. a string that expands to @%:@ (quadrigraph for #) after quadrigraph
# replacement, accomplished by embedding a quadrigraph for the empty
# string inside the quadrigraph for #
# The end result should be: ##@%:@
PFXFLAG='--stderr-prefix "@%:@#@%@&t@:@ "'
# Test with --stderr-prefix, without --merge.
command_ok_ "$PFXFLAG: make check passes" -- \
run_make -O AM_TEST_LOG_DRIVER_FLAGS="$PFXFLAG" check
dumpf all.log
command_ok_ "$PFXFLAG: result counts are correct" -- \
count_test_results total=2 pass=2 fail=0 xpass=0 xfail=0 skip=0 error=0
command_ok_ "$PFXFLAG: prefixed stderr in log" -- \
grep -q '^##@%:@ Bail out!$' all.log
command_ok_ "$PFXFLAG: missing final newline is added" -- \
grep -q '^##@%:@ final stderr line without newline terminator$' all.log
# Test with --stderr-prefix, with --merge.
command_ok_ "$PFXFLAG --merge: make check passes" -- \
run_make -O AM_TEST_LOG_DRIVER_FLAGS="$PFXFLAG --merge" check
dumpf all.log
command_ok_ "$PFXFLAG --merge: result counts are correct" -- \
count_test_results total=2 pass=2 fail=0 xpass=0 xfail=0 skip=0 error=0
command_ok_ "$PFXFLAG --merge: prefixed stderr in log" -- \
grep -q '^##@%:@ Bail out!$' all.log
# Note: When --stderr-prefix is enabled, the TAP driver intentionally waits to
# read a complete line before writing it to the log. This reduces the chances
# of mixing stderr and stdout in a single log line. If you look at the log
# for this test, the final stderr line appears last despite being written by
# the test program before the stderr comment lines. This is because the TAP
# driver patiently waited for a newline that never came.
command_ok_ "$PFXFLAG --merge: missing final newline is added" -- \
grep -q '^##@%:@ final stderr line without newline terminator$' all.log
# Test preserved stdout/stderr ordering. The sleeps between writes are
# necessary because stdout and stderr are independent and thus inherently race
# with each other. (The kernel can wake up the two downstream reader threads
# in the opposite order from the upstream writes. Or, if the TAP driver was
# changed to use select or poll, the upstream writer can write to both streams
# before the kernel wakes up the one downstream reader.)
PFXFLAG='--stderr-prefix "# "'
desc="$PFXFLAG --merge stdout/stderr ordering"
cat >all.test <<END || bailout_ "failed to create all.test"
#!/bin/sh
echo '1..1'
$sleep
echo 'stderr 1' >&2
$sleep
echo 'ok 1'
$sleep
echo 'stderr 2' >&2
END
chmod a+x all.test || bailout_ "failed to make all.test executable"
check_log_line_order() {
{
grep -xe "$1" all.log
grep -xe "$2" all.log
sed -n -e '/^\('"$1"'\)$/,${/^\('"$2"'\)$/p}' all.log | grep -xe "$2"
} >&2 # Write to stderr in case $1 or $2 looks like a TAP directive.
}
command_ok_ "$desc: make check passes" -- \
run_make -O AM_TEST_LOG_DRIVER_FLAGS="$PFXFLAG --merge" check
dumpf all.log
command_ok_ "$desc: result counts are correct" -- \
count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
command_ok_ "$desc: '1..1' before 'stderr 1'" -- \
check_log_line_order '1\.\.1' '# stderr 1'
command_ok_ "$desc: 'stderr 1' before 'ok 1'" -- \
check_log_line_order '# stderr 1' 'ok 1'
command_ok_ "$desc: 'ok 1' before 'stderr 2'" -- \
check_log_line_order 'ok 1' '# stderr 2'
plan_ now
: