Skip to content

Commit d3bb7bc

Browse files
committed
The use of the pipe in bazelbuild@b8e92cc made it swallow the exit code, so we need to set pipefail.
1 parent d6257ee commit d3bb7bc

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/test/shell/bazel/run_test.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,43 @@ EOF
172172
./script.bat || fail "Run should succeed"
173173
}
174174

175+
function test_run_test_exit_code() {
176+
# EXPERIMENTAL_SPLIT_XML_GENERATION is set by the outer bazel and influences
177+
# the test setup of the inner bazel. To make sure we hit the codepath we want
178+
# to test here, unset the variable.
179+
unset EXPERIMENTAL_SPLIT_XML_GENERATION
180+
181+
mkdir -p foo
182+
cat > foo/BUILD <<'EOF'
183+
sh_test(
184+
name = "exit0",
185+
srcs = ["exit0.sh"],
186+
)
187+
188+
sh_test(
189+
name = "exit1",
190+
srcs = ["exit1.sh"],
191+
)
192+
EOF
193+
194+
cat > foo/exit0.sh <<'EOF'
195+
set -x
196+
exit 0
197+
EOF
198+
chmod +x foo/exit0.sh
199+
bazel run //foo:exit0 &>"$TEST_log" \
200+
|| fail "Expected exit code 0, received $?"
201+
202+
cat > foo/exit1.sh <<'EOF'
203+
set -x
204+
exit 1
205+
EOF
206+
chmod +x foo/exit1.sh
207+
bazel run --noexperimental_split_xml_generation //foo:exit1 &>"$TEST_log" \
208+
&& fail "Expected exit code 1, received $?"
209+
210+
# Avoid failing the test because of the last non-zero exit-code.
211+
true
212+
}
213+
175214
run_suite "run_under_tests"

tools/test/test-setup.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,13 @@ if [[ "${EXPERIMENTAL_SPLIT_XML_GENERATION}" == "1" ]]; then
323323
("$1" "$TEST_PATH" "${@:3}" 2>&1) <&0 &
324324
fi
325325
else
326+
set -o pipefail
326327
if [ -z "$COVERAGE_DIR" ]; then
327328
("${TEST_PATH}" "$@" 2>&1 | tee -a "${XML_OUTPUT_FILE}.log") <&0 &
328329
else
329330
("$1" "$TEST_PATH" "${@:3}" 2>&1 | tee -a "${XML_OUTPUT_FILE}.log") <&0 &
330331
fi
332+
set +o pipefail
331333
fi
332334
childPid=$!
333335

0 commit comments

Comments
 (0)