From 7ad22bdeb065d26f941341cf2ad39a677ede1a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Donoso?= Date: Tue, 20 Feb 2024 21:10:48 -0500 Subject: [PATCH 1/6] [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 --- tools/test/windows/tw.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/test/windows/tw.cc b/tools/test/windows/tw.cc index 0f21baf4b33449..d240adf68b1e83 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("BAZEL_TEST", "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", From 68d10572a74ad311486989d11f1a719148ef3bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Donoso?= Date: Tue, 20 Feb 2024 23:33:15 -0500 Subject: [PATCH 2/6] [test][windows] Fix long char An oversight, test pass now --- tools/test/windows/tw.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/test/windows/tw.cc b/tools/test/windows/tw.cc index d240adf68b1e83..a85ae2b697ce46 100644 --- a/tools/test/windows/tw.cc +++ b/tools/test/windows/tw.cc @@ -629,7 +629,7 @@ bool ExportGtestVariables(const Path& test_tmpdir) { bool ExportMiscEnvvars(const Path& cwd) { // Add BAZEL_TEST environment variable. - if (!SetEnv("BAZEL_TEST", "1")) { + if (!SetEnv(L"BAZEL_TEST", L"1")) { return false; } From a960fd5cf6fe8150f8f7d9f6b3b85a2c106342c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Donoso?= Date: Wed, 21 Feb 2024 19:42:36 -0500 Subject: [PATCH 3/6] [test][windows] Check for BAZEL_TEST=1 env --- src/test/py/bazel/bazel_windows_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/py/bazel/bazel_windows_test.py b/src/test/py/bazel/bazel_windows_test.py index fdfa31fcbda9f0..6cb0cac8063ecb 100644 --- a/src/test/py/bazel/bazel_windows_test.py +++ b/src/test/py/bazel/bazel_windows_test.py @@ -165,6 +165,7 @@ def testWindowsEnvironmentVariablesSetting(self): self.assertNotIn('foo=bar1', result_in_lower_case) self.assertNotIn('foo=bar2', result_in_lower_case) self.assertIn('foo=bar3', result_in_lower_case) + seft.assertIn('bazel_test=1', result_in_lower_case) def testRunPowershellInAction(self): self.CreateWorkspaceWithDefaultRepos('WORKSPACE') From a9f846b990b079f8811b0d56f27461d7a88cc72b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Donoso?= Date: Wed, 21 Feb 2024 20:05:48 -0500 Subject: [PATCH 4/6] [test][windows] Fix typo in test --- src/test/py/bazel/bazel_windows_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/py/bazel/bazel_windows_test.py b/src/test/py/bazel/bazel_windows_test.py index 6cb0cac8063ecb..5180e11c8f1fbf 100644 --- a/src/test/py/bazel/bazel_windows_test.py +++ b/src/test/py/bazel/bazel_windows_test.py @@ -165,7 +165,7 @@ def testWindowsEnvironmentVariablesSetting(self): self.assertNotIn('foo=bar1', result_in_lower_case) self.assertNotIn('foo=bar2', result_in_lower_case) self.assertIn('foo=bar3', result_in_lower_case) - seft.assertIn('bazel_test=1', result_in_lower_case) + self.assertIn('bazel_test=1', result_in_lower_case) def testRunPowershellInAction(self): self.CreateWorkspaceWithDefaultRepos('WORKSPACE') From 908305172836c32da50819bac65fe70e0d99b311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Donoso?= Date: Wed, 21 Feb 2024 20:21:41 -0500 Subject: [PATCH 5/6] [test][windows] Create actual test that tries to read BAZEL_TEST The other approach wouldn't have worked. --- src/test/py/bazel/bazel_windows_test.py | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/test/py/bazel/bazel_windows_test.py b/src/test/py/bazel/bazel_windows_test.py index 5180e11c8f1fbf..11c1f71591d9de 100644 --- a/src/test/py/bazel/bazel_windows_test.py +++ b/src/test/py/bazel/bazel_windows_test.py @@ -165,7 +165,6 @@ def testWindowsEnvironmentVariablesSetting(self): self.assertNotIn('foo=bar1', result_in_lower_case) self.assertNotIn('foo=bar2', result_in_lower_case) self.assertIn('foo=bar3', result_in_lower_case) - self.assertIn('bazel_test=1', result_in_lower_case) def testRunPowershellInAction(self): self.CreateWorkspaceWithDefaultRepos('WORKSPACE') @@ -488,6 +487,34 @@ 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', + [ + 'echo "BAZEL_TEST=$BAZEL_TEST"', + ], + ) + + exit_code, stdout, stderr = self.RunBazel( + [ + 'test', + '//:foo_test', + ], + ) + self.AssertExitCode(exit_code, 0, stderr, stdout) + self.assertIn('BAZEL_TEST=1', '\n'.join(stdout)) + def testTestShardStatusFile(self): self.CreateWorkspaceWithDefaultRepos('WORKSPACE') self.ScratchFile( From 29bf1434582a590f6488f5047ef7af736fee86fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Donoso?= Date: Wed, 21 Feb 2024 22:01:02 -0500 Subject: [PATCH 6/6] [test][windows] Actually create correct test Now we correctly query for the env variable --- src/test/py/bazel/bazel_windows_test.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/py/bazel/bazel_windows_test.py b/src/test/py/bazel/bazel_windows_test.py index 11c1f71591d9de..316d7ec163bca1 100644 --- a/src/test/py/bazel/bazel_windows_test.py +++ b/src/test/py/bazel/bazel_windows_test.py @@ -502,7 +502,14 @@ def testBazelForwardsRequiredEnvVariable(self): self.ScratchFile( 'foo.sh', [ - 'echo "BAZEL_TEST=$BAZEL_TEST"', + ''' + if [[ "$BAZEL_TEST" == "1" ]]; then + exit 0 + else + echo "BAZEL_TEST is not set to 1" + exit 1 + fi + ''', ], ) @@ -513,7 +520,6 @@ def testBazelForwardsRequiredEnvVariable(self): ], ) self.AssertExitCode(exit_code, 0, stderr, stdout) - self.assertIn('BAZEL_TEST=1', '\n'.join(stdout)) def testTestShardStatusFile(self): self.CreateWorkspaceWithDefaultRepos('WORKSPACE')