aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/py
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2018-02-08 07:50:09 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-08 07:52:09 -0800
commitd7b6a7790eb2f1fb25616c3f76b9ef04d636c979 (patch)
tree29bb12bd223321a8d1d96e55273e04ff49e3e9fa /src/test/py
parent45c11fed32238ca0741028a7c9690281479c70cc (diff)
java,runfiles: fix tests with TEST_SRCDIR
Update //src/test/py/bazel:runfiles_test to test that the Java (and Python) runfiles libraries do NOT pick up TEST_SRCDIR from their environment. See https://bazel-review.googlesource.com/c/bazel/+/37190 See https://github.com/bazelbuild/bazel/issues/4598 Change-Id: I06eb50c8cb4c93a331e51cd38ebdd7c1bcf38bba PiperOrigin-RevId: 184994372
Diffstat (limited to 'src/test/py')
-rw-r--r--src/test/py/bazel/runfiles_test.py9
-rw-r--r--src/test/py/bazel/testdata/runfiles_test/foo/runfiles.py18
2 files changed, 23 insertions, 4 deletions
diff --git a/src/test/py/bazel/runfiles_test.py b/src/test/py/bazel/runfiles_test.py
index ca3cc0b5b7..abe23d078f 100644
--- a/src/test/py/bazel/runfiles_test.py
+++ b/src/test/py/bazel/runfiles_test.py
@@ -56,12 +56,14 @@ class RunfilesTest(test_base.TestBase):
self.assertTrue(os.path.exists(bin_path))
- exit_code, stdout, stderr = self.RunProgram([bin_path])
+ exit_code, stdout, stderr = self.RunProgram(
+ [bin_path], env_add={"TEST_SRCDIR": "__ignore_me__"})
self.AssertExitCode(exit_code, 0, stderr)
if len(stdout) != 2:
self.fail("stdout: %s" % stdout)
self.assertEqual(stdout[0], "Hello Java Foo!")
six.assertRegex(self, stdout[1], "^rloc=.*/foo/datadep/hello.txt")
+ self.assertNotIn("__ignore_me__", stdout[1])
with open(stdout[1].split("=", 1)[1], "r") as f:
lines = [l.strip() for l in f.readlines()]
if len(lines) != 1:
@@ -96,14 +98,17 @@ class RunfilesTest(test_base.TestBase):
self.assertTrue(os.path.exists(bin_path))
- exit_code, stdout, stderr = self.RunProgram([bin_path])
+ exit_code, stdout, stderr = self.RunProgram(
+ [bin_path], env_add={"TEST_SRCDIR": "__ignore_me__"})
self.AssertExitCode(exit_code, 0, stderr)
if len(stdout) < 4:
self.fail("stdout: %s" % stdout)
self.assertEqual(stdout[0], "Hello Python Foo!")
six.assertRegex(self, stdout[1], "^rloc=.*/foo/datadep/hello.txt")
+ self.assertNotIn("__ignore_me__", stdout[1])
self.assertEqual(stdout[2], "Hello Python Bar!")
six.assertRegex(self, stdout[3], "^rloc=.*/bar/bar-py-data.txt")
+ self.assertNotIn("__ignore_me__", stdout[3])
with open(stdout[1].split("=", 1)[1], "r") as f:
lines = [l.strip() for l in f.readlines()]
diff --git a/src/test/py/bazel/testdata/runfiles_test/foo/runfiles.py b/src/test/py/bazel/testdata/runfiles_test/foo/runfiles.py
index 6b2ba94c4e..6d5493f561 100644
--- a/src/test/py/bazel/testdata/runfiles_test/foo/runfiles.py
+++ b/src/test/py/bazel/testdata/runfiles_test/foo/runfiles.py
@@ -32,6 +32,15 @@ def ChildBinaryName(lang):
return "foo_ws/bar/bar-%s" % lang
+def SplitToLines(stdouterr):
+ if isinstance(stdouterr, bytes):
+ # Python3's communicate() returns bytes.
+ return [l.strip() for l in stdouterr.decode().split("\n")]
+ else:
+ # Python2's communicate() returns str.
+ return [l.strip() for l in stdouterr.split("\n")]
+
+
def main():
print("Hello Python Foo!")
r = runfiles.Create()
@@ -49,8 +58,13 @@ def main():
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
- for e in p.communicate():
- print(e)
+ out, err = p.communicate()
+ out = SplitToLines(out)
+ if len(out) >= 2:
+ print(out[0]) # e.g. "Hello Python Bar!"
+ print(out[1]) # e.g. "rloc=/tmp/foo_ws/bar/bar-py-data.txt"
+ else:
+ raise Exception("ERROR: error running bar-py: %s" % SplitToLines(err))
if __name__ == "__main__":