Skip to content

Commit 35bad7e

Browse files
keertkmeisterT
andauthored
Fix #18493. (#18512)
The use of the pipe in b8e92cc made it swallow the exit code, so we need to set pipefail. Fix #18493 Closes #18498. PiperOrigin-RevId: 535520323 Change-Id: Idf1a5c39bf5b7deec29b76c10ece2825b568ebf2 Co-authored-by: Tobias Werth <[email protected]>
1 parent 4eea9c5 commit 35bad7e

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
@@ -125,4 +125,43 @@ eof
125125
echo "$output" | grep --fixed-strings 'ExecuteProgram(C:\first_part second_part)' || fail "Expected error message to contain unquoted path"
126126
}
127127

128+
function test_run_test_exit_code() {
129+
# EXPERIMENTAL_SPLIT_XML_GENERATION is set by the outer bazel and influences
130+
# the test setup of the inner bazel. To make sure we hit the codepath we want
131+
# to test here, unset the variable.
132+
unset EXPERIMENTAL_SPLIT_XML_GENERATION
133+
134+
mkdir -p foo
135+
cat > foo/BUILD <<'EOF'
136+
sh_test(
137+
name = "exit0",
138+
srcs = ["exit0.sh"],
139+
)
140+
141+
sh_test(
142+
name = "exit1",
143+
srcs = ["exit1.sh"],
144+
)
145+
EOF
146+
147+
cat > foo/exit0.sh <<'EOF'
148+
set -x
149+
exit 0
150+
EOF
151+
chmod +x foo/exit0.sh
152+
bazel run //foo:exit0 &>"$TEST_log" \
153+
|| fail "Expected exit code 0, received $?"
154+
155+
cat > foo/exit1.sh <<'EOF'
156+
set -x
157+
exit 1
158+
EOF
159+
chmod +x foo/exit1.sh
160+
bazel run --noexperimental_split_xml_generation //foo:exit1 &>"$TEST_log" \
161+
&& fail "Expected exit code 1, received $?"
162+
163+
# Avoid failing the test because of the last non-zero exit-code.
164+
true
165+
}
166+
128167
run_suite "run_under_tests"

tools/test/test-setup.sh

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

0 commit comments

Comments
 (0)