1
1
#! /bin/bash
2
+ # Ignore unreachable code, as it is called by `make test`.
3
+ # shellcheck disable=SC2317
2
4
3
- cd " $( dirname " ${BASH_SOURCE} " ) "
5
+ cd " $( dirname " ${BASH_SOURCE[0] } " ) " || exit 1
4
6
5
7
RUNGUARD=../runguard
6
8
LOG1=" $( mktemp) "
7
9
LOG2=" $( mktemp) "
10
+ # shellcheck disable=SC2154
8
11
META=$( mktemp -p " $judgehost_tmpdir " )
9
12
10
13
fail () {
@@ -98,7 +101,7 @@ test_streamsize() {
98
101
exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -t 1 -s 123 yes DOMjudge
99
102
expect_stdout " DOMjudge"
100
103
limit=$(( 123 * 1024 ))
101
- actual=$( cat " $LOG1 " | wc -c )
104
+ actual=$( wc -c < " $LOG1 " )
102
105
[ $limit -eq $actual ] || fail " stdout not limited to ${limit} B, but wrote ${actual} B"
103
106
}
104
107
@@ -107,7 +110,7 @@ test_streamsize_stderr() {
107
110
expect_stderr " DOMjudge"
108
111
# Allow 100 bytes extra, for the runguard time limit message.
109
112
limit=$(( 42 * 1024 + 100 ))
110
- actual=$( cat " $LOG2 " | wc -c )
113
+ actual=$( wc -c < " $LOG2 " )
111
114
[ $limit -gt $actual ] || fail " stdout not limited to ${limit} B, but wrote ${actual} B"
112
115
}
113
116
@@ -120,7 +123,7 @@ test_redir_stdout() {
120
123
grep -q " foobar" " $stdout " || fail " did not find expected 'foobar' in redirect stdout"
121
124
122
125
# Verify that stdout is empty.
123
- actual=$( cat " $LOG1 " | wc -c )
126
+ actual=$( wc -c < " $LOG1 " )
124
127
[ $actual -eq 0 ] || fail " stdout should be empty, but contains ${actual} B"
125
128
126
129
# This will fail because of the timeout.
@@ -129,13 +132,13 @@ test_redir_stdout() {
129
132
expect_stderr " hard wall time"
130
133
131
134
# Verify that stdout is empty.
132
- actual=$( cat " $LOG1 " | wc -c )
135
+ actual=$( wc -c < " $LOG1 " )
133
136
[ $actual -eq 0 ] || fail " stdout should be empty, but contains ${actual} B"
134
137
135
138
# Verify that redirected stdout has the right contents.
136
139
grep -q " DOMjudge" " $stdout " || fail " did not find expected 'DOMjudge' in redirect stdout"
137
140
limit=$(( 23 * 1024 ))
138
- actual=$( cat " $stdout " | wc -c )
141
+ actual=$( wc -c < " $stdout " )
139
142
[ $limit -eq $actual ] || fail " redirected stdout not limited to ${limit} B, but wrote ${actual} B"
140
143
141
144
rm " $stdout "
@@ -156,14 +159,15 @@ test_redir_stderr() {
156
159
# Verify that redirected stdout has the right contents.
157
160
grep -q " DOMjudge" " $stderr " || fail " did not find expected 'DOMjudge' in redirect stderr"
158
161
limit=$(( 11 * 1024 ))
159
- actual=$( cat " $stderr " | wc -c )
162
+ actual=$( wc -c < " $stderr " )
160
163
[ $limit -eq $actual ] || fail " redirected stdout not limited to ${limit} B, but wrote ${actual} B"
161
164
162
165
rm " $stderr "
163
166
}
164
167
165
168
test_rootdir_changedir () {
166
169
# Prepare test directory.
170
+ # shellcheck disable=SC2154
167
171
almost_empty_dir=" $judgehost_judgedir /runguard_tests/almost_empty"
168
172
mkdir -p " $almost_empty_dir " /exists
169
173
cp hello " $almost_empty_dir " /
@@ -243,6 +247,7 @@ test_meta() {
243
247
exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -M " $META " false
244
248
expect_meta ' exitcode: 1'
245
249
250
+ # shellcheck disable=SC2024
246
251
echo " DOMjudge" | sudo $RUNGUARD -u domjudge-run-0 -t 2 -M " $META " rev > " $LOG1 " 2> " $LOG2 "
247
252
expect_meta ' wall-time: 0.0'
248
253
expect_meta ' stdout-bytes: 9'
0 commit comments