Fix handling of long test names by the bash unit test framework when using `set -eo pipefail`.
Bash unit test framework uses `... | head -c 80` to truncate test name, padded with `*`. `head` will read the first 80 bytes and close the file descriptor, consequently, the process stuck on `write(pipe_fd, ...)` will get SIGPIPE and fail. When using `set -eo pipefail`, the exit code will be propagated through the pipe and, consequently, getting the truncated test name will fail.
For tests with long names, the name itself will take 80 bytes, therefore `head` will not issue a second `read` and `close` the pipe. This makes the next process which generates the `*` padding run `write` for a pipe with no readers and fail on SIGPIPE.
Fix the helper to ignore failures propagated from printing the padded test name.
PiperOrigin-RevId: 401527864
diff --git a/src/test/shell/unittest_test.py b/src/test/shell/unittest_test.py
index c716d6a..ad3a7f4 100644
--- a/src/test/shell/unittest_test.py
+++ b/src/test/shell/unittest_test.py
@@ -288,6 +288,22 @@
result.assertLogMessage("Running tear_down")
result.assertLogMessage("Running testenv_tear_down")
+ def test_set_bash_errexit_pipefail_long_testname_succeeds(self):
+ test_name = "x" * 1000
+ self.write_file(
+ "thing.sh", """
+set -euo pipefail
+
+function test_%s() {
+ :
+}
+
+run_suite "bash errexit tests"
+""" % test_name)
+
+ result = self.execute_test("thing.sh")
+ result.assertSuccess("bash errexit tests")
+
def test_empty_test_fails(self):
self.write_file("thing.sh", """
# No tests present.