Skip to content

Commit

Permalink
Windows, test-wrapper: write undeclared outputs mf
Browse files Browse the repository at this point in the history
In this commit:

- implement logic to write the undeclared outputs
  manifest

- add directories to the undeclared outputs zip,
  as Bazel does on Linux

Still missing:

- writing the test output XML file
- running test under a coverage collector

See:
bazelbuild#5508
bazelbuild#6622

Change-Id: I7606114ad3e82da662bece63997d03d1d9c2fc8e
  • Loading branch information
laszlocsomor committed Nov 7, 2018
1 parent 79b9431 commit 8f867a3
Show file tree
Hide file tree
Showing 4 changed files with 375 additions and 48 deletions.
60 changes: 57 additions & 3 deletions src/test/py/bazel/test_wrapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import os
import unittest
import zipfile

from src.test.py.bazel import test_base

Expand Down Expand Up @@ -84,6 +85,10 @@ def _CreateMockWorkspace(self):
' srcs = ["testargs.bat"],',
' args = ["foo", "a b", "", "bar"],',
')',
'sh_test(',
' name = "undecl_test.bat",',
' srcs = ["undecl.bat"],',
')',
])
self.ScratchFile('foo/passing.bat', ['@exit /B 0'], executable=True)
self.ScratchFile('foo/failing.bat', ['@exit /B 1'], executable=True)
Expand Down Expand Up @@ -130,6 +135,21 @@ def _CreateMockWorkspace(self):
'@echo arg=(%9)',
],
executable=True)
self.ScratchFile(
'foo/undecl.bat',
[
'@echo OFF',
'set root=%TEST_UNDECLARED_OUTPUTS_DIR:/=\\%',
'md %root%\\out1',
'echo hello> %root%\\out1\\data1.txt',
'echo world>> %root%\\out1\\data1.txt',
'md %root%\\out2',
'echo Hallo> %root%\\out2\\data2.dat',
'echo Welt>> %root%\\out2\\data2.dat',
'md %root%\\empty\\sub',
],
executable=True)


def _AssertPassingTest(self, flag):
exit_code, _, stderr = self.RunBazel([
Expand Down Expand Up @@ -291,6 +311,41 @@ def _AssertTestArgs(self, flag, expected):
actual.append(str(line[len('arg='):]))
self.assertListEqual(expected, actual)

def _AssertUndeclaredOutputs(self, flag):
exit_code, bazel_testlogs, stderr = self.RunBazel(['info',
'bazel-testlogs'])
self.AssertExitCode(exit_code, 0, stderr)
bazel_testlogs = bazel_testlogs[0]

exit_code, stdout, stderr = self.RunBazel([
'test',
'//foo:undecl_test.bat',
'-t-',
'--test_output=errors',
flag,
])
self.AssertExitCode(exit_code, 0, stderr)

undecl_zip = os.path.join(bazel_testlogs, "foo", "undecl_test.bat",
"test.outputs", "outputs.zip")
self.assertTrue(os.path.exists(undecl_zip))
zip_content = {}
with zipfile.ZipFile(undecl_zip, 'r') as z:
zip_content = {f: z.getinfo(f).file_size for f in z.namelist()}
self.assertDictEqual(zip_content,
{'out1/': 0, 'out2/': 0, 'empty/': 0, 'empty/sub/': 0,
'out1/data1.txt': 14, 'out2/data2.dat': 13})

undecl_mf = os.path.join(bazel_testlogs, "foo", "undecl_test.bat",
"test.outputs_manifest", "MANIFEST")
self.assertTrue(os.path.exists(undecl_mf))
mf_content = []
with open(undecl_mf, "rt") as f:
mf_content = [line.strip() for line in f.readlines()]
self.assertListEqual(mf_content,
["out1/data1.txt\t14\ttext/plain",
"out2/data2.dat\t13\tapplication/octet-stream"])

def testTestExecutionWithTestSetupSh(self):
self._CreateMockWorkspace()
flag = '--noincompatible_windows_native_test_wrapper'
Expand Down Expand Up @@ -322,12 +377,10 @@ def testTestExecutionWithTestSetupSh(self):
'("\\\\\\")',
'(qux")'
])
self._AssertUndeclaredOutputs(flag)

def testTestExecutionWithTestWrapperExe(self):
self._CreateMockWorkspace()
# As of 2018-09-11, the Windows native test runner can run simple tests and
# export a few envvars, though it does not completely set up the test's
# environment yet.
flag = '--incompatible_windows_native_test_wrapper'
self._AssertPassingTest(flag)
self._AssertFailingTest(flag)
Expand Down Expand Up @@ -355,6 +408,7 @@ def testTestExecutionWithTestWrapperExe(self):
'(qux)',
'()'
])
self._AssertUndeclaredOutputs(flag)


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 8f867a3

Please sign in to comment.