From 8cd35661eaea38b6b7650701ccf21dcaaace2f72 Mon Sep 17 00:00:00 2001 From: Cristin Donoso Date: Mon, 26 Feb 2024 02:17:07 -0800 Subject: [PATCH] [test][windows] Export BAZEL_TEST=1 on windows This was an oversight from when exporting BAZEL_TEST on Linux. fixes: https://github.com/bazelbuild/bazel/issues/21420 Closes #21444. PiperOrigin-RevId: 610338496 Change-Id: Icbbdc42b6ea92a2de2b0c558aea47a24493c9d8a --- src/test/py/bazel/bazel_windows_test.py | 34 +++++++++++++++++++++++++ tools/test/windows/tw.cc | 5 ++++ 2 files changed, 39 insertions(+) diff --git a/src/test/py/bazel/bazel_windows_test.py b/src/test/py/bazel/bazel_windows_test.py index f7a5eb5e308cc5..2a16b7cd3473ca 100644 --- a/src/test/py/bazel/bazel_windows_test.py +++ b/src/test/py/bazel/bazel_windows_test.py @@ -471,6 +471,40 @@ def testZipUndeclaredTestOutputs(self): self.assertTrue(os.path.exists(output_file)) self.assertFalse(os.path.exists(output_zip)) + def testBazelForwardsRequiredEnvVariable(self): + self.CreateWorkspaceWithDefaultRepos('WORKSPACE') + self.ScratchFile( + 'BUILD', + [ + 'sh_test(', + ' name = "foo_test",', + ' srcs = ["foo.sh"],', + ')', + '', + ], + ) + self.ScratchFile( + 'foo.sh', + [ + """ + if [[ "$BAZEL_TEST" == "1" ]]; then + exit 0 + else + echo "BAZEL_TEST is not set to 1" + exit 1 + fi + """, + ], + ) + + exit_code, stdout, stderr = self.RunBazel( + [ + 'test', + '//:foo_test', + ], + ) + self.AssertExitCode(exit_code, 0, stderr, stdout) + def testTestShardStatusFile(self): self.CreateWorkspaceWithDefaultRepos('WORKSPACE') self.ScratchFile( diff --git a/tools/test/windows/tw.cc b/tools/test/windows/tw.cc index 0f21baf4b33449..a85ae2b697ce46 100644 --- a/tools/test/windows/tw.cc +++ b/tools/test/windows/tw.cc @@ -628,6 +628,11 @@ bool ExportGtestVariables(const Path& test_tmpdir) { } bool ExportMiscEnvvars(const Path& cwd) { + // Add BAZEL_TEST environment variable. + if (!SetEnv(L"BAZEL_TEST", L"1")) { + return false; + } + for (const wchar_t* name : {L"TEST_INFRASTRUCTURE_FAILURE_FILE", L"TEST_LOGSPLITTER_OUTPUT_FILE", L"TEST_PREMATURE_EXIT_FILE", L"TEST_UNUSED_RUNFILES_LOG_FILE",