forked from bazelbuild/rules_swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerated_header_tests.bzl
152 lines (137 loc) · 5.33 KB
/
generated_header_tests.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Copyright 2020 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for `swift_library.generated_header`."""
load("//test/rules:analysis_failure_test.bzl", "analysis_failure_test")
load(
"//test/rules:provider_test.bzl",
"make_provider_test_rule",
"provider_test",
)
private_deps_with_target_name_test = make_provider_test_rule(
config_settings = {
"//command_line_option:features": ["swift.add_target_name_to_output"],
},
)
def generated_header_test_suite(name, tags = []):
"""Test suite for `swift_library` generated headers.
Args:
name: The base name to be used in targets created by this macro.
tags: Additional tags to apply to each test.
"""
all_tags = [name] + tags
# Verify that the generated header by default gets an automatically
# generated name and is an output of the rule.
provider_test(
name = "{}_automatically_named_header_is_rule_output".format(name),
expected_files = [
"test/fixtures/generated_header/auto_header-Swift.h",
"*",
],
field = "files",
provider = "DefaultInfo",
tags = all_tags,
target_under_test = "//test/fixtures/generated_header:auto_header",
)
private_deps_with_target_name_test(
name = "{}_automatically_named_header_is_rule_output_with_target_name".format(name),
expected_files = [
"test/fixtures/generated_header/auto_header/auto_header-Swift.h",
"*",
],
field = "files",
provider = "DefaultInfo",
tags = all_tags,
target_under_test = "//test/fixtures/generated_header:auto_header",
)
# Verify that no generated header is created if the target doesn't request
# it.
provider_test(
name = "{}_no_header".format(name),
expected_files = [
"-test/fixtures/generated_header/no_header-Swift.h",
"*",
],
field = "files",
provider = "DefaultInfo",
tags = all_tags,
target_under_test = "//test/fixtures/generated_header:no_header",
)
# Verify that the explicit generated header is an output of the rule and
# that the automatically named one is *not*.
provider_test(
name = "{}_explicit_header".format(name),
expected_files = [
"test/fixtures/generated_header/SomeOtherName.h",
"-test/fixtures/generated_header/explicit_header-Swift.h",
"*",
],
field = "files",
provider = "DefaultInfo",
tags = all_tags,
target_under_test = "//test/fixtures/generated_header:explicit_header",
)
private_deps_with_target_name_test(
name = "{}_explicit_header_with_target_name".format(name),
expected_files = [
"test/fixtures/generated_header/explicit_header/SomeOtherName.h",
"-test/fixtures/generated_header/explicit_header-Swift.h",
"*",
],
field = "files",
provider = "DefaultInfo",
tags = all_tags,
target_under_test = "//test/fixtures/generated_header:explicit_header",
)
# Verify that the build fails to analyze if an invalid extension is used.
analysis_failure_test(
name = "{}_invalid_extension".format(name),
expected_message = "The generated header for a Swift module must have a '.h' extension",
tags = all_tags,
target_under_test = "//test/fixtures/generated_header:invalid_extension",
)
# Verify that the build analyzes if a path separator is used.
provider_test(
name = "{}_valid_path_separator".format(name),
expected_files = [
"test/fixtures/generated_header/Valid/Separator.h",
"*",
],
field = "files",
provider = "DefaultInfo",
tags = all_tags,
target_under_test = "//test/fixtures/generated_header:valid_path_separator",
)
private_deps_with_target_name_test(
name = "{}_valid_path_separator_with_target_name".format(name),
expected_files = [
"test/fixtures/generated_header/valid_path_separator/Valid/Separator.h",
"*",
],
field = "files",
provider = "DefaultInfo",
tags = all_tags,
target_under_test = "//test/fixtures/generated_header:valid_path_separator",
)
# Verify that the build fails if `generated_header_name` is set when
# `generates_header` is False.
analysis_failure_test(
name = "{}_fails_when_name_provided_but_generates_header_is_false".format(name),
expected_message = "'generated_header_name' may only be provided when 'generates_header' is True",
tags = all_tags,
target_under_test = "//test/fixtures/generated_header:invalid_attribute_combination",
)
native.test_suite(
name = name,
tags = all_tags,
)