Introduce new CoreTests module (#6233)

It's supposed to test code from SwiftLintCore.
This commit is contained in:
Danny Mösch
2025-09-04 20:56:51 +02:00
committed by GitHub
parent 14652dbb8b
commit 087278c052
36 changed files with 87 additions and 26 deletions
+11
View File
@@ -146,6 +146,17 @@ let package = Package(
],
swiftSettings: swiftFeatures + strictConcurrency
),
.testTarget(
name: "CoreTests",
dependencies: [
"SwiftLintCore",
"TestHelpers",
],
exclude: [
"Resources",
],
swiftSettings: swiftFeatures + strictConcurrency
),
.testTarget(
name: "ExtraRulesTests",
dependencies: [
+29
View File
@@ -114,6 +114,35 @@ swift_test(
deps = [":BuiltInRulesTests.library"],
)
# CoreTests
swift_library(
name = "CoreTests.library",
package_name = "SwiftLint",
testonly = True,
srcs = glob(
["CoreTests/**/*.swift"],
exclude = [
"CoreTests/Resources/**",
],
),
copts = copts + strict_concurrency_copts,
module_name = "CoreTests",
deps = [
":TestHelpers",
],
)
swift_test(
name = "CoreTests",
data = glob(
["CoreTests/Resources/**"],
allow_empty = True,
),
visibility = ["//visibility:public"],
deps = [":CoreTests.library"],
)
# FrameworkTests
swift_library(
@@ -1,4 +1,5 @@
import SwiftLintCore
import TestHelpers
import XCTest
final class AccessControlLevelTests: SwiftLintTestCase {
@@ -1,5 +1,4 @@
@testable import SwiftLintCore
@testable import SwiftLintFramework
import XCTest
final class ConditionallySourceKitFreeTests: XCTestCase {
@@ -1,4 +1,5 @@
import SwiftLintFramework
import SwiftLintCore
import TestHelpers
import XCTest
final class DisableAllTests: SwiftLintTestCase {
@@ -1,4 +1,5 @@
import SwiftLintFramework
import SwiftLintCore
import TestHelpers
import XCTest
final class ExampleTests: SwiftLintTestCase {
@@ -1,4 +1,5 @@
import SourceKittenFramework
import TestHelpers
import XCTest
final class ExtendedNSStringTests: SwiftLintTestCase {
@@ -1,3 +1,4 @@
import TestHelpers
import XCTest
final class ExtendedStringTests: SwiftLintTestCase {
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import SwiftLintCore
import TestHelpers
import XCTest
final class LineEndingTests: SwiftLintTestCase {
@@ -1,4 +1,5 @@
@testable import SwiftLintCore
import TestHelpers
import XCTest
final class RegexConfigurationTests: SwiftLintTestCase {
@@ -1,4 +1,5 @@
import SwiftLintCore
import TestHelpers
import XCTest
final class RegionTests: SwiftLintTestCase {
@@ -1,24 +1,7 @@
import SwiftLintCore
import TestHelpers
import XCTest
struct RuleWithLevelsMock: Rule {
var configuration = SeverityLevelsConfiguration<Self>(warning: 2, error: 3)
static let description = RuleDescription(identifier: "severity_level_mock",
name: "",
description: "",
kind: .style,
deprecatedAliases: ["mock"])
init() { /* conformance for test */ }
init(configuration: Any) throws {
self.init()
try self.configuration.apply(configuration: configuration)
}
func validate(file _: SwiftLintFile) -> [StyleViolation] { [] }
}
final class RuleTests: SwiftLintTestCase {
fileprivate struct RuleMock1: Rule {
var configuration = SeverityConfiguration<Self>(.warning)
@@ -1,3 +1,4 @@
import TestHelpers
import XCTest
final class StringExtensionTests: SwiftLintTestCase {
@@ -1,4 +1,5 @@
@testable import SwiftLintCore
import TestHelpers
import XCTest
final class SwiftLintFileTests: SwiftLintTestCase {
@@ -1,4 +1,5 @@
import Foundation
import TestHelpers
import XCTest
import Yams
+1
View File
@@ -3,6 +3,7 @@ import Foundation
import SourceKittenFramework
@testable import SwiftLintBuiltInRules
@testable import SwiftLintFramework
import TestHelpers
import XCTest
private extension Command {
@@ -1,4 +1,5 @@
@testable import SwiftLintFramework
import TestHelpers
import XCTest
final class ConfigurationAliasesTests: SwiftLintTestCase {
@@ -1,4 +1,5 @@
import SwiftLintFramework
import TestHelpers
// swiftlint:disable:next blanket_disable_command
// swiftlint:disable nesting identifier_name
@@ -1,6 +1,7 @@
import Foundation
import SourceKittenFramework
@testable import SwiftLintFramework
import TestHelpers
import XCTest
// swiftlint:disable file_length
@@ -1,4 +1,5 @@
import SwiftLintFramework
import TestHelpers
import XCTest
// swiftlint:disable:next balanced_xctest_lifecycle
-3
View File
@@ -1,3 +0,0 @@
// These imports are re-exported to make them available implicitly to all files.
// swiftlint:disable:next unused_import
@_exported import TestHelpers
@@ -1,5 +1,6 @@
import Foundation
@testable import SwiftLintFramework
import TestHelpers
import XCTest
private struct CacheTestHelper {
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers
import XCTest
final class ModifierOrderTests: SwiftLintTestCase {
@@ -388,7 +389,6 @@ final class ModifierOrderTests: SwiftLintTestCase {
XCTFail("Failed to create configuration")
return
}
let allViolations = violations(Example("final public var foo: String"), config: config)
let modifierOrderRuleViolation = allViolations.first { $0.ruleIdentifier == ruleID }
if let violation = modifierOrderRuleViolation {
@@ -1,5 +1,6 @@
@testable import SwiftLintBuiltInRules
@testable import SwiftLintCore
import TestHelpers
import XCTest
final class ParserDiagnosticsTests: SwiftLintTestCase {
@@ -1,6 +1,7 @@
import SourceKittenFramework
@testable import SwiftLintBuiltInRules
@testable import SwiftLintCore
import TestHelpers
import XCTest
final class RuleConfigurationTests: SwiftLintTestCase {
+1
View File
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import TestHelpers
final class RulesTests: SwiftLintTestCase {
func testLeadingWhitespace() {
@@ -1,4 +1,5 @@
@testable import SwiftLintFramework
import TestHelpers
import XCTest
final class SourceKitCrashTests: SwiftLintTestCase {
@@ -1,4 +1,5 @@
import SourceKittenFramework
import TestHelpers
import XCTest
final class StringViewExtensionTests: SwiftLintTestCase {
@@ -1,4 +1,5 @@
import SwiftLintFramework
import TestHelpers
import XCTest
final class SwiftVersionTests: SwiftLintTestCase {
@@ -1,4 +1,5 @@
@testable import SwiftLintFramework
import TestHelpers
import XCTest
final class YamlParserTests: SwiftLintTestCase {
+18
View File
@@ -17,3 +17,21 @@ public struct RuleMock: Rule {
public func validate(file _: SwiftLintFile) -> [StyleViolation] { [] }
}
public struct RuleWithLevelsMock: Rule {
public var configuration = SeverityLevelsConfiguration<Self>(warning: 2, error: 3)
public static let description = RuleDescription(identifier: "severity_level_mock",
name: "",
description: "",
kind: .style,
deprecatedAliases: ["mock"])
public init() { /* conformance for test */ }
public init(configuration: Any) throws {
self.init()
try self.configuration.apply(configuration: configuration)
}
public func validate(file _: SwiftLintFile) -> [StyleViolation] { [] }
}