Skip to content

Commit cd10d50

Browse files
fmeumcopybara-github
authored andcommitted
Fix --nozip_undeclared_test_outputs on Windows
Without this change, testing with `--nozip_undeclared_test_outputs` always fails with this error: ``` FATAL: MappedOutputFile(): CreateFileW() failed: (error: 3): The system cannot find the path specified. ``` Closes bazelbuild#16973. PiperOrigin-RevId: 494953454 Change-Id: I8338e897a9e4f4fdcd6dad511ee8e777182fefcd
1 parent ac504cb commit cd10d50

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

src/test/py/bazel/bazel_windows_test.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,60 @@ def testRunWithScriptPath(self):
397397
self.AssertExitCode(exit_code, 0, stderr)
398398
self.assertIn('Hello from test!', '\n'.join(stdout))
399399

400+
def testZipUndeclaredTestOutputs(self):
401+
self.CreateWorkspaceWithDefaultRepos('WORKSPACE')
402+
self.ScratchFile(
403+
'BUILD',
404+
[
405+
'sh_test(',
406+
' name = "foo_test",',
407+
' srcs = ["foo.sh"],',
408+
')',
409+
'',
410+
],
411+
)
412+
self.ScratchFile(
413+
'foo.sh',
414+
[
415+
'touch "$TEST_UNDECLARED_OUTPUTS_DIR/foo.txt"',
416+
],
417+
)
418+
419+
exit_code, stdout, stderr = self.RunBazel(['info', 'bazel-testlogs'])
420+
self.AssertExitCode(exit_code, 0, stderr)
421+
bazel_testlogs = stdout[0]
422+
423+
output_file = os.path.join(bazel_testlogs, 'foo_test/test.outputs/foo.txt')
424+
output_zip = os.path.join(
425+
bazel_testlogs, 'foo_test/test.outputs/outputs.zip'
426+
)
427+
428+
# Run the test with undeclared outputs zipping.
429+
exit_code, _, stderr = self.RunBazel(
430+
[
431+
'test',
432+
'--zip_undeclared_test_outputs',
433+
'//:foo_test',
434+
],
435+
)
436+
self.AssertExitCode(exit_code, 0, stderr)
437+
# FIXME: The Windows test runner does not delete the undeclared outputs
438+
# after zipping, which differs from the behavior on other platforms.
439+
self.assertTrue(os.path.exists(output_file))
440+
self.assertTrue(os.path.exists(output_zip))
441+
442+
# Run the test without undeclared outputs zipping.
443+
exit_code, _, stderr = self.RunBazel(
444+
[
445+
'test',
446+
'--nozip_undeclared_test_outputs',
447+
'//:foo_test',
448+
],
449+
)
450+
self.AssertExitCode(exit_code, 0, stderr)
451+
self.assertTrue(os.path.exists(output_file))
452+
self.assertFalse(os.path.exists(output_zip))
453+
400454

401455
if __name__ == '__main__':
402456
unittest.main()

tools/test/windows/tw.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,8 +1298,10 @@ bool StartSubprocess(const Path& path, const std::wstring& args,
12981298
}
12991299

13001300
bool ArchiveUndeclaredOutputs(const UndeclaredOutputs& undecl) {
1301-
if (undecl.root.Get().empty()) {
1302-
// TEST_UNDECLARED_OUTPUTS_DIR was undefined, there's nothing to archive.
1301+
if (undecl.root.Get().empty() || undecl.zip.Get().empty()) {
1302+
// TEST_UNDECLARED_OUTPUTS_DIR was undefined, so there's nothing to archive,
1303+
// or TEST_UNDECLARED_OUTPUTS_ZIP was undefined as
1304+
// --nozip_undeclared_test_outputs was specified.
13031305
return true;
13041306
}
13051307

0 commit comments

Comments
 (0)