diff --git a/src/test/py/bazel/BUILD b/src/test/py/bazel/BUILD index d5f59d680c4530..7aefb8c958057d 100644 --- a/src/test/py/bazel/BUILD +++ b/src/test/py/bazel/BUILD @@ -166,6 +166,12 @@ py_test( }), ) +py_test( + name = "printarg", + srcs = ["printarg.py"], + args = ["foo", "a b", "", "bar"], +) + py_test( name = "first_time_use_test", srcs = ["first_time_use_test.py"], diff --git a/src/test/py/bazel/test_wrapper_test.py b/src/test/py/bazel/test_wrapper_test.py index 7665f6810d93f3..d54c8a31c97499 100644 --- a/src/test/py/bazel/test_wrapper_test.py +++ b/src/test/py/bazel/test_wrapper_test.py @@ -80,10 +80,10 @@ def _CreateMockWorkspace(self): ' name = "unexported_test.bat",', ' srcs = ["unexported.bat"],', ')', - 'sh_test(', - ' name = "testargs_test.bat",', - ' srcs = ["testargs.bat"],', - ' args = ["foo", "a b", "", "bar"],', + 'py_test(', + ' name = "testargs",', + ' srcs = ["testargs.py"],', + r' args = ["foo", "a b", "", r"c\ d", "\'\'", "bar"],', ')', 'py_test(', ' name = "undecl_test",', @@ -135,18 +135,12 @@ def _CreateMockWorkspace(self): ], executable=True) self.ScratchFile( - 'foo/testargs.bat', + 'foo/testargs.py', [ - '@echo arg=(%~nx0)', # basename of $0 - '@echo arg=(%1)', - '@echo arg=(%2)', - '@echo arg=(%3)', - '@echo arg=(%4)', - '@echo arg=(%5)', - '@echo arg=(%6)', - '@echo arg=(%7)', - '@echo arg=(%8)', - '@echo arg=(%9)', + 'from __future__ import print_function', + 'import sys', + 'for a in sys.argv[1:]:', + ' print("arg=(%s)" % a)', ], executable=True) @@ -384,8 +378,12 @@ def _AssertTestArgs(self, flag, expected): bazel_bin = bazel_bin[0] exit_code, stdout, stderr = self.RunBazel([ + # --[no]incompatible_windows_style_arg_escaping affects what arguments + # the test receives. Run with --incompatible_windows_style_arg_escaping + # to test for future (as of 2019-04-05) behavior. + '--incompatible_windows_style_arg_escaping', 'test', - '//foo:testargs_test.bat', + '//foo:testargs', '-t-', '--test_output=all', '--test_arg=baz', @@ -568,10 +566,11 @@ def testTestExecutionWithTestSetupSh(self): self._AssertTestArgs( flag, [ - '(testargs_test.bat)', '(foo)', '(a)', '(b)', + '(c d)', + '()', '(bar)', # Note: debugging shows that test-setup.sh receives more-or-less # good arguments (let's ignore issues #6276 and #6277 for now), but @@ -582,10 +581,9 @@ def testTestExecutionWithTestSetupSh(self): # The test is here merely to guard against unwanted future change of # behavior. '(baz)', - '("\\"x)', - '(y\\"")', - '("\\\\\\")', - '(qux")' + '("x y")', + '("")', + '(qux)', ]) self._AssertUndeclaredOutputs(flag) self._AssertUndeclaredOutputsAnnotations(flag) @@ -606,7 +604,6 @@ def testTestExecutionWithTestWrapperExe(self): self._AssertTestArgs( flag, [ - '(testargs_test.bat)', '(foo)', # TODO(laszlocsomor): assert that "a b" is passed as one argument, # not two, after https://github.com/bazelbuild/bazel/issues/6277 @@ -616,12 +613,14 @@ def testTestExecutionWithTestWrapperExe(self): # 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")', - '("")', + '(x y)', + '()', '(qux)', - '()' ]) self._AssertUndeclaredOutputs(flag) self._AssertUndeclaredOutputsAnnotations(flag)