forked from junit-team/junit5-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
junit5.bzl
99 lines (87 loc) · 3.06 KB
/
junit5.bzl
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""External dependencies & java_junit5_test rule"""
JUNIT_JUPITER_GROUP_ID = "org.junit.jupiter"
JUNIT_JUPITER_ARTIFACT_ID_LIST = [
"junit-jupiter-api",
"junit-jupiter-engine",
"junit-jupiter-params",
]
JUNIT_PLATFORM_GROUP_ID = "org.junit.platform"
JUNIT_PLATFORM_ARTIFACT_ID_LIST = [
"junit-platform-commons",
"junit-platform-console",
"junit-platform-engine",
"junit-platform-launcher",
"junit-platform-suite-api",
]
JUNIT_EXTRA_DEPENDENCIES = [
("org.apiguardian", "apiguardian-api", "1.0.0"),
("org.opentest4j", "opentest4j", "1.1.1"),
]
def junit_jupiter_java_repositories(
version = "5.4.1"):
"""Imports dependencies for JUnit Jupiter"""
for artifact_id in JUNIT_JUPITER_ARTIFACT_ID_LIST:
native.maven_jar(
name = _format_maven_jar_name(JUNIT_JUPITER_GROUP_ID, artifact_id),
artifact = "%s:%s:%s" % (
JUNIT_JUPITER_GROUP_ID,
artifact_id,
version,
),
)
for t in JUNIT_EXTRA_DEPENDENCIES:
native.maven_jar(
name = _format_maven_jar_name(t[0], t[1]),
artifact = "%s:%s:%s" % t,
)
def junit_platform_java_repositories(
version = "1.4.1"):
"""Imports dependencies for JUnit Platform"""
for artifact_id in JUNIT_PLATFORM_ARTIFACT_ID_LIST:
native.maven_jar(
name = _format_maven_jar_name(JUNIT_PLATFORM_GROUP_ID, artifact_id),
artifact = "%s:%s:%s" % (
JUNIT_PLATFORM_GROUP_ID,
artifact_id,
version,
),
)
def java_junit5_test(name, srcs, test_class = None, deps = [], runtime_deps = [], **kwargs):
FILTER_KWARGS = [
"main_class",
"use_testrunner",
"args",
]
for arg in FILTER_KWARGS:
if arg in kwargs.keys():
kwargs.pop(arg)
junit_console_args = []
if test_class:
junit_console_args += ["--select-class", test_class]
else:
fail("must specific 'test_class'")
native.java_test(
name = name,
srcs = srcs,
use_testrunner = False,
main_class = "org.junit.platform.console.ConsoleLauncher",
args = junit_console_args,
deps = deps + [
_format_maven_jar_dep_name(JUNIT_JUPITER_GROUP_ID, artifact_id)
for artifact_id in JUNIT_JUPITER_ARTIFACT_ID_LIST
] + [
_format_maven_jar_dep_name(JUNIT_PLATFORM_GROUP_ID, "junit-platform-suite-api"),
] + [
_format_maven_jar_dep_name(t[0], t[1])
for t in JUNIT_EXTRA_DEPENDENCIES
],
runtime_deps = runtime_deps + [
_format_maven_jar_dep_name(JUNIT_PLATFORM_GROUP_ID, artifact_id)
for artifact_id in JUNIT_PLATFORM_ARTIFACT_ID_LIST
],
**kwargs
)
def _format_maven_jar_name(group_id, artifact_id):
return ("%s_%s" % (group_id, artifact_id)).replace(".", "_").replace("-", "_")
def _format_maven_jar_dep_name(group_id, artifact_id):
return "@%s//jar" % _format_maven_jar_name(group_id, artifact_id)