Andreas Wacknitz
2024-03-31 783118944874d559e30eea1600352e3feb5263a7
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
#!/bin/bash
 
# Override HOME. Bash processes $HOME/.profile.
HOME=$(pwd)/home
mkdir -p "$HOME"
export HOME
 
# Pre-set TMPDIR. The content of system tmp could collide with the tests.
TMPDIR=$(pwd)/tmp
mkdir -p "$TMPDIR"
export TMPDIR
 
if tty -s; then
    # If we have a tty, just run the tests
    gmake "$@"
else
    # If we don't have tty, run the tests in screen(1) to make the tests
    # pass successfully. But screen needs some pty already, so create one
    # using python. We can't run the tests directly in python as pty module
    # does not simulate terminal, it merely provides pty device. Also we
    # set the TERM environment variable to 'xterm' so that screen does not
    # start confused setting TERM to 'dumb' which breaks the tests again.
    # Also we have to collect the test output ourselves, since userland
    # infrastructure captures the screen output which is full of terminal
    # control codes. To offset anything user may have set in his .screenrc
    # we use /dev/null as screen config. Last touch is to unset TSTP signal
    # which is set if we run 'gmake test' via ssh. Unsetting it to default
    # makes the tests pass even in this case.
    python -c '
import pty;
import signal;
import sys;
 
signal.signal(signal.SIGTSTP, signal.SIG_DFL)
pty.spawn(sys.argv[1:])
' env TERM=xterm /usr/bin/screen -c /dev/null bash -c 'gmake '"$@"' 2>&1 | tee outfile'
fi