Files
SwiftLint/Tests/BUILD
JP Simard 3c2f4e31c9 Shard GeneratedTests into parallel targets and refactor code generation (#6102)
Split the monolithic GeneratedTests target (242 test classes) into 10
sharded targets with ~25 tests each to enable parallel test execution.
Reduces test time from 85.4s to 36.7s (57% improvement) by running
shards concurrently. Most shards finish in 2-8s with 2 outliers at
30-37s.

The implementation automatically scales with new rules and provides
parallel test execution with improved code maintainability.
2025-06-19 22:20:17 +00:00

218 lines
4.8 KiB
Python

load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library", "swift_test")
load(":generated_tests.bzl", "generated_tests")
exports_files(["BUILD"])
copts = [
"-warnings-as-errors",
"-enable-upcoming-feature",
"ExistentialAny",
"-enable-upcoming-feature",
"ConciseMagicFile",
"-enable-upcoming-feature",
"ImportObjcForwardDeclarations",
"-enable-upcoming-feature",
"ForwardTrailingClosures",
"-enable-upcoming-feature",
"ImplicitOpenExistentials",
]
strict_concurrency_copts = [
"-Xfrontend",
"-strict-concurrency=complete",
]
targeted_concurrency_copts = [
"-Xfrontend",
"-strict-concurrency=targeted",
]
# CLITests
swift_library(
name = "CLITests.library",
testonly = True,
srcs = glob(["CLITests/**/*.swift"]),
module_name = "CLITests",
package_name = "SwiftLint",
deps = [
"//:SwiftLintFramework",
],
copts = copts + strict_concurrency_copts,
)
swift_test(
name = "CLITests",
visibility = ["//visibility:public"],
deps = [":CLITests.library"],
)
# MacroTests
swift_library(
name = "MacroTests.library",
testonly = True,
srcs = glob(["MacroTests/**/*.swift"]),
module_name = "MacroTests",
deps = [
"//:SwiftLintCoreMacrosLib",
"@SwiftSyntax//:SwiftSyntaxMacrosTestSupport_opt",
],
copts = copts + strict_concurrency_copts,
)
swift_test(
name = "MacroTests",
visibility = ["//visibility:public"],
deps = [":MacroTests.library"],
)
# TestHelpers
swift_library(
name = "TestHelpers",
testonly = True,
srcs = glob(["TestHelpers/**/*.swift"]),
module_name = "TestHelpers",
package_name = "SwiftLint",
deps = [
"//:SwiftLintFramework",
],
copts = copts + strict_concurrency_copts,
)
# BuiltInRulesTests
swift_library(
name = "BuiltInRulesTests.library",
testonly = True,
srcs = glob(
["BuiltInRulesTests/**/*.swift"],
exclude = [
"BuiltInRulesTests/Resources/**",
# Bazel doesn't support paths with spaces in them
"BuiltInRulesTests/FileNameNoSpaceRuleTests.swift",
],
),
module_name = "BuiltInRulesTests",
package_name = "SwiftLint",
deps = [
":TestHelpers",
],
copts = copts + strict_concurrency_copts,
)
swift_test(
name = "BuiltInRulesTests",
data = glob(
["BuiltInRulesTests/Resources/**"],
allow_empty = True,
# Bazel doesn't support paths with spaces in them
exclude = ["BuiltInRulesTests/Resources/FileNameNoSpaceRuleFixtures/**"],
),
visibility = ["//visibility:public"],
deps = [":BuiltInRulesTests.library"],
)
# FrameworkTests
swift_library(
name = "FrameworkTests.library",
testonly = True,
srcs = glob(
["FrameworkTests/**/*.swift"],
exclude = [
"FrameworkTests/Resources/**",
],
),
module_name = "FrameworkTests",
package_name = "SwiftLint",
deps = [
":TestHelpers",
],
copts = copts + strict_concurrency_copts,
)
swift_test(
name = "FrameworkTests",
data = glob(
["FrameworkTests/Resources/**"],
allow_empty = True,
),
visibility = ["//visibility:public"],
deps = [":FrameworkTests.library"],
)
# GeneratedTests
generated_tests(copts, strict_concurrency_copts)
# IntegrationTests
filegroup(
name = "TestSources",
srcs = glob(
["**/*.swift"],
exclude = ["**/Resources/**"],
),
visibility = ["//visibility:public"],
)
swift_library(
name = "IntegrationTests.library",
testonly = True,
srcs = ["IntegrationTests/IntegrationTests.swift"],
module_name = "IntegrationTests",
package_name = "SwiftLint",
deps = [
":TestHelpers",
],
copts = copts + targeted_concurrency_copts, # Set to strict once SwiftLintFramework is updated
)
swift_test(
name = "IntegrationTests",
data = [
"//:LintInputs",
"IntegrationTests/default_rule_configurations.yml"
],
visibility = ["//visibility:public"],
deps = [":IntegrationTests.library"],
)
# ExtraRulesTests
genrule(
name = "ExtraRulesLinuxMain",
outs = ["main.swift"],
cmd = """
echo "import XCTest
XCTMain([testCase(ExtraRulesTests.allTests)])" >> $(OUTS)
""",
)
swift_library(
name = "ExtraRulesTests.library",
testonly = True,
srcs = [
"ExtraRulesTests/ExtraRulesTests.swift",
] + select({
"@platforms//os:linux": [":ExtraRulesLinuxMain"],
"//conditions:default": [],
}),
module_name = "ExtraRulesTests",
package_name = "SwiftLint",
deps = [
":TestHelpers",
],
copts = copts + strict_concurrency_copts,
)
swift_test(
name = "ExtraRulesTests",
visibility = ["//visibility:public"],
deps = [
":ExtraRulesTests.library",
],
)