]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Avoid a spurious test failure with shells that ignore write errors.
authorZack Weinberg <zack@owlfolio.org>
Fri, 22 Dec 2023 13:47:36 +0000 (08:47 -0500)
committerZack Weinberg <zack@owlfolio.org>
Fri, 22 Dec 2023 13:47:36 +0000 (08:47 -0500)
In a surprisingly large number of cases, the ‘printf’ shell utility
doesn’t report errors caused by writing to stdout.  This can cause
a spurious test failure on systems that have this bug in ‘printf’
and also have /dev/full.  Detect such systems and skip that subtest.

Problem reported by Alan Coopersmith.

* tests/torture.at (AC_CONFIG_FILES, HEADERS, LINKS and COMMANDS):
  If /bin/sh’s printf doesn’t report an error on writing to /dev/full,
  skip the subtests that write to /dev/full.

tests/torture.at

index 288a5a5590ac8ae3c6ea9b33dd457bccaf7cb82e..d98b92c02d2d21d58f52dc9bf881aa31c2076eab 100644 (file)
@@ -291,7 +291,21 @@ AT_CHECK_CONFIG_CREATION(command)
 # Create a link
 AT_CHECK_CONFIG_CREATION(link)
 
-# Now check for write errors
+# Now check for write errors.
+# Depending on the shell, 'printf' might or might not report write
+# errors on stdout.  Check /bin/sh regardless of $SHELL, because
+# config.status always uses /bin/sh.
+# Note: another way to force a write error is with ulimit -f, but
+# depending on the OS it might not be possible to set that limit
+# lower than one disk block, so we'd have to make the tests below
+# produce much more output.
+test_write_errors=false
+if test -w /dev/full && test -c /dev/full; then
+  if /bin/sh -c 'printf "write errors detected?\\n"' > /dev/full 2> /dev/null
+  then :
+  else test_write_errors=:
+  fi
+fi
 
 # Create a file
 AT_CHECK_CONFIG_CREATION_NOWRITE(file)
@@ -301,7 +315,7 @@ AT_CHECK([echo from-stdin | ./config.status --file=file:-],
 AT_CHECK([grep from-stdin file], [], [from-stdin
 ])
 # Force write error creating a file on stdout
-if test -w /dev/full && test -c /dev/full; then
+if $test_write_errors; then
   AT_CHECK([./config.status --file=-:input </dev/null >/dev/full || exit 1],
           [1], [ignore], [ignore])
 fi
@@ -320,7 +334,7 @@ AT_CHECK([./config.status --header=-:input </dev/null],
 AT_CHECK([grep OK stdout], [], [OK
 ])
 # Force write error creating a header on stdout
-if test -w /dev/full && test -c /dev/full; then
+if $test_write_errors; then
   AT_CHECK([./config.status --header=-:input </dev/null >/dev/full || exit 1],
           [1], [ignore], [ignore])
 fi