aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2017-12-11 06:27:47 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-11 06:29:18 -0800
commit373dcf941d979c1bb2d3c4f95d0c02616d488721 (patch)
treec5c225c5911a938b783b0d6b958d84e159dc0033 /src/test
parent30f6d44ff99cc60446e6ae1f7d4c9818351b918d (diff)
Windows Launcher: Fix argument passing
Make sure the actual binary recieves exactly the same argument passed to Windows exe launcher. Fixed https://github.com/bazelbuild/bazel/issues/4001 Change-Id: I5db2d7c2f78de8865abc04a2d5b65d69685d43db PiperOrigin-RevId: 178610493
Diffstat (limited to 'src/test')
-rw-r--r--src/test/py/bazel/launcher_test.py84
1 files changed, 63 insertions, 21 deletions
diff --git a/src/test/py/bazel/launcher_test.py b/src/test/py/bazel/launcher_test.py
index eb4fefb948..42d6efc600 100644
--- a/src/test/py/bazel/launcher_test.py
+++ b/src/test/py/bazel/launcher_test.py
@@ -188,6 +188,30 @@ class LauncherTest(test_base.TestBase):
exit_code, _, stderr = self.RunBazel(['test', '//foo:test'] + launcher_flag)
self.AssertExitCode(exit_code, 0, stderr)
+ def _buildAndCheckArgumentPassing(self, package, target_name):
+ exit_code, stdout, stderr = self.RunBazel(['info', 'bazel-bin'])
+ self.AssertExitCode(exit_code, 0, stderr)
+ bazel_bin = stdout[0]
+
+ exit_code, _, stderr = self.RunBazel([
+ 'build', '--windows_exe_launcher=1',
+ '//%s:%s' % (package, target_name)
+ ])
+ self.AssertExitCode(exit_code, 0, stderr)
+
+ bin_suffix = '.exe' if self.IsWindows() else ''
+ bin1 = os.path.join(bazel_bin, package, '%s%s' % (target_name, bin_suffix))
+ self.assertTrue(os.path.exists(bin1))
+ self.assertTrue(
+ os.path.isdir(
+ os.path.join(bazel_bin, '%s/%s%s.runfiles' % (package, target_name,
+ bin_suffix))))
+
+ arguments = ['a', 'a b', '"b"', 'C:\\a\\b\\', '"C:\\a b\\c\\"']
+ exit_code, stdout, stderr = self.RunProgram([bin1] + arguments)
+ self.AssertExitCode(exit_code, 0, stderr)
+ self.assertEqual(stdout, arguments)
+
def testJavaBinaryLauncher(self):
self.ScratchFile('WORKSPACE')
self.ScratchFile('foo/BUILD', [
@@ -223,6 +247,27 @@ class LauncherTest(test_base.TestBase):
self._buildJavaTargets(bazel_bin, ['--windows_exe_launcher=1'], '.exe'
if self.IsWindows() else '')
+ def testJavaBinaryArgumentPassing(self):
+ self.ScratchFile('WORKSPACE')
+ self.ScratchFile('foo/BUILD', [
+ 'java_binary(',
+ ' name = "bin",',
+ ' srcs = ["Main.java"],',
+ ' main_class = "Main",',
+ ')',
+ ])
+ self.ScratchFile('foo/Main.java', [
+ 'public class Main {',
+ ' public static void main(String[] args) {'
+ ' for (String arg : args) {',
+ ' System.out.println(arg);',
+ ' }'
+ ' }',
+ '}',
+ ])
+
+ self._buildAndCheckArgumentPassing('foo', 'bin')
+
def testShBinaryLauncher(self):
self.ScratchFile('WORKSPACE')
self.ScratchFile(
@@ -294,26 +339,7 @@ class LauncherTest(test_base.TestBase):
])
os.chmod(foo_sh, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
- exit_code, stdout, stderr = self.RunBazel(['info', 'bazel-bin'])
- self.AssertExitCode(exit_code, 0, stderr)
- bazel_bin = stdout[0]
-
- exit_code, _, stderr = self.RunBazel(
- ['build', '--windows_exe_launcher=1', '//foo:bin'])
- self.AssertExitCode(exit_code, 0, stderr)
-
- bin_suffix = '.exe' if self.IsWindows() else ''
-
- bin1 = os.path.join(bazel_bin, 'foo', 'bin%s' % bin_suffix)
- self.assertTrue(os.path.exists(bin1))
- self.assertTrue(
- os.path.isdir(
- os.path.join(bazel_bin, 'foo/bin%s.runfiles' % bin_suffix)))
-
- arguments = ['a', 'a b', '"b"', 'C:\\a\\b\\', '"C:\\a b\\c\\"']
- exit_code, stdout, stderr = self.RunProgram([bin1] + arguments)
- self.AssertExitCode(exit_code, 0, stderr)
- self.assertEqual(stdout, arguments)
+ self._buildAndCheckArgumentPassing('foo', 'bin')
def testPyBinaryLauncher(self):
self.ScratchFile('WORKSPACE')
@@ -376,6 +402,22 @@ class LauncherTest(test_base.TestBase):
self._buildPyTargets(bazel_bin, ['--windows_exe_launcher=1'], '.exe'
if self.IsWindows() else '')
+ def testPyBinaryArgumentPassing(self):
+ self.ScratchFile('WORKSPACE')
+ self.ScratchFile('foo/BUILD', [
+ 'py_binary(',
+ ' name = "bin",',
+ ' srcs = ["bin.py"],',
+ ')',
+ ])
+ self.ScratchFile('foo/bin.py', [
+ 'import sys',
+ 'for arg in sys.argv[1:]:',
+ ' print(arg)',
+ ])
+
+ self._buildAndCheckArgumentPassing('foo', 'bin')
+
def testWindowsJavaExeLauncher(self):
# Skip this test on non-Windows platforms
if not self.IsWindows():
@@ -452,7 +494,7 @@ class LauncherTest(test_base.TestBase):
exit_code, stdout, stderr = self.RunProgram(
[binary, '--jvm_flag="--some_path="./a b/c""', print_cmd])
self.AssertExitCode(exit_code, 0, stderr)
- self.assertIn('--some_path="./a b/c"', stdout)
+ self.assertIn('"--some_path=\\"./a b/c\\""', stdout)
exit_code, stdout, stderr = self.RunProgram(
[binary, '--jvm_flags="--path1=a --path2=b"', print_cmd])