Skip to content

Commit 0a9d612

Browse files
cristiandonosoccopybara-github
authored andcommitted
[test][windows] Export BAZEL_TEST=1 on windows
This was an oversight from when exporting BAZEL_TEST on Linux. fixes: #21420 Closes #21444. PiperOrigin-RevId: 610338496 Change-Id: Icbbdc42b6ea92a2de2b0c558aea47a24493c9d8a
1 parent e482e8b commit 0a9d612

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/test/py/bazel/bazel_windows_test.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,40 @@ def testZipUndeclaredTestOutputs(self):
487487
self.assertTrue(os.path.exists(output_file))
488488
self.assertFalse(os.path.exists(output_zip))
489489

490+
def testBazelForwardsRequiredEnvVariable(self):
491+
self.CreateWorkspaceWithDefaultRepos('WORKSPACE')
492+
self.ScratchFile(
493+
'BUILD',
494+
[
495+
'sh_test(',
496+
' name = "foo_test",',
497+
' srcs = ["foo.sh"],',
498+
')',
499+
'',
500+
],
501+
)
502+
self.ScratchFile(
503+
'foo.sh',
504+
[
505+
"""
506+
if [[ "$BAZEL_TEST" == "1" ]]; then
507+
exit 0
508+
else
509+
echo "BAZEL_TEST is not set to 1"
510+
exit 1
511+
fi
512+
""",
513+
],
514+
)
515+
516+
exit_code, stdout, stderr = self.RunBazel(
517+
[
518+
'test',
519+
'//:foo_test',
520+
],
521+
)
522+
self.AssertExitCode(exit_code, 0, stderr, stdout)
523+
490524
def testTestShardStatusFile(self):
491525
self.CreateWorkspaceWithDefaultRepos('WORKSPACE')
492526
self.ScratchFile(

tools/test/windows/tw.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,11 @@ bool ExportGtestVariables(const Path& test_tmpdir) {
628628
}
629629

630630
bool ExportMiscEnvvars(const Path& cwd) {
631+
// Add BAZEL_TEST environment variable.
632+
if (!SetEnv(L"BAZEL_TEST", L"1")) {
633+
return false;
634+
}
635+
631636
for (const wchar_t* name :
632637
{L"TEST_INFRASTRUCTURE_FAILURE_FILE", L"TEST_LOGSPLITTER_OUTPUT_FILE",
633638
L"TEST_PREMATURE_EXIT_FILE", L"TEST_UNUSED_RUNFILES_LOG_FILE",

0 commit comments

Comments
 (0)