Skip to content

Commit 830d464

Browse files
mattyclarksoncopybara-github
authored andcommitted
Export BAZEL_TEST=1 for bazel test executables
[Catch2][catch2] has [learnt][pr2399] how to output JUnit to the `XML_OUTPUT_FILE`. However, the upstream developers [felt][comment] that `XML_OUTPUT_FILE` is too generic to blanket enable JUnit output to the file as there are various XML reporters for Catch2. This patch enables exporting `BAZEL_TEST` environment variable so that Catch2 can enable JUnit output support unconditionally in their build when both `BAZEL_TEST` _and_ `XML_OUTPUT_FILE` are available. [catch2]: https://github.com/catchorg/Catch2 [pr2399]: catchorg/Catch2#2399 [comment]: catchorg/Catch2#2399 (comment) Closes #15393. PiperOrigin-RevId: 447706388
1 parent 83ca7d1 commit 830d464

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

site/en/reference/test-encyclopedia.md

+5
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ The initial environment block shall be composed as follows:
452452
class="external">JUnit test result schema</a>.</td>
453453
<td>optional</td>
454454
</tr>
455+
<tr>
456+
<td><code>BAZEL_TEST</code></td>
457+
<td>Signifies test executable is being driven by <code>bazel test</code></td>
458+
<td>required</td>
459+
</tr>
455460
</table>
456461

457462
The environment may contain additional entries. Tests should not depend on the

tools/test/test-setup.sh

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ function is_absolute {
3737
# root.
3838
EXEC_ROOT="$PWD"
3939

40+
# Declare that the executable is running in a `bazel test` environment
41+
# This allows test frameworks to enable output to the unprefixed environment variable
42+
# For example, if `BAZEL_TEST` and `XML_OUTPUT_FILE` are defined, write JUnit output
43+
export BAZEL_TEST=1
44+
4045
# Bazel sets some environment vars to relative paths to improve caching and
4146
# support remote execution, where the absolute path may not be known to Bazel.
4247
# Convert them to absolute paths here before running the actual test.

0 commit comments

Comments
 (0)