aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell
diff options
context:
space:
mode:
authorGravatar juliexxia <juliexxia@google.com>2018-01-12 18:05:46 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-12 18:07:55 -0800
commit07c4e3648e3b7a521b6706ffc5cbcdeca1ebf4e1 (patch)
tree1c7f4fdec231146e25ef4efc71f91a7da344adc5 /src/test/shell
parentb178e89e9ec079ecde901e4fca113c88e8aad317 (diff)
Introduce the blaze cquery command as the new ui for configurable query.
before: blaze build --nobuild //foo --experimental_post_build_query="deps(//foo)" after: blaze cquery "deps(//foo)" pros of ui change: - more concise - assumes query expression targets == targets to be built (but allows for flexibility through --top_level_targets flag) - separate from build command - cquery command recognizes query options, build options, and its own unique set of options cons of ui change: - adds another command to blaze - recognizes options that don't actually work yet -> requires more option validation RELNOTES: None PiperOrigin-RevId: 181816980
Diffstat (limited to 'src/test/shell')
-rwxr-xr-xsrc/test/shell/integration/configured_query_test.sh102
1 files changed, 91 insertions, 11 deletions
diff --git a/src/test/shell/integration/configured_query_test.sh b/src/test/shell/integration/configured_query_test.sh
index 240beaac76..6a45a89b0f 100755
--- a/src/test/shell/integration/configured_query_test.sh
+++ b/src/test/shell/integration/configured_query_test.sh
@@ -14,7 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# configured_query_test.sh: integration tests for bazel configured query
+# configured_query_test.sh: integration tests for bazel configured query.
+# This tests the command line ui of configured query while
+# ConfiguredTargetQueryTest tests its internal functionality.
# Load the test setup defined in the parent directory
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -26,22 +28,48 @@ add_to_bazelrc "build --package_path=%workspace%"
#### TESTS #############################################################
function test_basic_query() {
- rm -rf maple
- mkdir -p maple
- cat > maple/BUILD <<EOF
+ rm -rf maple
+ mkdir -p maple
+ cat > maple/BUILD <<EOF
sh_library(name='maple', deps=[':japanese'])
sh_library(name='japanese')
EOF
- bazel build --nobuild //maple \
- --experimental_post_build_query='deps(//maple)' > output 2>"$TEST_log" \
- || fail "Expected success"
- cat output >> "$TEST_log"
+ bazel cquery 'deps(//maple)' > output 2>"$TEST_log" || fail "Expected success"
assert_contains "//maple:maple" output
assert_contains "//maple:japanese" output
}
+function test_respects_selects() {
+ rm -rf ash
+ mkdir -p ash
+ cat > ash/BUILD <<EOF
+sh_library(
+ name = "ash",
+ deps = select({
+ ":excelsior": [":foo"],
+ ":americana": [":bar"],
+ }),
+)
+sh_library(name = "foo")
+sh_library(name = "bar")
+config_setting(
+ name = "excelsior",
+ values = {"define": "species=excelsior"},
+)
+config_setting(
+ name = "americana",
+ values = {"define": "species=americana"},
+)
+EOF
+
+ bazel cquery 'deps(//ash)' --define species=excelsior > output \
+ 2>"$TEST_log" || fail "Excepted success"
+ assert_contains "//ash:foo" output
+ assert_not_contains "//ash:bar" output
+}
+
function test_empty_results_printed() {
rm -rf redwood
mkdir -p redwood
@@ -51,15 +79,67 @@ sh_library(name='sequoia')
sh_library(name='sequoiadendron')
EOF
- bazel build --nobuild //redwood \
- --experimental_post_build_query='somepath(//redwood:sequoia,//redwood:sequoiadendron)' \
+ bazel cquery 'somepath(//redwood:sequoia,//redwood:sequoiadendron)' \
> output 2>"$TEST_log" || fail "Expected success"
expect_log "INFO: Empty query results"
- expect_not_log "//redwood:sequoiadendreon"
+ assert_not_contains "//redwood:sequoiadendreon" output
+}
+
+function test_universe_scope_specified() {
+ write_java_library_build
+
+ # The java_library rule has a host transition on its plugins attribute.
+ bazel cquery //pine:dep+//pine:plugin --universe_scope=//pine:my_java \
+ > output 2>"$TEST_log" || fail "Excepted success"
+ # Find the lines of output for //pine:plugin and //pine:dep.
+ PINE_HOST=$(grep "//pine:plugin" output)
+ PINE_TARGET=$(grep "//pine:dep" output)
+ # Trim to just configurations.
+ HOST_CONFIG=${PINE_HOST/"//pine:plugin"}
+ TARGET_CONFIG=${PINE_TARGET/"//pine:dep"}
+ # Ensure they are are not equal.
+ assert_not_equals $HOST_CONFIG $TARGET_CONFIG
}
+# This test ensures the known buggy behavior described at b/71905538 i.e. nodes
+# lingering from previous builds.
+# TODO(juliexxia): Remove this test once b/71905538 is fixed.
+function test_ghost_nodes_bug() {
+ write_java_library_build
+
+ # Create host-configured //pine:plugin node in this cquery
+ bazel cquery "deps(//pine:my_java)" || fail "Excepted success"
+ # This cquery should return target configured //pine:plugin but returns
+ # the host-configured target generated above.
+ bazel cquery //pine:dep+//pine:plugin \
+ > output 2>"$TEST_log" || fail "Excepted success"
+
+ # Find the lines of output for //pine:plugin and //pine:dep.
+ PLUGIN=$(grep "//pine:plugin" output)
+ DEP=$(grep "//pine:dep" output)
+ # Trim to just configurations.
+ PLUGIN_CONFIG=${PLUGIN/"//pine:plugin"}
+ DEP_CONFIG=${DEP/"//pine:dep"}
+ # Ensure they are are not equal (the buggy behavior).
+ assert_not_equals $PLUGIN_CONFIG $DEP_CONFIG
+}
+
+function write_java_library_build() {
+ rm -rf pine
+ mkdir -p pine
+ cat > pine/BUILD <<EOF
+java_library(
+ name = "my_java",
+ srcs = ['foo.java'],
+ deps = [":dep"],
+ plugins = [":plugin"]
+)
+java_library(name = "dep")
+java_plugin(name = "plugin")
+EOF
+}
function tear_down() {
bazel shutdown