Skip to content

Commit 73231cf

Browse files
committed
Add tests
1 parent 0fa9632 commit 73231cf

File tree

6 files changed

+87
-15
lines changed

6 files changed

+87
-15
lines changed

swift/internal/compiling.bzl

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,10 @@ def compile_action_configs(
877877
swift_action_names.DUMP_AST,
878878
],
879879
configurators = [_dependencies_swiftmodules_configurator],
880-
not_features = [SWIFT_FEATURE_VFSOVERLAY],
880+
not_features = [
881+
[SWIFT_FEATURE_VFSOVERLAY],
882+
[SWIFT_FEATURE_USE_EXPLICIT_SWIFT_MODULE_MAP],
883+
],
881884
),
882885
swift_toolchain_config.action_config(
883886
actions = [
@@ -890,18 +893,6 @@ def compile_action_configs(
890893
],
891894
features = [SWIFT_FEATURE_VFSOVERLAY],
892895
),
893-
])
894-
895-
action_configs.extend([
896-
swift_toolchain_config.action_config(
897-
actions = [
898-
swift_action_names.COMPILE,
899-
swift_action_names.DERIVE_FILES,
900-
swift_action_names.DUMP_AST,
901-
],
902-
configurators = [_dependencies_swiftmodules_configurator],
903-
not_features = [SWIFT_FEATURE_USE_EXPLICIT_SWIFT_MODULE_MAP],
904-
),
905896
swift_toolchain_config.action_config(
906897
actions = [
907898
swift_action_names.COMPILE,

test/features_tests.bzl

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ file_prefix_xcode_remap_test = make_action_command_line_test_rule(
3838
},
3939
)
4040

41+
vfsoverlay_test = make_action_command_line_test_rule(
42+
config_settings = {
43+
"//command_line_option:features": [
44+
"swift.vfsoverlay",
45+
],
46+
},
47+
)
48+
49+
explicit_swift_module_map_test = make_action_command_line_test_rule(
50+
config_settings = {
51+
"//command_line_option:features": [
52+
"swift.use_explicit_swift_module_map",
53+
],
54+
},
55+
)
56+
4157
def features_test_suite(name):
4258
"""Test suite for various features.
4359
@@ -47,13 +63,16 @@ def features_test_suite(name):
4763
default_test(
4864
name = "{}_default_test".format(name),
4965
tags = [name],
50-
expected_argv = ["-emit-object"],
66+
expected_argv = [
67+
"-emit-object",
68+
"-I$(BIN_DIR)/test/fixtures/basic",
69+
],
5170
not_expected_argv = [
5271
"-file-prefix-map",
5372
"-Xwrapped-swift=-file-prefix-pwd-is-dot",
5473
],
5574
mnemonic = "SwiftCompile",
56-
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
75+
target_under_test = "@build_bazel_rules_swift//test/fixtures/basic:second",
5776
)
5877

5978
file_prefix_map_test(
@@ -95,3 +114,33 @@ def features_test_suite(name):
95114
mnemonic = "SwiftCompile",
96115
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
97116
)
117+
118+
vfsoverlay_test(
119+
name = "{}_vfsoverlay_test".format(name),
120+
tags = [name],
121+
expected_argv = [
122+
"-Xfrontend -vfsoverlay$(BIN_DIR)/test/fixtures/basic/second.vfsoverlay.yaml",
123+
"-I/__build_bazel_rules_swift/swiftmodules",
124+
],
125+
not_expected_argv = [
126+
"-I$(BIN_DIR)/test/fixtures/basic",
127+
"-explicit-swift-module-map-file",
128+
],
129+
mnemonic = "SwiftCompile",
130+
target_under_test = "@build_bazel_rules_swift//test/fixtures/basic:second",
131+
)
132+
133+
explicit_swift_module_map_test(
134+
name = "{}_explicit_swift_module_map_test".format(name),
135+
tags = [name],
136+
expected_argv = [
137+
"-Xfrontend -explicit-swift-module-map-file -Xfrontend $(BIN_DIR)/test/fixtures/basic/second.swift-explicit-module-map.json",
138+
],
139+
not_expected_argv = [
140+
"-I$(BIN_DIR)/test/fixtures/basic",
141+
"-I/__build_bazel_rules_swift/swiftmodules",
142+
"-Xfrontend -vfsoverlay$(BIN_DIR)/test/fixtures/basic/second.vfsoverlay.yaml",
143+
],
144+
mnemonic = "SwiftCompile",
145+
target_under_test = "@build_bazel_rules_swift//test/fixtures/basic:second",
146+
)

test/fixtures/basic/BUILD

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
load("//swift:swift.bzl", "swift_library")
2+
load("//test/fixtures:common.bzl", "FIXTURE_TAGS")
3+
4+
package(
5+
default_visibility = ["//test:__subpackages__"],
6+
)
7+
8+
licenses(["notice"])
9+
10+
swift_library(
11+
name = "first",
12+
srcs = ["first.swift"],
13+
tags = FIXTURE_TAGS,
14+
)
15+
16+
swift_library(
17+
name = "second",
18+
srcs = ["second.swift"],
19+
tags = FIXTURE_TAGS,
20+
deps = ["first"],
21+
)

test/fixtures/basic/first.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public func foo() -> String {
2+
return "foo"
3+
}

test/fixtures/basic/second.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import first
2+
3+
public func bar() -> String {
4+
return foo()
5+
}

test/rules/action_command_line_test.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def _action_command_line_test_impl(ctx):
7777
# end and look for arguments followed by a trailing space so that having
7878
# `-foo` in the expected list doesn't match `-foobar`, for example.
7979
concatenated_args = " ".join(action.argv) + " "
80+
bin_dir = analysistest.target_bin_dir_path(env)
8081
for expected in ctx.attr.expected_argv:
82+
expected = expected.replace("$(BIN_DIR)", bin_dir)
8183
if expected + " " not in concatenated_args and expected + "=" not in concatenated_args:
8284
unittest.fail(
8385
env,
@@ -88,6 +90,7 @@ def _action_command_line_test_impl(ctx):
8890
),
8991
)
9092
for not_expected in ctx.attr.not_expected_argv:
93+
not_expected = not_expected.replace("$(BIN_DIR)", bin_dir)
9194
if not_expected + " " in concatenated_args or not_expected + "=" in concatenated_args:
9295
unittest.fail(
9396
env,

0 commit comments

Comments
 (0)