Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows, test wrapper: works with external tests #8090

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 51 additions & 40 deletions src/test/py/bazel/test_wrapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def _AssertUnexportsEnvvars(self, flag):
if not good or bad:
self._FailWithOutput(stderr + stdout)

def _AssertTestArgs(self, flag, expected):
def _AssertTestArgs(self, flag):
exit_code, bazel_bin, stderr = self.RunBazel(['info', 'bazel-bin'])
self.AssertExitCode(exit_code, 0, stderr)
bazel_bin = bazel_bin[0]
Expand All @@ -394,7 +394,25 @@ def _AssertTestArgs(self, flag, expected):
for line in stderr + stdout:
if line.startswith('arg='):
actual.append(str(line[len('arg='):]))
self.assertListEqual(expected, actual)
self.assertListEqual(
[
'(foo)',
# TODO(laszlocsomor): assert that "a b" is passed as one argument,
# not two, after https://github.com/bazelbuild/bazel/issues/6277
# is fixed.
'(a)',
'(b)',
# TODO(laszlocsomor): assert that the empty string argument is
# passed, after https://github.com/bazelbuild/bazel/issues/6276
# is fixed.
'(c d)',
'()',
'(bar)',
'(baz)',
'("x y")',
'("")',
'(qux)',
], actual)

def _AssertUndeclaredOutputs(self, flag):
exit_code, bazel_testlogs, stderr = self.RunBazel(
Expand Down Expand Up @@ -550,6 +568,35 @@ def _AssertXmlGeneratedByTestIsRetained(self, flag, split_xml=False):
xml_contents = [line.strip() for line in f.readlines()]
self.assertListEqual(xml_contents, ['leave this'])

# Test that the native test wrapper can run tests from external repositories.
# See https://github.com/bazelbuild/bazel/issues/8088
# Unfortunately as of 2019-04-18 the legacy test wrapper (test-setup.sh) also
# has this bug, but I (@laszlocsomor) work on enabling the native test wrapper
# by default so fixing the legacy one seems to make little sense.
def testRunningTestFromExternalRepo(self):
self.ScratchFile('WORKSPACE',
['local_repository(name = "a", path = "a")'])
self.ScratchFile('a/WORKSPACE')
self.ScratchFile('BUILD', ['py_test(name = "x", srcs = ["x.py"])'])
self.ScratchFile('a/BUILD', ['py_test(name = "x", srcs = ["x.py"])'])
self.ScratchFile('x.py')
self.ScratchFile('a/x.py')

for flag in ['--legacy_external_runfiles', '--nolegacy_external_runfiles']:
for target in ['//:x', '@a//:x']:
exit_code, _, stderr = self.RunBazel([
'test',
'-t-',
'--incompatible_windows_native_test_wrapper',
'--test_output=errors',
'--verbose_failures',
flag,
target,
])
self.AssertExitCode(exit_code, 0,
['flag=%s' % flag,
'target=%s' % target] + stderr)

def testTestExecutionWithTestSetupSh(self):
self._CreateMockWorkspace()
flag = '--noincompatible_windows_native_test_wrapper'
Expand All @@ -559,24 +606,7 @@ def testTestExecutionWithTestSetupSh(self):
self._AssertRunfiles(flag)
self._AssertShardedTest(flag)
self._AssertUnexportsEnvvars(flag)
self._AssertTestArgs(
flag,
[
'(foo)',
# If https://github.com/bazelbuild/bazel/issues/6277 is ever fixed,
# then assert that (a b) is one argument.
'(a)',
'(b)',
# If https://github.com/bazelbuild/bazel/issues/6276 is ever fixed,
# then assert that there's an empty argument before (c d).
'(c d)',
'()',
'(bar)',
'(baz)',
'("x y")',
'("")',
'(qux)',
])
self._AssertTestArgs(flag)
self._AssertUndeclaredOutputs(flag)
self._AssertUndeclaredOutputsAnnotations(flag)
self._AssertXmlGeneration(flag, split_xml=False)
Expand All @@ -593,26 +623,7 @@ def testTestExecutionWithTestWrapperExe(self):
self._AssertRunfiles(flag)
self._AssertShardedTest(flag)
self._AssertUnexportsEnvvars(flag)
self._AssertTestArgs(
flag,
[
'(foo)',
# TODO(laszlocsomor): assert that "a b" is passed as one argument,
# not two, after https://github.com/bazelbuild/bazel/issues/6277
# is fixed.
'(a)',
'(b)',
# TODO(laszlocsomor): assert that the empty string argument is
# passed, after https://github.com/bazelbuild/bazel/issues/6276
# is fixed.
'(c d)',
'()',
'(bar)',
'(baz)',
'("x y")',
'("")',
'(qux)',
])
self._AssertTestArgs(flag)
self._AssertUndeclaredOutputs(flag)
self._AssertUndeclaredOutputsAnnotations(flag)
self._AssertXmlGeneration(flag, split_xml=False)
Expand Down
11 changes: 8 additions & 3 deletions tools/test/windows/tw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1029,10 +1029,16 @@ inline bool GetWorkspaceName(std::wstring* result) {
return GetEnv(L"TEST_WORKSPACE", result) && !result->empty();
}

inline void StripLeadingDotSlash(std::wstring* s) {
inline void ComputeRunfilePath(const std::wstring& test_workspace,
std::wstring* s) {
if (s->size() >= 2 && (*s)[0] == L'.' && (*s)[1] == L'/') {
s->erase(0, 2);
}
if (s->find(L"external/") == 0) {
s->erase(0, 9);
} else {
*s = test_workspace + L"/" + *s;
}
}

bool FindTestBinary(const Path& argv0, std::wstring test_path, Path* result) {
Expand All @@ -1058,8 +1064,7 @@ bool FindTestBinary(const Path& argv0, std::wstring test_path, Path* result) {
return false;
}

StripLeadingDotSlash(&test_path);
test_path = workspace + L"/" + test_path;
ComputeRunfilePath(workspace, &test_path);

std::string utf8_test_path;
uint32_t err;
Expand Down