forked from bazelbuild/rules_java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava_test_tests.bzl
More file actions
83 lines (78 loc) · 2.55 KB
/
Copy pathjava_test_tests.bzl
File metadata and controls
83 lines (78 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""Tests for the java_test rule"""
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
load("@rules_testing//lib:truth.bzl", "matching", "subjects")
load("@rules_testing//lib:util.bzl", "util")
load("//java:java_library.bzl", "java_library")
load("//java:java_test.bzl", "java_test")
load("//test/java/testutil:rules/custom_java_info_rule.bzl", "custom_java_info_rule")
def _test_java_test_propagates_direct_native_libraries(name):
util.helper_target(
cc_library,
name = name + "/cclib",
srcs = ["z.cc"],
)
util.helper_target(
cc_binary,
name = name + "/native",
srcs = ["cc/x.cc"],
deps = [name + "/cclib"],
linkshared = 1,
linkstatic = 1,
)
util.helper_target(
java_library,
name = name + "/jl",
srcs = ["java/A.java"],
deps = [name + "/native"],
)
util.helper_target(
cc_binary,
name = name + "/ccl",
srcs = ["cc/x.cc"],
deps = [name + "/cclib"],
linkshared = 1,
linkstatic = 1,
)
util.helper_target(
custom_java_info_rule,
name = name + "/r",
output_jar = name + "-out.jar",
cc_dep = [name + "/ccl"],
dep = [name + "/jl"],
)
util.helper_target(
java_test,
name = name + "/binary",
srcs = ["java/C.java"],
deps = [name + "/r"],
main_class = "C",
)
analysis_test(
name = name,
impl = _test_java_test_propagates_direct_native_libraries_impl,
target = name + "/binary",
)
def _test_java_test_propagates_direct_native_libraries_impl(env, target):
executable = target[DefaultInfo].files_to_run.executable.short_path
assert_action = env.expect.that_target(target).action_generating(executable)
if assert_action.actual.substitutions:
# TemplateExpansion action on linux/mac
assert_jvm_flags = assert_action.substitutions().get(
"%jvm_flags%",
factory = lambda v, meta: subjects.collection([v], meta),
)
else:
# windows
assert_jvm_flags = assert_action.argv()
assert_jvm_flags.contains_predicate(
matching.str_matches("-Djava.library.path=${JAVA_RUNFILES}/*/test_java_test_propagates_direct_native_libraries"),
)
def java_test_tests(name):
test_suite(
name = name,
tests = [
_test_java_test_propagates_direct_native_libraries,
],
)