aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java
diff options
context:
space:
mode:
authorGravatar Dmitry Lomov <dslomov@google.com>2016-06-22 19:04:28 +0000
committerGravatar Lukacs Berki <lberki@google.com>2016-06-23 11:10:20 +0000
commit3a8935c28d3407b893cd23edde5355fc2b688ba9 (patch)
tree377d760d07f5c61478431036f5bb02cac3dd14a3 /src/test/java
parent1fb9461b67ee49aa72a55a444aec006ee2594cee (diff)
Make intellij_info_tests work again.
-- MOS_MIGRATED_REVID=125592395
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl48
-rw-r--r--src/test/java/com/google/devtools/build/lib/ideinfo/skylarktests/intellij_info_tests.bzl27
-rw-r--r--src/test/java/com/google/devtools/build/lib/ideinfo/skylarktests/testing.bzl6
3 files changed, 54 insertions, 27 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl b/src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl
index 45719b8479..c3a62043b1 100644
--- a/src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl
+++ b/src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl
@@ -395,7 +395,7 @@ def build_java_toolchain_ide_info(target):
##### Main aspect function
-def _aspect_impl(target, ctx):
+def _aspect_impl_helper(target, ctx, for_test):
"""Aspect implementation function."""
rule_attrs = ctx.rule.attr
@@ -427,9 +427,12 @@ def _aspect_impl(target, ctx):
prerequisites = direct_dep_targets + runtime_dep_targets + list_omit_none(legacy_resource_target)
ide_info_text = set()
ide_resolve_files = set()
+ intellij_infos = dict()
for dep in prerequisites:
ide_info_text = ide_info_text | dep.intellij_info_files.ide_info_text
ide_resolve_files = ide_resolve_files | dep.intellij_info_files.ide_resolve_files
+ if for_test:
+ intellij_infos.update(dep.intellij_infos)
# Collect C-specific information
(c_rule_ide_info, c_ide_resolve_files) = build_c_rule_ide_info(target, ctx)
@@ -479,9 +482,13 @@ def _aspect_impl(target, ctx):
output = ctx.new_file(target.label.name + ".intellij-build.txt")
ctx.file_action(output, info.to_proto())
ide_info_text = ide_info_text | set([output])
+ if for_test:
+ intellij_infos[str(target.label)] = info
+ else:
+ intellij_infos = None
# Return providers.
- return struct(
+ return struct_omit_none(
intellij_aspect = True,
output_groups = {
"ide-info-text" : ide_info_text,
@@ -491,19 +498,30 @@ def _aspect_impl(target, ctx):
ide_info_text = ide_info_text,
ide_resolve_files = ide_resolve_files,
),
+ intellij_infos = intellij_infos,
export_deps = export_deps,
)
-intellij_info_aspect = aspect(
- attrs = {
- "_package_parser": attr.label(
- default = tool_label("//tools/android:PackageParser"),
- cfg = HOST_CFG,
- executable = True,
- allow_files = True,
- ),
- },
- attr_aspects = ALL_DEPS.label + ALL_DEPS.label_list + [LEGACY_RESOURCE_ATTR],
- fragments = ["cpp"],
- implementation = _aspect_impl,
-)
+def _aspect_impl(target, ctx):
+ return _aspect_impl_helper(target, ctx, for_test=False)
+
+def _test_aspect_impl(target, ctx):
+ return _aspect_impl_helper(target, ctx, for_test=True)
+
+def _aspect_def(impl):
+ return aspect(
+ attrs = {
+ "_package_parser": attr.label(
+ default = tool_label("//tools/android:PackageParser"),
+ cfg = HOST_CFG,
+ executable = True,
+ allow_files = True),
+ },
+ attr_aspects = ALL_DEPS.label + ALL_DEPS.label_list + [LEGACY_RESOURCE_ATTR],
+ fragments = ["cpp"],
+ implementation = impl,
+ )
+
+
+intellij_info_aspect = _aspect_def(_aspect_impl)
+intellij_info_test_aspect = _aspect_def(_test_aspect_impl)
diff --git a/src/test/java/com/google/devtools/build/lib/ideinfo/skylarktests/intellij_info_tests.bzl b/src/test/java/com/google/devtools/build/lib/ideinfo/skylarktests/intellij_info_tests.bzl
index 2722efdccd..1d7e34f27a 100644
--- a/src/test/java/com/google/devtools/build/lib/ideinfo/skylarktests/intellij_info_tests.bzl
+++ b/src/test/java/com/google/devtools/build/lib/ideinfo/skylarktests/intellij_info_tests.bzl
@@ -19,21 +19,22 @@ load(":skylarktests/testing.bzl",
"end_test",
"fail_test",
"assert_equals",
+ "assert_contains_all",
"assert_true")
-load(":intellij_info.bzl", "intellij_info_aspect")
+load(":intellij_info.bzl", "intellij_info_test_aspect")
def test(impl):
return rule(impl,
attrs = {
- 'targets' : attr.label_list(aspects = [intellij_info_aspect]),
+ 'targets' : attr.label_list(aspects = [intellij_info_test_aspect]),
},
test = True,
)
def infos_to_dict(infos):
- return { i.label : i for i in infos }
+ return infos
def _source_paths(env, artifact_locations):
for f in artifact_locations:
@@ -65,7 +66,7 @@ def _jar_expected_string(base, jar, interface_jar, source_jar):
def _test_simple_java_library(ctx):
env = start_test(ctx)
- infos = infos_to_dict(ctx.attr.targets[0].ide_infos)
+ infos = infos_to_dict(ctx.attr.targets[0].intellij_infos)
info = infos.get(str(ctx.label.relative(":simple1")))
if not info:
fail_test(env, "info not found")
@@ -81,8 +82,6 @@ def _test_simple_java_library(ctx):
assert_equals(env, "java_library", info.kind_string)
- assert_equals(env, [], info.dependencies)
-
assert_equals(env,
[ctx.label.package + "/skylarktests/testfiles/Simple1.java"],
_source_paths(env, info.java_rule_ide_info.sources))
@@ -109,15 +108,15 @@ def test_simple_java_library():
################################################
def _test_java_library_with_dependencies(ctx):
env = start_test(ctx)
- infos = infos_to_dict(ctx.attr.targets[0].ide_infos)
+ infos = infos_to_dict(ctx.attr.targets[0].intellij_infos)
info_simple = infos.get(str(ctx.label.relative(":simple2")))
info_complex = infos.get(str(ctx.label.relative(":complex2")))
assert_equals(env,
[ctx.label.package + "/skylarktests/testfiles/Complex2.java"],
_source_paths(env, info_complex.java_rule_ide_info.sources))
- assert_equals(env,
- [str(ctx.label.relative(":simple2"))],
- info_complex.dependencies)
+ assert_contains_all(env,
+ [str(ctx.label.relative(":simple2"))],
+ info_complex.dependencies)
end_test(env)
test_java_library_with_dependencies_rule_test = test(_test_java_library_with_dependencies)
@@ -132,6 +131,10 @@ def test_java_library_with_dependencies():
)
def skylark_tests():
- test_simple_java_library()
- test_java_library_with_dependencies()
+ test_simple_java_library()
+ test_java_library_with_dependencies()
+
+ native.test_suite(name = "skylark_tests",
+ tests = [":test_simple_java_library",
+ ":test_java_library_with_dependencies"])
diff --git a/src/test/java/com/google/devtools/build/lib/ideinfo/skylarktests/testing.bzl b/src/test/java/com/google/devtools/build/lib/ideinfo/skylarktests/testing.bzl
index 05f3e83320..f97472d5d6 100644
--- a/src/test/java/com/google/devtools/build/lib/ideinfo/skylarktests/testing.bzl
+++ b/src/test/java/com/google/devtools/build/lib/ideinfo/skylarktests/testing.bzl
@@ -38,6 +38,12 @@ def assert_equals(env, expected, actual):
if not expected == actual:
fail_test(env, "'%s' != '%s'" % (expected, actual))
+def assert_contains_all(env, expected, actual):
+ for e in expected:
+ if e not in actual:
+ fail_test(env, "'%s' is not in '%s'" % (e, actual))
+
+
def assert_true(env, condition, message):
if not condition:
fail_test(env, message)