This repository was archived by the owner on Feb 10, 2025. It is now read-only.
forked from jblang/bbcbasic-z80
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest
More file actions
executable file
·117 lines (90 loc) · 2.37 KB
/
test
File metadata and controls
executable file
·117 lines (90 loc) · 2.37 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
set +x
TEST_RUNNER_DIR=./tests-fixtures/
SCRIPT_TO_RUN=$1
TAIL=${2}
MOCK_FILE=${TEST_RUNNER_DIR}${SCRIPT_TO_RUN}.bas
sudo rm -f /tmp/output.txt
SCREEN_PID=$(sudo screen -ls | grep bbcbasictestrunner | cut -d. -f1 | awk '{print $1}')
if [ "$SCREEN_PID" != "" ]; then
sudo kill $SCREEN_PID
fi
echo "${SCRIPT_TO_RUN}:"
CMD=""
if test -f "$MOCK_FILE"; then
CMD="--hbios-mocks $MOCK_FILE $CMD"
fi
STARTUP_FAILED=1
TAILPID=
function cleanup()
{
if [ $TAILPID ]; then
kill $TAILPID
fi
if [ "$STARTUP_FAILED" == "1" ]; then
cat /tmp/output.txt
fi
}
trap cleanup EXIT
set -e
sudo screen -d -m -L -Logfile /tmp/output.txt -S "bbcbasictestrunner" $(which cpm) $CMD
sudo screen -r bbcbasictestrunner -p0 -X logfile flush 0
input="${SCRIPT_TO_RUN}.bas"
sudo screen -S bbcbasictestrunner -p 0 -X stuff "BBCBASIC^M"
set +e
STARTUP_FAILED=0
if [ "$TAIL" != "no-tail" ]; then
tail -F -n50 /tmp/output.txt 2> /dev/null &
TAILPID=$!
fi
cd ${TEST_RUNNER_DIR}
while IFS= read -r line
do
if [ "$TAIL" == "no-tail" ]; then
printf "."
fi
if [[ ${line:0:1} == "." ]] ; then
if [ "${line}" == "./clear" ]; then
sudo truncate -s 0 /tmp/output.txt
else
if [ "${line}" == ".ESC" ]; then
sudo screen -S bbcbasictestrunner -p 0 -X stuff "^["
else
if [ "$TAIL" != "no-tail" ]; then
echo
printf "\e[33m"
echo ${line}
printf "\e[0m"
fi
if ! eval "$line"; then
echo
echo -e "\e[31m${line}"
echo -e "FAILED\e[0m"
exit 1
fi
fi
fi
else
if [[ ${line:0:1} != "<" && ${line:0:1} != ">" ]]; then
sudo screen -S bbcbasictestrunner -p 0 -X stuff "$line"
sudo screen -S bbcbasictestrunner -p 0 -X stuff "^M"
fi
fi
done < "$input"
sudo screen -S bbcbasictestrunner -p 0 -X stuff "*BYE^M"
NEXT_WAIT_TIME=0
until [ $(grep -c "*BYE" /tmp/output.txt) == "1" ] || [ $NEXT_WAIT_TIME -eq 6 ]; do
(( NEXT_WAIT_TIME++ ))
sleep 0.25
sudo screen -S bbcbasictestrunner -p 0 -X stuff "^M"
sudo screen -S bbcbasictestrunner -p 0 -X stuff "*BYE^M"
done
sudo screen -S bbcbasictestrunner -p 0 -X stuff "bye^M"
SCREEN_PID=$(sudo screen -ls | grep bbcbasictestrunner | cut -d. -f1 | awk '{print $1}')
if [ "$SCREEN_PID" != "" ]; then
sudo kill $SCREEN_PID
echo
echo "Session failed to exit"
else
echo -e "\nPASSED"
fi