Introduce SwiftLintTestCase
To consistently set up rules before tests
This commit is contained in:
parent
165172e0fa
commit
4c04cdafa7
|
@ -1,14 +1,13 @@
|
|||
@_spi(TestHelper)
|
||||
@testable import SwiftLintFramework
|
||||
import SwiftLintTestHelpers
|
||||
import XCTest
|
||||
|
||||
// swiftlint:disable:next blanket_disable_command
|
||||
// swiftlint:disable file_length single_test_class type_name
|
||||
|
||||
{% for rule in types.structs %}
|
||||
{% if rule.name|hasSuffix:"Rule" %}
|
||||
class {{ rule.name }}GeneratedTests: XCTestCase {
|
||||
class {{ rule.name }}GeneratedTests: SwiftLintTestCase {
|
||||
func testWithDefaultConfiguration() {
|
||||
verifyRule({{ rule.name }}.description)
|
||||
}
|
||||
|
|
|
@ -66,6 +66,13 @@ file_name:
|
|||
- GeneratedTests.swift
|
||||
- TestHelpers.swift
|
||||
|
||||
balanced_xctest_lifecycle: &unit_test_configuration
|
||||
test_parent_classes:
|
||||
- SwiftLintTestCase
|
||||
- XCTestCase
|
||||
empty_xctest_method: *unit_test_configuration
|
||||
single_test_class: *unit_test_configuration
|
||||
|
||||
function_body_length: 60
|
||||
type_body_length: 400
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import SwiftLintTestHelpers
|
||||
import XCTest
|
||||
|
||||
final class ExtraRulesTests: XCTestCase {
|
||||
final class ExtraRulesTests: SwiftLintTestCase {
|
||||
func testWithDefaultConfiguration() {
|
||||
for ruleType in extraRules() {
|
||||
verifyRule(ruleType.description)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,6 +2,7 @@ import Foundation
|
|||
import SourceKittenFramework
|
||||
@_spi(TestHelper)
|
||||
import SwiftLintFramework
|
||||
import SwiftLintTestHelpers
|
||||
import XCTest
|
||||
|
||||
private let config: Configuration = {
|
||||
|
@ -14,7 +15,7 @@ private let config: Configuration = {
|
|||
return Configuration(configurationFiles: [Configuration.defaultFileName])
|
||||
}()
|
||||
|
||||
class IntegrationTests: XCTestCase {
|
||||
class IntegrationTests: SwiftLintTestCase {
|
||||
func testSwiftLintLints() {
|
||||
// This is as close as we're ever going to get to a self-hosting linter.
|
||||
let swiftFiles = config.lintableFiles(inPath: "", forceExclude: false)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class AccessControlLevelTests: XCTestCase {
|
||||
class AccessControlLevelTests: SwiftLintTestCase {
|
||||
func testDescription() {
|
||||
XCTAssertEqual(AccessControlLevel.private.description, "private")
|
||||
XCTAssertEqual(AccessControlLevel.fileprivate.description, "fileprivate")
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class AttributesRuleTests: XCTestCase {
|
||||
class AttributesRuleTests: SwiftLintTestCase {
|
||||
func testAttributesWithAlwaysOnSameLine() {
|
||||
// Test with custom `always_on_same_line`
|
||||
let nonTriggeringExamples = [
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class BlanketDisableCommandRuleTests: XCTestCase {
|
||||
private var emptyDescription: RuleDescription {
|
||||
BlanketDisableCommandRule.description.with(triggeringExamples: []).with(nonTriggeringExamples: [])
|
||||
}
|
||||
class BlanketDisableCommandRuleTests: SwiftLintTestCase {
|
||||
private lazy var emptyDescription = BlanketDisableCommandRule.description
|
||||
.with(triggeringExamples: [])
|
||||
.with(nonTriggeringExamples: [])
|
||||
|
||||
func testAlwaysBlanketDisable() {
|
||||
let nonTriggeringExamples = [Example("// swiftlint:disable file_length\n// swiftlint:enable file_length")]
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
import SwiftLintTestHelpers
|
||||
import XCTest
|
||||
|
||||
class CollectingRuleTests: XCTestCase {
|
||||
class CollectingRuleTests: SwiftLintTestCase {
|
||||
func testCollectsIntoStorage() {
|
||||
struct Spec: MockCollectingRule {
|
||||
func collectInfo(for file: SwiftLintFile) -> Int {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class CollectionAlignmentRuleTests: XCTestCase {
|
||||
class CollectionAlignmentRuleTests: SwiftLintTestCase {
|
||||
func testCollectionAlignmentWithAlignLeft() {
|
||||
let baseDescription = CollectionAlignmentRule.description
|
||||
let examples = CollectionAlignmentRule.Examples(alignColons: false)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class ColonRuleTests: XCTestCase {
|
||||
class ColonRuleTests: SwiftLintTestCase {
|
||||
func testColonWithFlexibleRightSpace() {
|
||||
// Verify Colon rule with test values for when flexible_right_spacing
|
||||
// is true.
|
||||
|
|
|
@ -14,7 +14,7 @@ private extension Command {
|
|||
}
|
||||
}
|
||||
|
||||
class CommandTests: XCTestCase {
|
||||
class CommandTests: SwiftLintTestCase {
|
||||
// MARK: Command Creation
|
||||
|
||||
func testNoCommandsInEmptyFile() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class CompilerProtocolInitRuleTests: XCTestCase {
|
||||
class CompilerProtocolInitRuleTests: SwiftLintTestCase {
|
||||
private let ruleID = CompilerProtocolInitRule.description.identifier
|
||||
|
||||
func testViolationMessageForExpressibleByIntegerLiteral() throws {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class ComputedAccessorsOrderRuleTests: XCTestCase {
|
||||
class ComputedAccessorsOrderRuleTests: SwiftLintTestCase {
|
||||
func testSetGetConfiguration() {
|
||||
let nonTriggeringExamples = [
|
||||
Example("""
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class ConditionalReturnsOnNewlineRuleTests: XCTestCase {
|
||||
class ConditionalReturnsOnNewlineRuleTests: SwiftLintTestCase {
|
||||
func testConditionalReturnsOnNewlineWithIfOnly() {
|
||||
// Test with `if_only` set to true
|
||||
let nonTriggeringExamples = [
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
final class ConfigurationAliasesTests: XCTestCase {
|
||||
final class ConfigurationAliasesTests: SwiftLintTestCase {
|
||||
private let testRuleList = RuleList(rules: RuleWithLevelsMock.self)
|
||||
|
||||
func testConfiguresCorrectlyFromDeprecatedAlias() throws {
|
||||
|
|
|
@ -8,7 +8,7 @@ import XCTest
|
|||
|
||||
private let optInRules = RuleRegistry.shared.list.list.filter({ $0.1.init() is OptInRule }).map({ $0.0 })
|
||||
|
||||
class ConfigurationTests: XCTestCase {
|
||||
class ConfigurationTests: SwiftLintTestCase {
|
||||
// MARK: Setup & Teardown
|
||||
private var previousWorkingDir: String!
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class ContainsOverFirstNotNilRuleTests: XCTestCase {
|
||||
class ContainsOverFirstNotNilRuleTests: SwiftLintTestCase {
|
||||
func testFirstReason() {
|
||||
let example = Example("↓myList.first { $0 % 2 == 0 } != nil")
|
||||
let violations = self.violations(example)
|
||||
|
|
|
@ -2,7 +2,7 @@ import SourceKittenFramework
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class CustomRulesTests: XCTestCase {
|
||||
class CustomRulesTests: SwiftLintTestCase {
|
||||
func testCustomRuleConfigurationSetsCorrectlyWithMatchKinds() {
|
||||
let configDict = [
|
||||
"my_custom_rule": [
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class CyclomaticComplexityConfigurationTests: XCTestCase {
|
||||
class CyclomaticComplexityConfigurationTests: SwiftLintTestCase {
|
||||
func testCyclomaticComplexityConfigurationInitializerSetsLevels() {
|
||||
let warning = 10
|
||||
let error = 30
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class CyclomaticComplexityRuleTests: XCTestCase {
|
||||
class CyclomaticComplexityRuleTests: SwiftLintTestCase {
|
||||
private lazy var complexSwitchExample: Example = {
|
||||
var example = "func switcheroo() {\n"
|
||||
example += " switch foo {\n"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class DeploymentTargetConfigurationTests: XCTestCase {
|
||||
class DeploymentTargetConfigurationTests: SwiftLintTestCase {
|
||||
private typealias Version = DeploymentTargetConfiguration.Version
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class DeploymentTargetRuleTests: XCTestCase {
|
||||
class DeploymentTargetRuleTests: SwiftLintTestCase {
|
||||
func testMacOSAttributeReason() {
|
||||
let example = Example("@available(macOS 10.11, *)\nclass A {}")
|
||||
let violations = self.violations(example, config: ["macOS_deployment_target": "10.14.0"])
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class DisableAllTests: XCTestCase {
|
||||
class DisableAllTests: SwiftLintTestCase {
|
||||
/// Example violations. Could be replaced with other single violations.
|
||||
private let violatingPhrases = [
|
||||
Example("let r = 0"), // Violates identifier_name
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class DiscouragedDirectInitRuleTests: XCTestCase {
|
||||
class DiscouragedDirectInitRuleTests: SwiftLintTestCase {
|
||||
private let baseDescription = DiscouragedDirectInitRule.description
|
||||
|
||||
func testDiscouragedDirectInitWithConfiguredSeverity() {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class DiscouragedObjectLiteralRuleTests: XCTestCase {
|
||||
class DiscouragedObjectLiteralRuleTests: SwiftLintTestCase {
|
||||
func testWithImageLiteral() {
|
||||
let baseDescription = DiscouragedObjectLiteralRule.description
|
||||
let nonTriggeringExamples = baseDescription.nonTriggeringExamples + [
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class EmptyCountRuleTests: XCTestCase {
|
||||
class EmptyCountRuleTests: SwiftLintTestCase {
|
||||
func testEmptyCountWithOnlyAfterDot() {
|
||||
// Test with `only_after_dot` set to true
|
||||
let nonTriggeringExamples = [
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class ExampleTests: XCTestCase {
|
||||
class ExampleTests: SwiftLintTestCase {
|
||||
func testEquatableDoesNotLookAtFile() {
|
||||
let first = Example("foo", file: "a", line: 1)
|
||||
let second = Example("foo", file: "b", line: 1)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class ExpiringTodoRuleTests: XCTestCase {
|
||||
private var config: Configuration = makeConfiguration()
|
||||
class ExpiringTodoRuleTests: SwiftLintTestCase {
|
||||
private lazy var config: Configuration = makeConfiguration()
|
||||
|
||||
func testExpiringTodo() {
|
||||
verifyRule(ExpiringTodoRule.description, commentDoesntViolate: false)
|
||||
|
@ -38,7 +38,7 @@ class ExpiringTodoRuleTests: XCTestCase {
|
|||
let ruleConfig: ExpiringTodoConfiguration = .init(
|
||||
dateDelimiters: .init(opening: "<", closing: ">")
|
||||
)
|
||||
config = Self.makeConfiguration(with: ruleConfig)
|
||||
config = makeConfiguration(with: ruleConfig)
|
||||
|
||||
let example = Example("fatalError() // TODO: <\(dateString(for: .expired))> Implement")
|
||||
let violations = self.violations(example)
|
||||
|
@ -51,7 +51,7 @@ class ExpiringTodoRuleTests: XCTestCase {
|
|||
dateFormat: "MM-dd-yyyy",
|
||||
dateSeparator: "-"
|
||||
)
|
||||
config = Self.makeConfiguration(with: ruleConfig)
|
||||
config = makeConfiguration(with: ruleConfig)
|
||||
|
||||
let example = Example("fatalError() // TODO: [\(dateString(for: .expired))] Implement")
|
||||
let violations = self.violations(example)
|
||||
|
@ -63,7 +63,7 @@ class ExpiringTodoRuleTests: XCTestCase {
|
|||
let ruleConfig: ExpiringTodoConfiguration = .init(
|
||||
dateFormat: "yyyy/MM/dd"
|
||||
)
|
||||
config = Self.makeConfiguration(with: ruleConfig)
|
||||
config = makeConfiguration(with: ruleConfig)
|
||||
|
||||
let example = Example("fatalError() // TODO: [\(dateString(for: .expired))] Implement")
|
||||
let violations = self.violations(example)
|
||||
|
@ -132,7 +132,7 @@ class ExpiringTodoRuleTests: XCTestCase {
|
|||
let ruleConfig: ExpiringTodoConfiguration = .init(
|
||||
dateFormat: "dd/yyyy/MM"
|
||||
)
|
||||
config = Self.makeConfiguration(with: ruleConfig)
|
||||
config = makeConfiguration(with: ruleConfig)
|
||||
|
||||
let example = Example("fatalError() // TODO: [31/01/2020] Implement")
|
||||
let violations = self.violations(example)
|
||||
|
@ -173,7 +173,7 @@ class ExpiringTodoRuleTests: XCTestCase {
|
|||
)!
|
||||
}
|
||||
|
||||
private static func makeConfiguration(with ruleConfiguration: ExpiringTodoConfiguration? = nil) -> Configuration {
|
||||
private func makeConfiguration(with ruleConfiguration: ExpiringTodoConfiguration? = nil) -> Configuration {
|
||||
var serializedConfig: [String: Any]?
|
||||
|
||||
if let config = ruleConfiguration {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class ExplicitTypeInterfaceConfigurationTests: XCTestCase {
|
||||
class ExplicitTypeInterfaceConfigurationTests: SwiftLintTestCase {
|
||||
func testDefaultConfiguration() {
|
||||
let config = ExplicitTypeInterfaceConfiguration()
|
||||
XCTAssertEqual(config.severityConfiguration.severity, .warning)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class ExplicitTypeInterfaceRuleTests: XCTestCase {
|
||||
class ExplicitTypeInterfaceRuleTests: SwiftLintTestCase {
|
||||
func testLocalVars() {
|
||||
let nonTriggeringExamples = [
|
||||
Example("func foo() {\nlet intVal: Int = 1\n}"),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import SourceKittenFramework
|
||||
import XCTest
|
||||
|
||||
class ExtendedNSStringTests: XCTestCase {
|
||||
class ExtendedNSStringTests: SwiftLintTestCase {
|
||||
func testLineAndCharacterForByteOffset_forContentsContainingMultibyteCharacters() {
|
||||
let contents = "" +
|
||||
"import Foundation\n" + // 18 characters
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import XCTest
|
||||
|
||||
class ExtendedStringTests: XCTestCase {
|
||||
class ExtendedStringTests: SwiftLintTestCase {
|
||||
func testCountOccurrences() {
|
||||
XCTAssertEqual("aabbabaaba".countOccurrences(of: "a"), 6)
|
||||
XCTAssertEqual("".countOccurrences(of: "a"), 0)
|
||||
|
|
|
@ -3,7 +3,7 @@ import XCTest
|
|||
|
||||
private let fixturesDirectory = "\(TestResources.path)/FileHeaderRuleFixtures"
|
||||
|
||||
class FileHeaderRuleTests: XCTestCase {
|
||||
class FileHeaderRuleTests: SwiftLintTestCase {
|
||||
private func validate(fileName: String, using configuration: Any) throws -> [StyleViolation] {
|
||||
let file = SwiftLintFile(path: fixturesDirectory.stringByAppendingPathComponent(fileName))!
|
||||
let rule = try FileHeaderRule(configuration: configuration)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class FileLengthRuleTests: XCTestCase {
|
||||
class FileLengthRuleTests: SwiftLintTestCase {
|
||||
func testFileLengthWithDefaultConfiguration() {
|
||||
verifyRule(FileLengthRule.description, commentDoesntViolate: false,
|
||||
testMultiByteOffsets: false, testShebang: false)
|
||||
|
|
|
@ -6,7 +6,7 @@ private let fixturesDirectory = #file.bridge()
|
|||
.deletingLastPathComponent.bridge()
|
||||
.appendingPathComponent("Resources/FileNameNoSpaceRuleFixtures")
|
||||
|
||||
class FileNameNoSpaceRuleTests: XCTestCase {
|
||||
class FileNameNoSpaceRuleTests: SwiftLintTestCase {
|
||||
private func validate(fileName: String, excludedOverride: [String]? = nil) throws -> [StyleViolation] {
|
||||
let file = SwiftLintFile(path: fixturesDirectory.stringByAppendingPathComponent(fileName))!
|
||||
let rule: FileNameNoSpaceRule
|
||||
|
|
|
@ -3,7 +3,7 @@ import XCTest
|
|||
|
||||
private let fixturesDirectory = "\(TestResources.path)/FileNameRuleFixtures"
|
||||
|
||||
class FileNameRuleTests: XCTestCase {
|
||||
class FileNameRuleTests: SwiftLintTestCase {
|
||||
private func validate(fileName: String, excludedOverride: [String]? = nil,
|
||||
prefixPattern: String? = nil, suffixPattern: String? = nil,
|
||||
nestedTypeSeparator: String? = nil) throws -> [StyleViolation] {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class FileTypesOrderRuleTests: XCTestCase {
|
||||
class FileTypesOrderRuleTests: SwiftLintTestCase {
|
||||
// swiftlint:disable:next function_body_length
|
||||
func testFileTypesOrderReversedOrder() {
|
||||
// Test with reversed `order` entries
|
||||
|
|
|
@ -13,7 +13,7 @@ private func violatingFuncWithBody(_ body: String, file: StaticString = #file, l
|
|||
return funcWithBody(body, violates: true, file: file, line: line)
|
||||
}
|
||||
|
||||
class FunctionBodyLengthRuleTests: XCTestCase {
|
||||
class FunctionBodyLengthRuleTests: SwiftLintTestCase {
|
||||
func testFunctionBodyLengths() {
|
||||
let longFunctionBody = funcWithBody(repeatElement("x = 0\n", count: 49).joined())
|
||||
XCTAssertEqual(self.violations(longFunctionBody), [])
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
private func funcWithParameters(_ parameters: String,
|
||||
violates: Bool = false,
|
||||
|
@ -10,7 +9,7 @@ private func funcWithParameters(_ parameters: String,
|
|||
return Example("func \(marker)abc(\(parameters)) {}\n", file: file, line: line)
|
||||
}
|
||||
|
||||
class FunctionParameterCountRuleTests: XCTestCase {
|
||||
class FunctionParameterCountRuleTests: SwiftLintTestCase {
|
||||
func testFunctionParameterCount() {
|
||||
let baseDescription = FunctionParameterCountRule.description
|
||||
let nonTriggeringExamples = [
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class GenericTypeNameRuleTests: XCTestCase {
|
||||
class GenericTypeNameRuleTests: SwiftLintTestCase {
|
||||
func testGenericTypeNameWithExcluded() {
|
||||
let baseDescription = GenericTypeNameRule.description
|
||||
let nonTriggeringExamples = baseDescription.nonTriggeringExamples + [
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
final class GlobTests: XCTestCase {
|
||||
final class GlobTests: SwiftLintTestCase {
|
||||
private var mockPath: String {
|
||||
return testResourcesPath.stringByAppendingPathComponent("ProjectMock")
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class IdentifierNameRuleTests: XCTestCase {
|
||||
class IdentifierNameRuleTests: SwiftLintTestCase {
|
||||
func testIdentifierNameWithExcluded() {
|
||||
let baseDescription = IdentifierNameRule.description
|
||||
let nonTriggeringExamples = baseDescription.nonTriggeringExamples + [
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
final class ImplicitGetterRuleTests: XCTestCase {
|
||||
final class ImplicitGetterRuleTests: SwiftLintTestCase {
|
||||
func testPropertyReason() throws {
|
||||
let config = try XCTUnwrap(makeConfig(nil, ImplicitGetterRule.description.identifier))
|
||||
let example = Example("""
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class ImplicitReturnConfigurationTests: XCTestCase {
|
||||
class ImplicitReturnConfigurationTests: SwiftLintTestCase {
|
||||
func testImplicitReturnConfigurationFromDictionary() throws {
|
||||
var configuration = ImplicitReturnConfiguration(includedKinds: Set<ImplicitReturnConfiguration.ReturnKind>())
|
||||
let config: [String: Any] = [
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class ImplicitReturnRuleTests: XCTestCase {
|
||||
class ImplicitReturnRuleTests: SwiftLintTestCase {
|
||||
func testOnlyClosureKindIncluded() {
|
||||
let nonTriggeringExamples = ImplicitReturnRuleExamples.GenericExamples.nonTriggeringExamples +
|
||||
ImplicitReturnRuleExamples.ClosureExamples.nonTriggeringExamples +
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import XCTest
|
||||
|
||||
// swiftlint:disable:next type_name
|
||||
class ImplicitlyUnwrappedOptionalConfigurationTests: XCTestCase {
|
||||
class ImplicitlyUnwrappedOptionalConfigurationTests: SwiftLintTestCase {
|
||||
func testImplicitlyUnwrappedOptionalConfigurationProperlyAppliesConfigurationFromDictionary() throws {
|
||||
var configuration = ImplicitlyUnwrappedOptionalConfiguration(
|
||||
mode: .allExceptIBOutlets,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class ImplicitlyUnwrappedOptionalRuleTests: XCTestCase {
|
||||
class ImplicitlyUnwrappedOptionalRuleTests: SwiftLintTestCase {
|
||||
func testImplicitlyUnwrappedOptionalRuleDefaultConfiguration() {
|
||||
let rule = ImplicitlyUnwrappedOptionalRule()
|
||||
XCTAssertEqual(rule.configuration.mode, .allExceptIBOutlets)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class InclusiveLanguageRuleTests: XCTestCase {
|
||||
class InclusiveLanguageRuleTests: SwiftLintTestCase {
|
||||
func testNonTriggeringExamplesWithNonDefaultConfig() {
|
||||
InclusiveLanguageRuleExamples.nonTriggeringExamplesWithConfig.forEach { example in
|
||||
let description = InclusiveLanguageRule.description
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class IndentationWidthRuleTests: XCTestCase {
|
||||
class IndentationWidthRuleTests: SwiftLintTestCase {
|
||||
// MARK: Examples
|
||||
/// It's not okay to have the first line indented.
|
||||
func testFirstLineIndentation() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class LineEndingTests: XCTestCase {
|
||||
class LineEndingTests: SwiftLintTestCase {
|
||||
func testCarriageReturnDoesNotCauseError() {
|
||||
XCTAssert(
|
||||
violations(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class LineLengthConfigurationTests: XCTestCase {
|
||||
class LineLengthConfigurationTests: SwiftLintTestCase {
|
||||
func testLineLengthConfigurationInitializerSetsLength() {
|
||||
let warning = 100
|
||||
let error = 150
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class LineLengthRuleTests: XCTestCase {
|
||||
class LineLengthRuleTests: SwiftLintTestCase {
|
||||
private let longFunctionDeclarations = [
|
||||
Example("public func superDuperLongFunctionDeclaration(a: String, b: String, " +
|
||||
"c: String, d: String, e: String, f: String, g: String, h: String, i: String, " +
|
||||
|
|
|
@ -68,7 +68,7 @@ private class TestFileManager: LintableFileManager {
|
|||
}
|
||||
}
|
||||
|
||||
class LinterCacheTests: XCTestCase {
|
||||
class LinterCacheTests: SwiftLintTestCase {
|
||||
// MARK: Test Helpers
|
||||
|
||||
private var cache = LinterCache(fileManager: TestFileManager())
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class MissingDocsRuleTests: XCTestCase {
|
||||
class MissingDocsRuleTests: SwiftLintTestCase {
|
||||
func testDescriptionEmpty() {
|
||||
let configuration = MissingDocsRuleConfiguration()
|
||||
XCTAssertEqual(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class ModifierOrderTests: XCTestCase {
|
||||
class ModifierOrderTests: SwiftLintTestCase {
|
||||
func testAttributeTypeMethod() {
|
||||
let descriptionOverride = ModifierOrderRule.description
|
||||
.with(nonTriggeringExamples: [
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class MultilineArgumentsRuleTests: XCTestCase {
|
||||
class MultilineArgumentsRuleTests: SwiftLintTestCase {
|
||||
func testMultilineArgumentsWithWithNextLine() {
|
||||
let nonTriggeringExamples = [
|
||||
Example("foo()"),
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class NestingRuleTests: XCTestCase {
|
||||
class NestingRuleTests: SwiftLintTestCase {
|
||||
// swiftlint:disable:next function_body_length
|
||||
func testNestingWithAlwaysAllowOneTypeInFunctions() {
|
||||
var nonTriggeringExamples = NestingRule.description.nonTriggeringExamples
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import SwiftParser
|
||||
import XCTest
|
||||
|
||||
class NumberSeparatorRuleTests: XCTestCase {
|
||||
class NumberSeparatorRuleTests: SwiftLintTestCase {
|
||||
func testNumberSeparatorWithMinimumLength() {
|
||||
let nonTriggeringExamples = [
|
||||
Example("let foo = 10_000"),
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class ObjectLiteralRuleTests: XCTestCase {
|
||||
class ObjectLiteralRuleTests: SwiftLintTestCase {
|
||||
// MARK: - Instance Properties
|
||||
private let imageLiteralTriggeringExamples = ["", ".init"].flatMap { (method: String) -> [Example] in
|
||||
["UI", "NS"].flatMap { (prefix: String) -> [Example] in
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class OpeningBraceRuleTests: XCTestCase {
|
||||
class OpeningBraceRuleTests: SwiftLintTestCase {
|
||||
// swiftlint:disable:next function_body_length
|
||||
func testWithAllowMultilineTrue() {
|
||||
// Test with `same_line` set to false
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
final class ParserDiagnosticsTests: XCTestCase {
|
||||
final class ParserDiagnosticsTests: SwiftLintTestCase {
|
||||
func testFileWithParserErrorDiagnostics() {
|
||||
parserDiagnosticsDisabledForTests = false
|
||||
XCTAssertNotNil(SwiftLintFile(contents: "importz Foundation").parserDiagnostics)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
final class PrefixedTopLevelConstantRuleTests: XCTestCase {
|
||||
final class PrefixedTopLevelConstantRuleTests: SwiftLintTestCase {
|
||||
func testPrivateOnly() {
|
||||
let triggeringExamples = [
|
||||
Example("private let ↓Foo = 20.0"),
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class PrivateOverFilePrivateRuleTests: XCTestCase {
|
||||
class PrivateOverFilePrivateRuleTests: SwiftLintTestCase {
|
||||
func testPrivateOverFilePrivateValidatingExtensions() {
|
||||
let baseDescription = PrivateOverFilePrivateRule.description
|
||||
let triggeringExamples = baseDescription.triggeringExamples + [
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class RegexConfigurationTests: XCTestCase {
|
||||
class RegexConfigurationTests: SwiftLintTestCase {
|
||||
func testShouldValidateIsTrueByDefault() {
|
||||
let config = RegexConfiguration(identifier: "example")
|
||||
XCTAssertTrue(config.shouldValidate(filePath: "App/file.swift"))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class RegionTests: XCTestCase {
|
||||
class RegionTests: SwiftLintTestCase {
|
||||
// MARK: Regions From Files
|
||||
|
||||
func testNoRegionsInEmptyFile() {
|
||||
|
|
|
@ -3,7 +3,7 @@ import SourceKittenFramework
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class ReporterTests: XCTestCase {
|
||||
class ReporterTests: SwiftLintTestCase {
|
||||
func testReporterFromString() {
|
||||
for reporter in reportersList {
|
||||
XCTAssertEqual(reporter.identifier, reporterFrom(identifier: reporter.identifier).identifier)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class RequiredEnumCaseRuleConfigurationTests: XCTestCase {
|
||||
class RequiredEnumCaseRuleConfigurationTests: SwiftLintTestCase {
|
||||
private typealias RuleConfiguration = RequiredEnumCaseRuleConfiguration
|
||||
private typealias RequiredCase = RuleConfiguration.RequiredCase
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SomeModule
|
||||
import XCTest
|
||||
|
||||
class BoolExtensionTests: XCTestCase {
|
||||
class BoolExtensionTests: SwiftLintTestCase {
|
||||
func testExample() {
|
||||
// some code
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import SourceKittenFramework
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class RuleConfigurationTests: XCTestCase {
|
||||
class RuleConfigurationTests: SwiftLintTestCase {
|
||||
func testNameConfigurationSetsCorrectly() {
|
||||
let config = [ "min_length": ["warning": 17, "error": 7],
|
||||
"max_length": ["warning": 170, "error": 700],
|
||||
|
|
|
@ -19,7 +19,7 @@ struct RuleWithLevelsMock: ConfigurationProviderRule {
|
|||
func validate(file: SwiftLintFile) -> [StyleViolation] { return [] }
|
||||
}
|
||||
|
||||
class RuleTests: XCTestCase {
|
||||
class RuleTests: SwiftLintTestCase {
|
||||
fileprivate struct RuleMock1: Rule {
|
||||
var configurationDescription: String { return "N/A" }
|
||||
static let description = RuleDescription(identifier: "RuleMock1", name: "",
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class RulesTests: XCTestCase {
|
||||
class RulesTests: SwiftLintTestCase {
|
||||
func testLeadingWhitespace() {
|
||||
verifyRule(LeadingWhitespaceRule.description, skipDisableCommandTests: true,
|
||||
testMultiByteOffsets: false, testShebang: false)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class SourceKitCrashTests: XCTestCase {
|
||||
class SourceKitCrashTests: SwiftLintTestCase {
|
||||
func testAssertHandlerIsNotCalledOnNormalFile() {
|
||||
let file = SwiftLintFile(contents: "A file didn't crash SourceKitService")
|
||||
file.sourcekitdFailed = false
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class StatementPositionRuleTests: XCTestCase {
|
||||
class StatementPositionRuleTests: SwiftLintTestCase {
|
||||
func testStatementPositionUncuddled() {
|
||||
let configuration = ["statement_mode": "uncuddled_else"]
|
||||
verifyRule(StatementPositionRule.uncuddledDescription, ruleConfiguration: configuration)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
final class StringExtensionTests: XCTestCase {
|
||||
final class StringExtensionTests: SwiftLintTestCase {
|
||||
func testRelativePathExpression() {
|
||||
XCTAssertEqual("Folder/Test", "Root/Folder/Test".path(relativeTo: "Root"))
|
||||
XCTAssertEqual("Test", "Root/Folder/Test".path(relativeTo: "Root/Folder"))
|
||||
|
|
|
@ -2,7 +2,7 @@ import SourceKittenFramework
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
final class StringViewExtensionTests: XCTestCase {
|
||||
final class StringViewExtensionTests: SwiftLintTestCase {
|
||||
func testByteOffsetInvalidCases() {
|
||||
let view = StringView("")
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class SwiftLintFileTests: XCTestCase {
|
||||
class SwiftLintFileTests: SwiftLintTestCase {
|
||||
private let tempFile = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
|
||||
|
||||
override func setUp() async throws {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
final class SwiftVersionTests: XCTestCase {
|
||||
final class SwiftVersionTests: SwiftLintTestCase {
|
||||
func testDetectSwiftVersion() {
|
||||
#if compiler(>=6.0.0)
|
||||
let version = "6.0.0"
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class SwitchCaseAlignmentRuleTests: XCTestCase {
|
||||
class SwitchCaseAlignmentRuleTests: SwiftLintTestCase {
|
||||
func testSwitchCaseAlignmentWithoutIndentedCases() {
|
||||
let baseDescription = SwitchCaseAlignmentRule.description
|
||||
let examples = SwitchCaseAlignmentRule.Examples(indentedCases: false)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class TodoRuleTests: XCTestCase {
|
||||
class TodoRuleTests: SwiftLintTestCase {
|
||||
func testTodo() {
|
||||
verifyRule(TodoRule.description, commentDoesntViolate: false)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class TrailingClosureConfigurationTests: XCTestCase {
|
||||
class TrailingClosureConfigurationTests: SwiftLintTestCase {
|
||||
func testDefaultConfiguration() {
|
||||
let config = TrailingClosureConfiguration()
|
||||
XCTAssertEqual(config.severityConfiguration.severity, .warning)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class TrailingClosureRuleTests: XCTestCase {
|
||||
class TrailingClosureRuleTests: SwiftLintTestCase {
|
||||
func testWithOnlySingleMutedParameterEnabled() {
|
||||
let originalDescription = TrailingClosureRule.description
|
||||
let description = originalDescription
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class TrailingCommaRuleTests: XCTestCase {
|
||||
class TrailingCommaRuleTests: SwiftLintTestCase {
|
||||
func testTrailingCommaRuleWithDefaultConfiguration() {
|
||||
// Verify TrailingCommaRule with test values for when mandatory_comma is false (default).
|
||||
let triggeringExamples = TrailingCommaRule.description.triggeringExamples +
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class TrailingWhitespaceRuleTests: XCTestCase {
|
||||
class TrailingWhitespaceRuleTests: SwiftLintTestCase {
|
||||
func testWithIgnoresEmptyLinesEnabled() {
|
||||
// Perform additional tests with the ignores_empty_lines setting enabled.
|
||||
// The set of non-triggering examples is extended by a whitespace-indented empty line
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class TypeContentsOrderRuleTests: XCTestCase {
|
||||
class TypeContentsOrderRuleTests: SwiftLintTestCase {
|
||||
// swiftlint:disable:next function_body_length
|
||||
func testTypeContentsOrderReversedOrder() {
|
||||
// Test with reversed `order` entries
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class TypeNameRuleTests: XCTestCase {
|
||||
class TypeNameRuleTests: SwiftLintTestCase {
|
||||
func testTypeNameWithExcluded() {
|
||||
let baseDescription = TypeNameRule.description
|
||||
let nonTriggeringExamples = baseDescription.nonTriggeringExamples + [
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class UnusedOptionalBindingRuleTests: XCTestCase {
|
||||
class UnusedOptionalBindingRuleTests: SwiftLintTestCase {
|
||||
func testDefaultConfiguration() {
|
||||
let baseDescription = UnusedOptionalBindingRule.description
|
||||
let triggeringExamples = baseDescription.triggeringExamples + [
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class VerticalWhitespaceRuleTests: XCTestCase {
|
||||
class VerticalWhitespaceRuleTests: SwiftLintTestCase {
|
||||
private let ruleID = VerticalWhitespaceRule.description.identifier
|
||||
|
||||
func testAttributesWithMaxEmptyLines() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class XCTSpecificMatcherRuleTests: XCTestCase {
|
||||
class XCTSpecificMatcherRuleTests: SwiftLintTestCase {
|
||||
func testEqualTrue() {
|
||||
let example = Example("XCTAssertEqual(a, true)")
|
||||
let violations = self.violations(example)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
class YamlParserTests: XCTestCase {
|
||||
class YamlParserTests: SwiftLintTestCase {
|
||||
func testParseEmptyString() {
|
||||
XCTAssertEqual((try YamlParser.parse("", env: [:])).count, 0,
|
||||
"Parsing empty YAML string should succeed")
|
||||
|
|
|
@ -2,7 +2,7 @@ import Foundation
|
|||
import XCTest
|
||||
import Yams
|
||||
|
||||
class YamlSwiftLintTests: XCTestCase {
|
||||
class YamlSwiftLintTests: SwiftLintTestCase {
|
||||
func testFlattenYaml() throws {
|
||||
do {
|
||||
guard let yamlDict = try Yams.load(yaml: try getTestYaml()) as? [String: Any] else {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
// swiftlint:disable:next balanced_xctest_lifecycle
|
||||
open class SwiftLintTestCase: XCTestCase {
|
||||
override open class func setUp() {
|
||||
super.setUp()
|
||||
RuleRegistry.registerAllRulesOnce()
|
||||
}
|
||||
}
|
|
@ -330,7 +330,6 @@ public extension XCTestCase {
|
|||
testShebang: Bool = true,
|
||||
file: StaticString = #file,
|
||||
line: UInt = #line) {
|
||||
RuleRegistry.registerAllRulesOnce()
|
||||
guard ruleDescription.minSwiftVersion <= .current else {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue