Skip to content

Commit 69416a8

Browse files
hvadehrarules_java Copybara
authored andcommitted
Migrate the JavaStarlarkApiTest.testExposesJavaCommonProvider test to Starlark
The test is removed from Bazel and added in rules_java PiperOrigin-RevId: 734668871 Change-Id: I1e70b195712a28b3173f4299e6902b46753f59b8
1 parent 7ea6427 commit 69416a8

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

java/test/common/java_common_tests.bzl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for java_common APIs"""
22

33
load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
4+
load("@rules_testing//lib:truth.bzl", "matching")
45
load("@rules_testing//lib:util.bzl", "util")
56
load("//java:java_library.bzl", "java_library")
67
load("//java/common:java_common.bzl", "java_common")
@@ -232,6 +233,50 @@ def _test_compile_override_with_empty_bootclasspath_impl(env, target):
232233
"{}/custom-system".format(target.label.package),
233234
)])
234235

236+
def _test_exposes_java_info_as_provider(name):
237+
util.helper_target(
238+
java_library,
239+
name = name + "/dep",
240+
srcs = ["Dep.java"],
241+
)
242+
analysis_test(
243+
name = name,
244+
impl = _test_exposes_java_info_as_provider_impl,
245+
target = name + "/dep",
246+
)
247+
248+
def _test_exposes_java_info_as_provider_impl(env, target):
249+
java_info = target[java_common.provider]
250+
assert_java_info = java_info_subject.new(
251+
java_info,
252+
env.expect.meta.derive(
253+
format_str_kwargs = {
254+
"name": target.label.name,
255+
"package": target.label.package,
256+
},
257+
),
258+
)
259+
260+
assert_java_info.compilation_args().transitive_runtime_jars().contains_exactly([
261+
"{package}/lib{name}.jar",
262+
])
263+
assert_java_info.compilation_args().transitive_compile_time_jars().contains_exactly([
264+
"{package}/lib{name}-hjar.jar",
265+
])
266+
assert_java_info.compilation_args().full_compile_jars().contains_exactly([
267+
"{package}/lib{name}.jar",
268+
])
269+
assert_java_info.source_jars().contains_exactly_predicates([
270+
matching.file_basename_equals("dep-src.jar"),
271+
])
272+
273+
assert_output = assert_java_info.outputs().jars().singleton()
274+
assert_output.class_jar().short_path_equals("{package}/lib{name}.jar")
275+
assert_output.compile_jar().short_path_equals("{package}/lib{name}-hjar.jar")
276+
assert_output.source_jars().contains_exactly(["{package}/lib{name}-src.jar"])
277+
assert_output.jdeps().short_path_equals("{package}/lib{name}.jdeps")
278+
assert_output.compile_jdeps().short_path_equals("{package}/lib{name}-hjar.jdeps")
279+
235280
def java_common_tests(name):
236281
test_suite(
237282
name = name,
@@ -244,5 +289,6 @@ def java_common_tests(name):
244289
_test_compile_extend_compile_time_jdeps_rule_outputs,
245290
_test_compile_bootclasspath,
246291
_test_compile_override_with_empty_bootclasspath,
292+
_test_exposes_java_info_as_provider,
247293
],
248294
)

java/test/testutil/java_info_subject.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ def _new_java_outputs_collection_subject(java_outputs, meta):
6060

6161
def _new_java_outputs_subject(java_output, meta):
6262
public = struct(
63+
class_jar = lambda: subjects.file(java_output.class_jar, meta.derive("class_jar")),
6364
compile_jar = lambda: subjects.file(java_output.compile_jar, meta.derive("compile_jar")),
65+
source_jars = lambda: subjects.depset_file(java_output.source_jars if hasattr(java_output.source_jars, "to_list") else depset(java_output.source_jars), meta.derive("source_jars")),
66+
jdeps = lambda: subjects.file(java_output.jdeps, meta.derive("jdeps")),
67+
compile_jdeps = lambda: subjects.file(java_output.compile_jdeps, meta.derive("compile_jdeps")),
6468
)
6569
return public
6670

0 commit comments

Comments
 (0)