diff --git a/src/test/py/bazel/bazel_windows_test.py b/src/test/py/bazel/bazel_windows_test.py index fdfa31fcbda9f0..0e50fce6e6e93a 100644 --- a/src/test/py/bazel/bazel_windows_test.py +++ b/src/test/py/bazel/bazel_windows_test.py @@ -487,6 +487,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",