aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2018-06-01 03:01:45 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-01 03:03:21 -0700
commit8b7709885c5fa4a88bff5440b5912113a1a157a0 (patch)
treeb03aa2586c226d7947e3ca09db3e623985a62479
parent242c3b82e4455c932587395c1e9bff4fd61b0162 (diff)
Windows,testing: add query regression test
This test could have prevented https://github.com/bazelbuild/bazel/issues/5300 Change-Id: I02e3b723958c81e0de80f2c2130b583ea4e7f40b Closes #5310. Change-Id: I02e3b723958c81e0de80f2c2130b583ea4e7f40b PiperOrigin-RevId: 198849437
-rw-r--r--src/test/py/bazel/BUILD7
-rw-r--r--src/test/py/bazel/query_test.py51
2 files changed, 58 insertions, 0 deletions
diff --git a/src/test/py/bazel/BUILD b/src/test/py/bazel/BUILD
index 532d78d8ad..200bf78d45 100644
--- a/src/test/py/bazel/BUILD
+++ b/src/test/py/bazel/BUILD
@@ -138,6 +138,13 @@ py_test(
}),
)
+py_test(
+ name = "query_test",
+ size = "medium",
+ srcs = ["query_test.py"],
+ deps = [":test_base"],
+)
+
test_suite(
name = "windows_tests",
tags = [
diff --git a/src/test/py/bazel/query_test.py b/src/test/py/bazel/query_test.py
new file mode 100644
index 0000000000..d5b37fa8fa
--- /dev/null
+++ b/src/test/py/bazel/query_test.py
@@ -0,0 +1,51 @@
+# pylint: disable=g-bad-file-header
+# Copyright 2018 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+from src.test.py.bazel import test_base
+
+
+class QueryTest(test_base.TestBase):
+
+ def testSimpleQuery(self):
+ self.ScratchFile('WORKSPACE')
+ self.ScratchFile('foo/BUILD', [
+ 'exports_files(["exported.txt"])',
+ 'filegroup(name = "top-rule", srcs = [":dep-rule"])',
+ 'filegroup(name = "dep-rule", srcs = ["src.txt"])',
+ ])
+ self.ScratchFile('foo/src.txt')
+ self.ScratchFile('foo/exported.txt')
+ self.ScratchFile('foo/non-exported.txt')
+ self._AssertQueryOutput('//foo:top-rule', '//foo:top-rule')
+ self._AssertQueryOutput('//foo:*', '//foo:top-rule', '//foo:dep-rule',
+ '//foo:src.txt', '//foo:exported.txt',
+ '//foo:BUILD')
+ self._AssertQueryOutput('deps(//foo:top-rule)', '//foo:top-rule',
+ '//foo:dep-rule', '//foo:src.txt')
+ self._AssertQueryOutput('deps(//foo:top-rule, 1)', '//foo:top-rule',
+ '//foo:dep-rule')
+
+ def _AssertQueryOutput(self, query_expr, *expected_results):
+ exit_code, stdout, stderr = self.RunBazel(['query', query_expr])
+ self.AssertExitCode(exit_code, 0, stderr)
+
+ stdout = sorted(x for x in stdout if x)
+ self.assertEqual(len(stdout), len(expected_results))
+ self.assertListEqual(stdout, sorted(expected_results))
+
+
+if __name__ == '__main__':
+ unittest.main()