Skip to content

Commit 2d5beca

Browse files
committed
sharness: add function to check for COLUMNS usability
Problem: With some versions of bash (likely >= 5.0), the COLUMNS shell variable, when overridden in the environment for testing purposes, is not preserved across invocation of the flux(1) command driver during sharness tests. This appears to occur because COLUMNS is reset by the libtool wrapper script (which has the shebang line #!/bin/bash), and only seems to occur if the sharness test is run with `-d -v` for unknown reason. Add a function to sharness.d/flux-sharness.sh that checks if COLUMNS can be preserved in the testsuite environment across an invocation of `flux(1)`. This can be used by tests that require this functionality to set a prereq, allowing them to skip the tests if necessary instead of erroneously failing.
1 parent 1a25d9a commit 2d5beca

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

t/sharness.d/flux-sharness.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,23 @@ test_on_rank() {
292292
flux exec --rank=${ranks} "$@"
293293
}
294294

295+
# Note: Some versions of bash may cause the `flux` libtool wrapper script
296+
# to reset the COLUMNS shell variable even if it is explicitly set for
297+
# for testing purposes. This causes tests that check for output truncation
298+
# based on COLUMNS to erroneously fail. (Note: this only seems to be the
299+
# case when tests are run with --debug --verbose for unknown reasons.
300+
#
301+
# Add a script for tests that use COLUMNS to check if the variable will
302+
# be preserved across an invovation of flux(1) so they may set a prereq
303+
# and skip tests that might erroneous fail if COLUMNS is not preserved.
304+
#
305+
test_columns_variable_preserved() {
306+
local cols=$(COLUMNS=12 \
307+
flux python -c \
308+
"import shutil; print(shutil.get_terminal_size().columns)")
309+
test "$cols" = "12"
310+
}
311+
295312
# Export a shorter name for this test
296313
TEST_NAME=$SHARNESS_TEST_NAME
297314
export TEST_NAME

0 commit comments

Comments
 (0)