Skip to content

Commit

Permalink
Update cquery integration tests to use a custom Starlark rule.
Browse files Browse the repository at this point in the history
This insulates the tests from changes to the implementation of Java rules.

PiperOrigin-RevId: 332254659
  • Loading branch information
katre authored and Yannic committed Oct 5, 2020
1 parent 8268521 commit cb7f093
Showing 1 changed file with 39 additions and 26 deletions.
65 changes: 39 additions & 26 deletions src/test/shell/integration/configured_query_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,68 +153,81 @@ EOF

function test_universe_scope_specified() {
local -r pkg=$FUNCNAME
write_java_library_build $pkg
write_test_targets $pkg

# The java_library rule has a host transition on its plugins attribute.
bazel cquery //$pkg:dep+//$pkg:plugin --universe_scope=//$pkg:my_java \
bazel cquery //$pkg:target+//$pkg:host --universe_scope=//$pkg:main \
> output 2>"$TEST_log" || fail "Excepted success"

# Find the lines of output for //$pkg:plugin and //$pkg:dep.
PKG_HOST=$(grep "//$pkg:plugin" output)
PKG_TARGET=$(grep "//$pkg:dep" output)
PKG_HOST=$(grep "//$pkg:host" output)
PKG_TARGET=$(grep "//$pkg:target" output)
# Trim to just configurations.
HOST_CONFIG=${PKG_HOST/"//$pkg:plugin"}
TARGET_CONFIG=${PKG_TARGET/"//$pkg:dep"}
HOST_CONFIG=${PKG_HOST/"//$pkg:host"}
TARGET_CONFIG=${PKG_TARGET/"//$pkg:target"}
# Ensure they are are not equal.
assert_not_equals $HOST_CONFIG $TARGET_CONFIG
}

function test_host_config_output() {
local -r pkg=$FUNCNAME
write_java_library_build $pkg
write_test_targets $pkg

bazel cquery //$pkg:plugin --universe_scope=//$pkg:my_java \
bazel cquery //$pkg:host --universe_scope=//$pkg:main \
> output 2>"$TEST_log" || fail "Excepted success"

assert_contains "//$pkg:plugin (HOST)" output
assert_contains "//$pkg:host (HOST)" output
}

function test_transitions_lite() {
local -r pkg=$FUNCNAME
write_java_library_build $pkg
write_test_targets $pkg

bazel cquery "deps(//$pkg:my_java)" --transitions=lite \
bazel cquery "deps(//$pkg:main)" --transitions=lite \
> output 2>"$TEST_log" || fail "Excepted success"

assert_contains "//$pkg:my_java" output
assert_contains "plugins#//$pkg:plugin#HostTransition" output
assert_contains "//$pkg:main" output
assert_contains "host_dep#//$pkg:host#HostTransition" output
}


function test_transitions_full() {
local -r pkg=$FUNCNAME
write_java_library_build $pkg
write_test_targets $pkg

bazel cquery "deps(//$pkg:my_java)" --transitions=full \
bazel cquery "deps(//$pkg:main)" --transitions=full \
> output 2>"$TEST_log" || fail "Excepted success"

assert_contains "//$pkg:my_java" output
assert_contains "plugins#//$pkg:plugin#HostTransition" output
assert_contains "//$pkg:main" output
assert_contains "host_dep#//$pkg:host#HostTransition" output
}

function write_java_library_build() {
local -r pkg=$1
function write_test_targets() {
mkdir -p $pkg
cat > $pkg/rule.bzl <<EOF
def _my_rule_impl(ctx):
pass
my_rule = rule(
implementation = _my_rule_impl,
attrs = {
"src_dep": attr.label(allow_single_file = True),
"target_dep": attr.label(cfg = 'target'),
"host_dep": attr.label(cfg = 'host'),
},
)
EOF
cat > $pkg/BUILD <<EOF
java_library(
name = "my_java",
srcs = ['foo.java'],
deps = [":dep"],
plugins = [":plugin"]
load(':rule.bzl', 'my_rule')
filegroup(name = "target")
filegroup(name = "host")
my_rule(
name = "main",
src_dep = "file.txt",
target_dep = ":target",
host_dep = ":host",
)
java_library(name = "dep")
java_plugin(name = "plugin")
EOF
touch $pkg/file.txt
}

# TODO(gregce): --show_config_fragments and RequiredConfigFragmentsProvider
Expand Down

0 comments on commit cb7f093

Please sign in to comment.