-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathct.bzl
131 lines (117 loc) · 3.79 KB
/
ct.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
load(
"//private:util.bzl",
_additional_file_dest_relative_path = "additional_file_dest_relative_path",
)
load(
"//private:ct.bzl",
_code_paths = "code_paths",
_ct_test = "ct_test",
_sanitize_sname = "sanitize_sname",
)
load(
":erlang_bytecode.bzl",
"erlang_bytecode",
)
load(
":erlang_app.bzl",
"DEFAULT_TEST_ERLC_OPTS",
)
def additional_file_dest_relative_path(dep_label, f):
return _additional_file_dest_relative_path(dep_label, f)
def code_paths(ctx, dep):
return _code_paths(dep)
def sanitize_sname(s):
return _sanitize_sname(s)
def ct_suite(
name = "",
suite_name = "",
additional_hdrs = [],
additional_srcs = [],
erlc_opts = DEFAULT_TEST_ERLC_OPTS,
deps = [],
runtime_deps = [],
**kwargs):
if suite_name == "":
suite_name = name
erlang_bytecode(
name = "{}_beam_files".format(suite_name),
hdrs = native.glob(["include/*.hrl", "src/*.hrl"] + additional_hdrs),
srcs = ["test/{}.erl".format(suite_name)] + additional_srcs,
erlc_opts = erlc_opts,
dest = "test",
deps = [":test_erlang_app"] + deps,
testonly = True,
)
ct_suite_variant(
name = name,
suite_name = suite_name,
deps = deps,
runtime_deps = runtime_deps,
**kwargs
)
return suite_name
def ct_suite_variant(
name = "",
suite_name = "",
additional_beam = [],
data = [],
deps = [],
runtime_deps = [],
**kwargs):
if suite_name == "":
suite_name = name
data_dir_files = native.glob(["test/{}_data/**/*".format(suite_name)])
_ct_test(
shard_suite = Label("@rules_erlang//tools/shard_suite:shard_suite"),
coverdata_to_lcov = Label("@rules_erlang//tools/coverdata_to_lcov:coverdata_to_lcov"),
name = name,
suite_name = suite_name,
is_windows = select({
"@bazel_tools//src/conditions:host_windows": True,
"//conditions:default": False,
}),
compiled_suites = [":{}_beam_files".format(suite_name)] + additional_beam,
data = data_dir_files + data,
deps = [":test_erlang_app"] + deps + runtime_deps,
**kwargs
)
return suite_name
def ct_test(
name = None,
suite_name = None,
compiled_suites = None,
deps = [":test_erlang_app"],
shard_suite = Label("@rules_erlang//tools/shard_suite:shard_suite"),
coverdata_to_lcov = Label("@rules_erlang//tools/coverdata_to_lcov:coverdata_to_lcov"),
**kwargs):
if suite_name == None or suite_name == "":
suite_name = name
if compiled_suites == None:
compiled_suites = [":{}_beam_files".format(suite_name)]
_ct_test(
name = name,
suite_name = suite_name,
compiled_suites = compiled_suites,
deps = deps,
shard_suite = shard_suite,
coverdata_to_lcov = coverdata_to_lcov,
is_windows = select({
"@bazel_tools//src/conditions:host_windows": True,
"//conditions:default": False,
}),
**kwargs
)
def assert_suites(suite_names, suite_files = None):
if suite_files == None:
suite_files = native.glob(["test/**/*_SUITE.erl"])
for f in suite_files:
sn = f.rpartition("/")[-1].replace(".erl", "")
if not sn in suite_names:
fail("A bazel rule has not been defined for {} (expected {} in {})".format(f, sn, suite_names))
def assert_suites2(suite_files = None):
if suite_files == None:
suite_files = native.glob(["test/**/*_SUITE.erl"])
for f in suite_files:
sn = f.rpartition("/")[-1].replace(".erl", "")
if not sn in native.existing_rules():
fail("A bazel rule has not been defined for {}".format(f))