Skip to content

Commit

Permalink
Split RulesTests into several test cases, generating them automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelofabri committed Jul 22, 2018
1 parent 41d3977 commit 8aadb80
Show file tree
Hide file tree
Showing 118 changed files with 1,631 additions and 715 deletions.
15 changes: 15 additions & 0 deletions .sourcery/AutomaticRuleTests.stencil
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import SwiftLintFramework
import XCTest

// swiftlint:disable file_length single_test_class type_name

{% for rule in types.structs|based:"AutomaticTestableRule" %}
class {{ rule.name }}Tests: XCTestCase {
func testWithDefaultConfiguration() {
verifyRule({{ rule.name }}.description)
}
}

{% endfor %}
// just to avoid a file_name warning
private struct AutomaticRuleTests {}
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ VERSION_STRING=$(shell /usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionSt

all: build

sourcery: Tests/LinuxMain.swift Source/SwiftLintFramework/Models/MasterRuleList.swift
sourcery: Tests/LinuxMain.swift Source/SwiftLintFramework/Models/MasterRuleList.swift Tests/SwiftLintFrameworkTests/AutomaticRuleTests.swift

Tests/LinuxMain.swift: Tests/*/*.swift .sourcery/LinuxMain.stencil
sourcery --sources Tests --templates .sourcery/LinuxMain.stencil --output .sourcery
sourcery --sources Tests --templates .sourcery/LinuxMain.stencil --output .sourcery --force-parse generated
mv .sourcery/LinuxMain.generated.swift Tests/LinuxMain.swift

Source/SwiftLintFramework/Models/MasterRuleList.swift: Source/SwiftLintFramework/Rules/*.swift .sourcery/MasterRuleList.stencil
sourcery --sources Source/SwiftLintFramework/Rules --templates .sourcery/MasterRuleList.stencil --output .sourcery
mv .sourcery/MasterRuleList.generated.swift Source/SwiftLintFramework/Models/MasterRuleList.swift

Tests/SwiftLintFrameworkTests/AutomaticRuleTests.generated.swift: Source/SwiftLintFramework/Rules/*.swift .sourcery/AutomaticRuleTests.stencil
sourcery --sources Source/SwiftLintFramework/Rules --templates .sourcery/AutomaticRuleTests.stencil --output .sourcery
mv .sourcery/AutomaticRuleTests.generated.swift Tests/SwiftLintFrameworkTests/AutomaticRuleTests.generated.swift

bootstrap:
script/bootstrap

Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Models/MasterRuleList.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated using Sourcery 0.13.1 — https://github.com/krzysztofzablocki/Sourcery
// Generated using Sourcery 0.11.2 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT

public let masterRuleList = RuleList(rules: [
Expand Down
2 changes: 2 additions & 0 deletions Source/SwiftLintFramework/Protocols/Rule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ extension Rule {

public protocol OptInRule: Rule {}

public protocol AutomaticTestableRule: Rule {}

public protocol ConfigurationProviderRule: Rule {
associatedtype ConfigurationType: RuleConfiguration

Expand Down
3 changes: 2 additions & 1 deletion Source/SwiftLintFramework/Rules/AnyObjectProtocolRule.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Foundation
import SourceKittenFramework

public struct AnyObjectProtocolRule: ASTRule, OptInRule, CorrectableRule, ConfigurationProviderRule {
public struct AnyObjectProtocolRule: ASTRule, OptInRule, CorrectableRule,
ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/ArrayInitRule.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct ArrayInitRule: ASTRule, ConfigurationProviderRule, OptInRule {
public struct ArrayInitRule: ASTRule, ConfigurationProviderRule, OptInRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/BlockBasedKVORule.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct BlockBasedKVORule: ASTRule, ConfigurationProviderRule {
public struct BlockBasedKVORule: ASTRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct ClassDelegateProtocolRule: ASTRule, ConfigurationProviderRule {
public struct ClassDelegateProtocolRule: ASTRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/ClosingBraceRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ private extension File {
}
}

public struct ClosingBraceRule: CorrectableRule, ConfigurationProviderRule {
public struct ClosingBraceRule: CorrectableRule, ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct ClosureEndIndentationRule: Rule, OptInRule, ConfigurationProviderRule {
public struct ClosureEndIndentationRule: Rule, OptInRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct ClosureParameterPositionRule: ASTRule, ConfigurationProviderRule {
public struct ClosureParameterPositionRule: ASTRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/ClosureSpacingRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension NSRange {
}
}

public struct ClosureSpacingRule: CorrectableRule, ConfigurationProviderRule, OptInRule {
public struct ClosureSpacingRule: CorrectableRule, ConfigurationProviderRule, OptInRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/CommaRule.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct CommaRule: CorrectableRule, ConfigurationProviderRule {
public struct CommaRule: CorrectableRule, ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct CompilerProtocolInitRule: ASTRule, ConfigurationProviderRule {
public struct CompilerProtocolInitRule: ASTRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct ConditionalReturnsOnNewlineRule: ConfigurationProviderRule, Rule, OptInRule {
public struct ConditionalReturnsOnNewlineRule: ConfigurationProviderRule, Rule, OptInRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SourceKittenFramework

public struct ContainsOverFirstNotNilRule: CallPairRule, OptInRule, ConfigurationProviderRule {
public struct ContainsOverFirstNotNilRule: CallPairRule, OptInRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/ControlStatementRule.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SourceKittenFramework

public struct ControlStatementRule: ConfigurationProviderRule {
public struct ControlStatementRule: ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/ConvenienceTypeRule.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SourceKittenFramework

public struct ConvenienceTypeRule: ASTRule, OptInRule, ConfigurationProviderRule {
public struct ConvenienceTypeRule: ASTRule, OptInRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct DiscardedNotificationCenterObserverRule: ASTRule, ConfigurationProviderRule {
public struct DiscardedNotificationCenterObserverRule: ASTRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct DiscouragedObjectLiteralRule: ASTRule, OptInRule, ConfigurationProviderRule {
public struct DiscouragedObjectLiteralRule: ASTRule, OptInRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct DiscouragedOptionalBooleanRule: OptInRule, ConfigurationProviderRule {
public struct DiscouragedOptionalBooleanRule: OptInRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct DiscouragedOptionalCollectionRule: ASTRule, OptInRule, ConfigurationProviderRule {
public struct DiscouragedOptionalCollectionRule: ASTRule, OptInRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/DynamicInlineRule.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct DynamicInlineRule: ASTRule, ConfigurationProviderRule {
public struct DynamicInlineRule: ASTRule, ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.error)

Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/EmptyCountRule.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SourceKittenFramework

public struct EmptyCountRule: ConfigurationProviderRule, OptInRule {
public struct EmptyCountRule: ConfigurationProviderRule, OptInRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.error)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private func wrapInFunc(_ str: String) -> String {
"""
}

public struct EmptyEnumArgumentsRule: ASTRule, ConfigurationProviderRule, CorrectableRule {
public struct EmptyEnumArgumentsRule: ASTRule, ConfigurationProviderRule, CorrectableRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/EmptyParametersRule.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct EmptyParametersRule: ConfigurationProviderRule, CorrectableRule {
public struct EmptyParametersRule: ConfigurationProviderRule, CorrectableRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Foundation
import SourceKittenFramework

public struct EmptyParenthesesWithTrailingClosureRule: ASTRule, CorrectableRule, ConfigurationProviderRule {
public struct EmptyParenthesesWithTrailingClosureRule: ASTRule, CorrectableRule, ConfigurationProviderRule,
AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/EmptyStringRule.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SourceKittenFramework

public struct EmptyStringRule: ConfigurationProviderRule, OptInRule {
public struct EmptyStringRule: ConfigurationProviderRule, OptInRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct EmptyXCTestMethodRule: Rule, OptInRule, ConfigurationProviderRule {
public struct EmptyXCTestMethodRule: Rule, OptInRule, ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/ExplicitACLRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SourceKittenFramework

private typealias SourceKittenElement = [String: SourceKitRepresentable]

public struct ExplicitACLRule: OptInRule, ConfigurationProviderRule {
public struct ExplicitACLRule: OptInRule, ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct ExplicitEnumRawValueRule: ASTRule, OptInRule, ConfigurationProviderRule {
public struct ExplicitEnumRawValueRule: ASTRule, OptInRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/ExplicitInitRule.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct ExplicitInitRule: ASTRule, ConfigurationProviderRule, CorrectableRule, OptInRule {
public struct ExplicitInitRule: ASTRule, ConfigurationProviderRule, CorrectableRule, OptInRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct ExplicitTopLevelACLRule: OptInRule, ConfigurationProviderRule {
public struct ExplicitTopLevelACLRule: OptInRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct ExtensionAccessModifierRule: ASTRule, ConfigurationProviderRule, OptInRule {
public struct ExtensionAccessModifierRule: ASTRule, ConfigurationProviderRule, OptInRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/FallthroughRule.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SourceKittenFramework

public struct FallthroughRule: ConfigurationProviderRule, OptInRule {
public struct FallthroughRule: ConfigurationProviderRule, OptInRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct FatalErrorMessageRule: ASTRule, ConfigurationProviderRule, OptInRule {
public struct FatalErrorMessageRule: ASTRule, ConfigurationProviderRule, OptInRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/FirstWhereRule.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SourceKittenFramework

public struct FirstWhereRule: CallPairRule, OptInRule, ConfigurationProviderRule {
public struct FirstWhereRule: CallPairRule, OptInRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/ForWhereRule.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct ForWhereRule: ASTRule, ConfigurationProviderRule {
public struct ForWhereRule: ASTRule, ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/ForceCastRule.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SourceKittenFramework

public struct ForceCastRule: ConfigurationProviderRule {
public struct ForceCastRule: ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.error)

Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/ForceTryRule.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SourceKittenFramework

public struct ForceTryRule: ConfigurationProviderRule {
public struct ForceTryRule: ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.error)

Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/ForceUnwrappingRule.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct ForceUnwrappingRule: OptInRule, ConfigurationProviderRule {
public struct ForceUnwrappingRule: OptInRule, ConfigurationProviderRule, AutomaticTestableRule {

public var configuration = SeverityConfiguration(.warning)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SourceKittenFramework

public struct FunctionDefaultParameterAtEndRule: ASTRule, ConfigurationProviderRule, OptInRule {
public struct FunctionDefaultParameterAtEndRule: ASTRule, ConfigurationProviderRule, OptInRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/ImplicitGetterRule.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework

public struct ImplicitGetterRule: ConfigurationProviderRule {
public struct ImplicitGetterRule: ConfigurationProviderRule, AutomaticTestableRule {
public var configuration = SeverityConfiguration(.warning)

public init() {}
Expand Down
Loading

0 comments on commit 8aadb80

Please sign in to comment.