diff options
| author | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-03-10 17:38:27 +0300 |
|---|---|---|
| committer | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-03-10 17:38:27 +0300 |
| commit | ceefe27a76f3b2075abbf01b0c44375363967af6 (patch) | |
| tree | 5654f2ffb11f9bdae881c055eef0ff498b5b1111 | |
| parent | aa069b768494b8d7503701cffad690e0563ee3b7 (diff) | |
| download | Project-Tick-ceefe27a76f3b2075abbf01b0c44375363967af6.tar.gz Project-Tick-ceefe27a76f3b2075abbf01b0c44375363967af6.zip | |
test: stabilize PTY -t tests in restricted environments
Handle PTY/TTY limitations more robustly in the test suite:
- check isatty(fd) in fd_helper after dup2
- skip PTY-positive checks when PTY setup or tty probes are blocked
- use an absolute shell path for fd_helper execv probes
- keep failing when shell test -t succeeds but test(1) returns false
Signed-off-by: Mehmet Samet Duman <yongdohyun@projecttick.org>
| -rw-r--r-- | tests/fd_helper.c | 3 | ||||
| -rw-r--r-- | tests/test.sh | 49 |
2 files changed, 44 insertions, 8 deletions
diff --git a/tests/fd_helper.c b/tests/fd_helper.c index 6036b62bef..27d81f7164 100644 --- a/tests/fd_helper.c +++ b/tests/fd_helper.c @@ -99,6 +99,9 @@ main(int argc, char **argv) if (dup2(slave_fd, fd) < 0) die_errno("dup2"); + if (!isatty(fd)) + die_errno("isatty"); + if (slave_fd != fd) close(slave_fd); close(master_fd); diff --git a/tests/test.sh b/tests/test.sh index d2c6e9ff5f..debbbf81a1 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -5,6 +5,7 @@ ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) TEST_BIN=${TEST_BIN:-"$ROOT/out/test"} BRACKET_BIN=${BRACKET_BIN:-"$ROOT/out/["} FD_HELPER_BIN=${FD_HELPER_BIN:-"$ROOT/build/fd_helper"} +SHELL_BIN=$(command -v sh) TMPDIR=${TMPDIR:-/tmp} WORKDIR=$(mktemp -d "$TMPDIR/test-test.XXXXXX") @@ -413,14 +414,46 @@ assert_empty "closed fd tty stdout" "$LAST_STDOUT" assert_empty "closed fd tty stderr" "$LAST_STDERR" run_capture "$FD_HELPER_BIN" 9 "$TEST_BIN" -t 9 -if [ "$LAST_STATUS" -eq 126 ]; then - assert_contains "pty helper skip reason" "$LAST_STDERR" "posix_openpt" - skip "pty-backed -t positive test skipped because PTY allocation is blocked" -else - assert_status "pty fd tty status" 0 "$LAST_STATUS" - assert_empty "pty fd tty stdout" "$LAST_STDOUT" - assert_empty "pty fd tty stderr" "$LAST_STDERR" -fi +case $LAST_STATUS in + 0) + assert_empty "pty fd tty stdout" "$LAST_STDOUT" + assert_empty "pty fd tty stderr" "$LAST_STDERR" + ;; + 1) + run_capture "$FD_HELPER_BIN" 9 "$SHELL_BIN" -c 'test -t 9' + case $LAST_STATUS in + 1) + skip "pty-backed -t positive test skipped because shell test also reports non-tty" + ;; + 126) + case $LAST_STDERR in + *"posix_openpt"*|*"grantpt"*|*"unlockpt"*|*"ptsname"*|*"open slave pty"*|*"isatty"*) + skip "pty-backed -t positive test skipped because PTY checks are blocked" + ;; + *) + fail "pty helper unexpected failure: $LAST_STDERR" + ;; + esac + ;; + *) + fail "pty fd tty status mismatch: test returned 1 but shell test -t returned $LAST_STATUS" + ;; + esac + ;; + 126) + case $LAST_STDERR in + *"posix_openpt"*|*"grantpt"*|*"unlockpt"*|*"ptsname"*|*"open slave pty"*|*"isatty"*) + skip "pty-backed -t positive test skipped because PTY checks are blocked" + ;; + *) + fail "pty helper unexpected failure: $LAST_STDERR" + ;; + esac + ;; + *) + fail "pty helper unexpected status: $LAST_STATUS" + ;; +esac run_capture "$BRACKET_BIN" alpha = alpha ']' assert_status "bracket true status" 0 "$LAST_STATUS" |
