11#! /bin/bash
2+ # Ignore unreachable code, as it is called by `make test`.
3+ # shellcheck disable=SC2317
24
3- cd " $( dirname " ${BASH_SOURCE} " ) "
5+ cd " $( dirname " ${BASH_SOURCE[0] } " ) " || exit 1
46
57RUNGUARD=../runguard
68LOG1=" $( mktemp) "
79LOG2=" $( mktemp) "
10+ # shellcheck disable=SC2154
811META=$( mktemp -p " $judgehost_tmpdir " )
912
1013fail () {
@@ -98,7 +101,7 @@ test_streamsize() {
98101 exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -t 1 -s 123 yes DOMjudge
99102 expect_stdout " DOMjudge"
100103 limit=$(( 123 * 1024 ))
101- actual=$( cat " $LOG1 " | wc -c )
104+ actual=$( wc -c < " $LOG1 " )
102105 [ $limit -eq $actual ] || fail " stdout not limited to ${limit} B, but wrote ${actual} B"
103106}
104107
@@ -107,7 +110,7 @@ test_streamsize_stderr() {
107110 expect_stderr " DOMjudge"
108111 # Allow 100 bytes extra, for the runguard time limit message.
109112 limit=$(( 42 * 1024 + 100 ))
110- actual=$( cat " $LOG2 " | wc -c )
113+ actual=$( wc -c < " $LOG2 " )
111114 [ $limit -gt $actual ] || fail " stdout not limited to ${limit} B, but wrote ${actual} B"
112115}
113116
@@ -120,7 +123,7 @@ test_redir_stdout() {
120123 grep -q " foobar" " $stdout " || fail " did not find expected 'foobar' in redirect stdout"
121124
122125 # Verify that stdout is empty.
123- actual=$( cat " $LOG1 " | wc -c )
126+ actual=$( wc -c < " $LOG1 " )
124127 [ $actual -eq 0 ] || fail " stdout should be empty, but contains ${actual} B"
125128
126129 # This will fail because of the timeout.
@@ -129,13 +132,13 @@ test_redir_stdout() {
129132 expect_stderr " hard wall time"
130133
131134 # Verify that stdout is empty.
132- actual=$( cat " $LOG1 " | wc -c )
135+ actual=$( wc -c < " $LOG1 " )
133136 [ $actual -eq 0 ] || fail " stdout should be empty, but contains ${actual} B"
134137
135138 # Verify that redirected stdout has the right contents.
136139 grep -q " DOMjudge" " $stdout " || fail " did not find expected 'DOMjudge' in redirect stdout"
137140 limit=$(( 23 * 1024 ))
138- actual=$( cat " $stdout " | wc -c )
141+ actual=$( wc -c < " $stdout " )
139142 [ $limit -eq $actual ] || fail " redirected stdout not limited to ${limit} B, but wrote ${actual} B"
140143
141144 rm " $stdout "
@@ -156,14 +159,15 @@ test_redir_stderr() {
156159 # Verify that redirected stdout has the right contents.
157160 grep -q " DOMjudge" " $stderr " || fail " did not find expected 'DOMjudge' in redirect stderr"
158161 limit=$(( 11 * 1024 ))
159- actual=$( cat " $stderr " | wc -c )
162+ actual=$( wc -c < " $stderr " )
160163 [ $limit -eq $actual ] || fail " redirected stdout not limited to ${limit} B, but wrote ${actual} B"
161164
162165 rm " $stderr "
163166}
164167
165168test_rootdir_changedir () {
166169 # Prepare test directory.
170+ # shellcheck disable=SC2154
167171 almost_empty_dir=" $judgehost_judgedir /runguard_tests/almost_empty"
168172 mkdir -p " $almost_empty_dir " /exists
169173 cp hello " $almost_empty_dir " /
@@ -243,6 +247,7 @@ test_meta() {
243247 exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -M " $META " false
244248 expect_meta ' exitcode: 1'
245249
250+ # shellcheck disable=SC2024
246251 echo " DOMjudge" | sudo $RUNGUARD -u domjudge-run-0 -t 2 -M " $META " rev > " $LOG1 " 2> " $LOG2 "
247252 expect_meta ' wall-time: 0.0'
248253 expect_meta ' stdout-bytes: 9'
0 commit comments