Skip to content

Commit

Permalink
Separate built-in rule tests from framework tests (#5924)
Browse files Browse the repository at this point in the history
* Short names for test modules
* Lint plugins and `Package.swift` in integration tests
* Simplify and merge file groups in Bazel
* Move common functions to `TestHelpers`
  • Loading branch information
SimplyDanny authored Dec 30, 2024
1 parent bef8acf commit 15b2855
Show file tree
Hide file tree
Showing 227 changed files with 200 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .sourcery/GeneratedTests.stencil
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@testable import SwiftLintBuiltInRules
@testable import SwiftLintCore
import SwiftLintTestHelpers
import TestHelpers

// swiftlint:disable:next blanket_disable_command
// swiftlint:disable file_length single_test_class type_name
Expand Down
3 changes: 2 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ included:
- Tests
- Package.swift
excluded:
- Tests/SwiftLintFrameworkTests/Resources
- Tests/BuiltInRulesTests/Resources
- Tests/FrameworkTests/Resources

# Enabled/disabled rules
analyzer_rules:
Expand Down
5 changes: 3 additions & 2 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ cc_library(

filegroup(
name = "LintInputs",
srcs = glob(["Source/**/*.swift"]) + [
srcs = glob(["Plugins/**/*.swift", "Source/**/*.swift"]) + [
".swiftlint.yml",
"//Tests:SwiftLintFrameworkTestsData",
"Package.swift",
"//Tests:TestSources",
],
visibility = ["//Tests:__subpackages__"],
)
Expand Down
26 changes: 19 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,18 @@ let package = Package(
),
.target(name: "DyldWarningWorkaround"),
.target(
name: "SwiftLintTestHelpers",
name: "TestHelpers",
dependencies: [
"SwiftLintFramework"
],
path: "Tests/SwiftLintTestHelpers",
path: "Tests/TestHelpers",
swiftSettings: swiftFeatures
),
.testTarget(
name: "SwiftLintFrameworkTests",
name: "FrameworkTests",
dependencies: [
"SwiftLintFramework",
"SwiftLintTestHelpers",
"TestHelpers",
"SwiftLintCoreMacros",
],
exclude: [
Expand All @@ -136,26 +136,38 @@ let package = Package(
name: "GeneratedTests",
dependencies: [
"SwiftLintFramework",
"SwiftLintTestHelpers",
"TestHelpers",
],
swiftSettings: swiftFeatures
),
.testTarget(
name: "IntegrationTests",
dependencies: [
"SwiftLintFramework",
"SwiftLintTestHelpers",
"TestHelpers",
],
exclude: [
"default_rule_configurations.yml"
],
swiftSettings: swiftFeatures
),
.testTarget(
name: "BuiltInRulesTests",
dependencies: [
"SwiftLintBuiltInRules",
"SwiftLintFramework",
"TestHelpers",
],
exclude: [
"Resources",
],
swiftSettings: swiftFeatures
),
.testTarget(
name: "ExtraRulesTests",
dependencies: [
"SwiftLintFramework",
"SwiftLintTestHelpers",
"TestHelpers",
],
swiftSettings: swiftFeatures
),
Expand Down
76 changes: 49 additions & 27 deletions Tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,65 +55,78 @@ swift_test(
deps = [":MacroTests.library"],
)

# SwiftLintTestHelpers
# TestHelpers

swift_library(
name = "SwiftLintTestHelpers",
name = "TestHelpers",
testonly = True,
srcs = glob(["SwiftLintTestHelpers/**/*.swift"]),
module_name = "SwiftLintTestHelpers",
srcs = glob(["TestHelpers/**/*.swift"]),
module_name = "TestHelpers",
package_name = "SwiftLint",
deps = [
"//:SwiftLintFramework",
],
copts = copts,
)

# SwiftLintFrameworkTests
# BuiltInRulesTests

filegroup(
name = "SwiftLintFrameworkTestsSources",
swift_library(
name = "BuiltInRulesTests.library",
testonly = True,
srcs = glob(
["SwiftLintFrameworkTests/**/*.swift"],
["BuiltInRulesTests/**/*.swift"],
exclude = [
"SwiftLintFrameworkTests/Resources/**",
"BuiltInRulesTests/Resources/**",
# Bazel doesn't support paths with spaces in them
"SwiftLintFrameworkTests/FileNameNoSpaceRuleTests.swift",
"BuiltInRulesTests/FileNameNoSpaceRuleTests.swift",
],
),
module_name = "BuiltInRulesTests",
package_name = "SwiftLint",
deps = [
":TestHelpers",
],
copts = copts,
)

filegroup(
name = "SwiftLintFrameworkTestsData",
srcs = glob(
["**/**"],
swift_test(
name = "BuiltInRulesTests",
data = glob(
["BuiltInRulesTests/Resources/**"],
# Bazel doesn't support paths with spaces in them
exclude = ["SwiftLintFrameworkTests/Resources/FileNameNoSpaceRuleFixtures/**"],
exclude = ["BuiltInRulesTests/Resources/FileNameNoSpaceRuleFixtures/**"],
),
visibility = ["//visibility:public"],
deps = [":BuiltInRulesTests.library"],
)

# FrameworkTests

swift_library(
name = "SwiftLintFrameworkTests.library",
name = "FrameworkTests.library",
testonly = True,
srcs = [":SwiftLintFrameworkTestsSources"],
module_name = "SwiftLintFrameworkTests",
srcs = glob(
["FrameworkTests/**/*.swift"],
exclude = [
"FrameworkTests/Resources/**",
],
),
module_name = "FrameworkTests",
package_name = "SwiftLint",
deps = [
":SwiftLintTestHelpers",
":TestHelpers",
],
copts = copts,
)

swift_test(
name = "SwiftLintFrameworkTests",
name = "FrameworkTests",
data = glob(
["SwiftLintFrameworkTests/Resources/**"],
# Bazel doesn't support paths with spaces in them
exclude = ["SwiftLintFrameworkTests/Resources/FileNameNoSpaceRuleFixtures/**"],
["FrameworkTests/Resources/**"],
),
visibility = ["//visibility:public"],
deps = [":SwiftLintFrameworkTests.library"],
deps = [":FrameworkTests.library"],
)

# GeneratedTests
Expand All @@ -125,7 +138,7 @@ swift_library(
module_name = "GeneratedTests",
package_name = "SwiftLint",
deps = [
":SwiftLintTestHelpers",
":TestHelpers",
],
copts = copts,
)
Expand All @@ -138,14 +151,23 @@ swift_test(

# 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 = [
":SwiftLintTestHelpers",
":TestHelpers",
],
copts = copts,
)
Expand Down Expand Up @@ -184,7 +206,7 @@ swift_library(
module_name = "ExtraRulesTests",
package_name = "SwiftLint",
deps = [
":SwiftLintTestHelpers",
":TestHelpers",
],
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers

final class AttributesRuleTests: SwiftLintTestCase {
func testAttributesWithAlwaysOnSameLine() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers
import XCTest

final class BlanketDisableCommandRuleTests: SwiftLintTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers
import XCTest

final class ChildOptionSeverityConfigurationTests: SwiftLintTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers

final class CollectionAlignmentRuleTests: SwiftLintTestCase {
func testCollectionAlignmentWithAlignLeft() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers

final class ColonRuleTests: SwiftLintTestCase {
func testColonWithFlexibleRightSpace() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers
import XCTest

final class CompilerProtocolInitRuleTests: SwiftLintTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers
import XCTest

final class ComputedAccessorsOrderRuleTests: SwiftLintTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers

final class ConditionalReturnsOnNewlineRuleTests: SwiftLintTestCase {
func testConditionalReturnsOnNewlineWithIfOnly() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers
import XCTest

final class ContainsOverFirstNotNilRuleTests: SwiftLintTestCase {
Expand All @@ -25,6 +26,6 @@ final class ContainsOverFirstNotNilRuleTests: SwiftLintTestCase {
return []
}

return SwiftLintFrameworkTests.violations(example, config: config)
return TestHelpers.violations(example, config: config)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers
import XCTest

final class CyclomaticComplexityConfigurationTests: SwiftLintTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers

final class CyclomaticComplexityRuleTests: SwiftLintTestCase {
private lazy var complexSwitchExample: Example = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers
import XCTest

final class DeploymentTargetConfigurationTests: SwiftLintTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers
import XCTest

final class DeploymentTargetRuleTests: SwiftLintTestCase {
Expand Down Expand Up @@ -39,6 +40,6 @@ final class DeploymentTargetRuleTests: SwiftLintTestCase {
return []
}

return SwiftLintFrameworkTests.violations(example, config: config)
return TestHelpers.violations(example, config: config)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers

final class DiscouragedDirectInitRuleTests: SwiftLintTestCase {
private let baseDescription = DiscouragedDirectInitRule.description
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers

final class DiscouragedObjectLiteralRuleTests: SwiftLintTestCase {
func testWithImageLiteral() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers

final class EmptyCountRuleTests: SwiftLintTestCase {
func testEmptyCountWithOnlyAfterDot() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@testable import SwiftLintBuiltInRules
import SwiftLintFramework
import TestHelpers
import XCTest

final class ExpiringTodoRuleTests: SwiftLintTestCase {
Expand Down Expand Up @@ -142,7 +143,7 @@ final class ExpiringTodoRuleTests: SwiftLintTestCase {
}

private func violations(_ example: Example) -> [StyleViolation] {
SwiftLintFrameworkTests.violations(example, config: config)
TestHelpers.violations(example, config: config)
}

private func dateString(for status: ExpiringTodoRule.ExpiryViolationLevel) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers

final class ExplicitInitRuleTests: SwiftLintTestCase {
func testIncludeBareInit() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@testable import SwiftLintBuiltInRules
@testable import SwiftLintCore
import TestHelpers
import XCTest

final class ExplicitTypeInterfaceConfigurationTests: SwiftLintTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers

final class ExplicitTypeInterfaceRuleTests: SwiftLintTestCase {
func testLocalVars() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@testable import SwiftLintBuiltInRules
import TestHelpers
import XCTest

private let fixturesDirectory = "\(TestResources.path)/FileHeaderRuleFixtures"
private let fixturesDirectory = "\(TestResources.path())/FileHeaderRuleFixtures"

final class FileHeaderRuleTests: SwiftLintTestCase {
private func validate(fileName: String, using configuration: Any) throws -> [StyleViolation] {
Expand Down
Loading

0 comments on commit 15b2855

Please sign in to comment.