Skip to content

Commit

Permalink
automatically generate LinuxMain.swift using Sourcery
Browse files Browse the repository at this point in the history
This adds 6 tests that were accidentally not being run on Linux:

* LineLengthConfigurationTests.testLineLengthConfigurationInitialiserSetsIgnoresComments
* LineLengthConfigurationTests.testLineLengthConfigurationInitialiserSetsIgnoresFunctionDeclarations
* LineLengthConfigurationTests.testLineLengthConfigurationThrowsOnBadConfigValues
* LineLengthRuleTests.testLineLengthWithIgnoreCommentsEnabled
* LineLengthRuleTests.testLineLengthWithIgnoreFunctionDeclarationsEnabled
* RegionTests.testSeveralRegionsFromSeveralCommands
  • Loading branch information
jpsim committed Jun 2, 2017
1 parent b9bec52 commit 25a92c4
Show file tree
Hide file tree
Showing 36 changed files with 449 additions and 551 deletions.
24 changes: 24 additions & 0 deletions .sourcery/LinuxMain.stencil
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// LinuxMain.swift
// SwiftLint
//
// Created by JP Simard on 12/11/16.
// Copyright © 2016 Realm. All rights reserved.
//

@testable import SwiftLintFrameworkTests
import XCTest

// swiftlint:disable line_length file_length

{% for type in types.classes|based:"XCTestCase" %}
extension {{ type.name }} {
static var allTests: [(String, ({{ type.name }}) -> () throws -> Void)] = [
{% for method in type.methods where method.parameters.count == 0 and method.shortName|hasPrefix:"test" %} ("{{ method.shortName }}", {{ method.shortName }}){% if not forloop.last %},{% endif %}
{% endfor %}]
}

{% endfor %}
XCTMain([
{% for type in types.classes|based:"XCTestCase" %} testCase({{ type.name }}.allTests){% if not forloop.last %},{% endif %}
{% endfor %}])
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ $ swift test
$ make docker_test
```

XCTest functions that are added need to be mirrored in the `allTests` static var
in the test class extensions at the bottom of the test files.
If XCTest cases or functions are added/removed/renamed, you'll need to run
`make update_linux_tests`, which requires that
[Sourcery](https://github.com/krzysztofzablocki/Sourcery) be installed on your
machine.

## Rules

Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ VERSION_STRING=$(shell /usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionSt
all: bootstrap
$(BUILD_TOOL) $(XCODEFLAGS) build

update_linux_tests:
sourcery --sources Tests --templates .sourcery --output .sourcery
tail -n +4 .sourcery/LinuxMain.generated.swift > Tests/LinuxMain.swift
rm .sourcery/LinuxMain.generated.swift

bootstrap:
script/bootstrap

Expand Down
417 changes: 416 additions & 1 deletion Tests/LinuxMain.swift

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions Tests/SwiftLintFrameworkTests/AttributesRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,3 @@ class AttributesRuleTests: XCTestCase {
ruleConfiguration: ["always_on_line_above": ["@objc"]])
}
}

extension AttributesRuleTests {
static var allTests: [(String, (AttributesRuleTests) -> () throws -> Void)] {
return [
("testAttributesWithDefaultConfiguration", testAttributesWithDefaultConfiguration),
("testAttributesWithAlwaysOnSameLine", testAttributesWithAlwaysOnSameLine),
("testAttributesWithAlwaysOnLineAbove", testAttributesWithAlwaysOnLineAbove)
]
}
}
10 changes: 0 additions & 10 deletions Tests/SwiftLintFrameworkTests/ColonRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,3 @@ class ColonRuleTests: XCTestCase {
verifyRule(description, ruleConfiguration: ["apply_to_dictionaries": false])
}
}

extension ColonRuleTests {
static var allTests: [(String, (ColonRuleTests) -> () throws -> Void)] {
return [
("testColonWithDefaultConfiguration", testColonWithDefaultConfiguration),
("testColonWithFlexibleRightSpace", testColonWithFlexibleRightSpace),
("testColonWithoutApplyToDictionaries", testColonWithoutApplyToDictionaries)
]
}
}
22 changes: 0 additions & 22 deletions Tests/SwiftLintFrameworkTests/CommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,25 +211,3 @@ class CommandTests: XCTestCase {
}
}
}

extension CommandTests {
static var allTests: [(String, (CommandTests) -> () throws -> Void)] {
return [
("testNoCommandsInEmptyFile", testNoCommandsInEmptyFile),
("testEmptyString", testEmptyString),
("testDisable", testDisable),
("testDisablePrevious", testDisablePrevious),
("testDisableThis", testDisableThis),
("testDisableNext", testDisableNext),
("testEnable", testEnable),
("testEnablePrevious", testEnablePrevious),
("testEnableThis", testEnableThis),
("testEnableNext", testEnableNext),
("testActionInverse", testActionInverse),
("testNoModifierCommandExpandsToItself", testNoModifierCommandExpandsToItself),
("testExpandPreviousCommand", testExpandPreviousCommand),
("testExpandThisCommand", testExpandThisCommand),
("testExpandNextCommand", testExpandNextCommand)
]
}
}
31 changes: 0 additions & 31 deletions Tests/SwiftLintFrameworkTests/ConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -304,34 +304,3 @@ fileprivate extension XCTestCase {
return projectMockPathLevel3.stringByAppendingPathComponent("Level3.swift")
}
}

extension ConfigurationTests {
static var allTests: [(String, (ConfigurationTests) -> () throws -> Void)] {
return [
("testInit", testInit),
("testEmptyConfiguration", testEmptyConfiguration),
("testWhitelistRules", testWhitelistRules),
("testWarningThreshold_value", testWarningThreshold_value),
("testWarningThreshold_nil", testWarningThreshold_nil),
("testOtherRuleConfigurationsAlongsideWhitelistRules",
testOtherRuleConfigurationsAlongsideWhitelistRules),
("testDisabledRules", testDisabledRules),
("testDisabledRulesWithUnknownRule", testDisabledRulesWithUnknownRule),
("testExcludedPaths", testExcludedPaths),
("testIsEqualTo", testIsEqualTo),
("testIsNotEqualTo", testIsNotEqualTo),
("testMerge", testMerge),
("testLevel0", testLevel0),
("testLevel1", testLevel1),
("testLevel2", testLevel2),
("testLevel3", testLevel3),
("testConfiguresCorrectlyFromDict", testConfiguresCorrectlyFromDict),
("testConfigureFallsBackCorrectly", testConfigureFallsBackCorrectly),
("testConfiguresCorrectlyFromDeprecatedAlias", testConfiguresCorrectlyFromDeprecatedAlias),
("testReturnsNilWithDuplicatedConfiguration", testReturnsNilWithDuplicatedConfiguration),
("testInitsFromDeprecatedAlias", testInitsFromDeprecatedAlias),
("testWhitelistRulesFromDeprecatedAlias", testWhitelistRulesFromDeprecatedAlias),
("testDisabledRulesFromDeprecatedAlias", testDisabledRulesFromDeprecatedAlias)
]
}
}
21 changes: 0 additions & 21 deletions Tests/SwiftLintFrameworkTests/CustomRulesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,3 @@ class CustomRulesTests: XCTestCase {
return File(path: "\(bundlePath)/test.txt")!
}
}

extension CustomRulesTests {
static var allTests: [(String, (CustomRulesTests) -> () throws -> Void)] {
return [
("testCustomRuleConfigurationSetsCorrectly",
testCustomRuleConfigurationSetsCorrectly),
("testCustomRuleConfigurationThrows",
testCustomRuleConfigurationThrows),
("testCustomRules",
testCustomRules),
("testLocalDisableCustomRule",
testLocalDisableCustomRule),
("testCustomRulesIncludedDefault",
testCustomRulesIncludedDefault),
("testCustomRulesIncludedExcludesFile",
testCustomRulesIncludedExcludesFile),
("testCustomRulesExcludedExcludesFile",
testCustomRulesExcludedExcludesFile)
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,3 @@ class CyclomaticComplexityConfigurationTests: XCTestCase {
}

}

extension CyclomaticComplexityConfigurationTests {
static var allTests: [(String, (CyclomaticComplexityConfigurationTests) -> () throws -> Void)] {
return [
("testCyclomaticComplexityConfigurationInitializerSetsLevels",
testCyclomaticComplexityConfigurationInitializerSetsLevels),
("testCyclomaticComplexityConfigurationInitializerSetsIgnoresCaseStatements",
testCyclomaticComplexityConfigurationInitializerSetsIgnoresCaseStatements),
("testCyclomaticComplexityConfigurationThrowsOnBadConfigValues",
testCyclomaticComplexityConfigurationThrowsOnBadConfigValues),
("testCyclomaticComplexityConfigurationApplyConfigurationWithDictionary",
testCyclomaticComplexityConfigurationApplyConfigurationWithDictionary),
("testCyclomaticComplexityConfigurationCompares",
testCyclomaticComplexityConfigurationCompares)
]
}
}
13 changes: 0 additions & 13 deletions Tests/SwiftLintFrameworkTests/CyclomaticComplexityRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,3 @@ class CyclomaticComplexityRuleTests: XCTestCase {
}

}

extension CyclomaticComplexityRuleTests {
static var allTests: [(String, (CyclomaticComplexityRuleTests) -> () throws -> Void)] {
return [
("testCyclomaticComplexity",
testCyclomaticComplexity),
("testIgnoresCaseStatementsConfigurationEnabled",
testIgnoresCaseStatementsConfigurationEnabled),
("testIgnoresCaseStatementsConfigurationDisabled",
testIgnoresCaseStatementsConfigurationDisabled)
]
}
}
9 changes: 0 additions & 9 deletions Tests/SwiftLintFrameworkTests/ExtendedNSStringTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,3 @@ class ExtendedNSStringTests: XCTestCase {
}
}
}

extension ExtendedNSStringTests {
static var allTests: [(String, (ExtendedNSStringTests) -> () throws -> Void)] {
return [
("testLineAndCharacterForByteOffset_forContentsContainingMultibyteCharacters",
testLineAndCharacterForByteOffset_forContentsContainingMultibyteCharacters)
]
}
}
12 changes: 0 additions & 12 deletions Tests/SwiftLintFrameworkTests/FileHeaderRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,3 @@ class FileHeaderRuleTests: XCTestCase {
skipCommentTests: true)
}
}

extension FileHeaderRuleTests {
static var allTests: [(String, (FileHeaderRuleTests) -> () throws -> Void)] {
return [
("testFileHeaderWithDefaultConfiguration", testFileHeaderWithDefaultConfiguration),
("testFileHeaderWithRequiredString", testFileHeaderWithRequiredString),
("testFileHeaderWithRequiredPattern", testFileHeaderWithRequiredPattern),
("testFileHeaderWithForbiddenString", testFileHeaderWithForbiddenString),
("testFileHeaderWithForbiddenPattern", testFileHeaderWithForbiddenPattern)
]
}
}
13 changes: 0 additions & 13 deletions Tests/SwiftLintFrameworkTests/FunctionBodyLengthRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,3 @@ class FunctionBodyLengthRuleTests: XCTestCase {
return SwiftLintFrameworkTests.violations(string, config: config)
}
}

extension FunctionBodyLengthRuleTests {
static var allTests: [(String, (FunctionBodyLengthRuleTests) -> () throws -> Void)] {
return [
("testFunctionBodyLengths",
testFunctionBodyLengths),
("testFunctionBodyLengthsWithComments",
testFunctionBodyLengthsWithComments),
("testFunctionBodyLengthsWithMultilineComments",
testFunctionBodyLengthsWithMultilineComments)
]
}
}
10 changes: 0 additions & 10 deletions Tests/SwiftLintFrameworkTests/GenericTypeNameRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,3 @@ class GenericTypeNameRuleTests: XCTestCase {
verifyRule(description, ruleConfiguration: ["validates_start_lowercase": false])
}
}

extension GenericTypeNameRuleTests {
static var allTests: [(String, (GenericTypeNameRuleTests) -> () throws -> Void)] {
return [
("testGenericTypeName", testGenericTypeName),
("testGenericTypeNameWithAllowedSymbols", testGenericTypeNameWithAllowedSymbols),
("testGenericTypeNameWithIgnoreStartWithLowercase", testGenericTypeNameWithIgnoreStartWithLowercase)
]
}
}
10 changes: 0 additions & 10 deletions Tests/SwiftLintFrameworkTests/IdentifierNameRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,3 @@ class IdentifierNameRuleTests: XCTestCase {
verifyRule(description, ruleConfiguration: ["validates_start_lowercase": false])
}
}

extension IdentifierNameRuleTests {
static var allTests: [(String, (IdentifierNameRuleTests) -> () throws -> Void)] {
return [
("testIdentifierName", testIdentifierName),
("testIdentifierNameWithAllowedSymbols", testIdentifierNameWithAllowedSymbols),
("testIdentifierNameWithIgnoreStartWithLowercase", testIdentifierNameWithIgnoreStartWithLowercase)
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,3 @@ class ImplicitlyUnwrappedOptionalConfigurationTests: XCTestCase {
}

}

extension ImplicitlyUnwrappedOptionalConfigurationTests {
static var allTests: [(String, (ImplicitlyUnwrappedOptionalConfigurationTests) -> () throws -> Void)] {
return [
("testImplicitlyUnwrappedOptionalConfigurationProperlyAppliesConfigurationFromDictionary",
testImplicitlyUnwrappedOptionalConfigurationProperlyAppliesConfigurationFromDictionary),
("testImplicitlyUnwrappedOptionalConfigurationThrowsOnBadConfig",
testImplicitlyUnwrappedOptionalConfigurationThrowsOnBadConfig)
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,3 @@ class ImplicitlyUnwrappedOptionalRuleTests: XCTestCase {
commentDoesntViolate: true, stringDoesntViolate: true)
}
}

extension ImplicitlyUnwrappedOptionalRuleTests {
static var allTests: [(String, (ImplicitlyUnwrappedOptionalRuleTests) -> () throws -> Void)] {
return [
("testImplicitlyUnwrappedOptionalRuleDefaultConfiguration",
testImplicitlyUnwrappedOptionalRuleDefaultConfiguration),
("testImplicitlyUnwrappedOptionalRuleWarnsOnOutletsInAllMode",
testImplicitlyUnwrappedOptionalRuleWarnsOnOutletsInAllMode)
]
}
}
9 changes: 0 additions & 9 deletions Tests/SwiftLintFrameworkTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,3 @@ extension String {
}
}
}

extension IntegrationTests {
static var allTests: [(String, (IntegrationTests) -> () throws -> Void)] {
return [
("testSwiftLintLints", testSwiftLintLints),
("testSwiftLintAutoCorrects", testSwiftLintAutoCorrects)
]
}
}
23 changes: 0 additions & 23 deletions Tests/SwiftLintFrameworkTests/LineLengthConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,26 +192,3 @@ class LineLengthConfigurationTests: XCTestCase {
XCTAssertTrue(configuration2 == configuration6)
}
}

extension LineLengthConfigurationTests {
static var allTests: [(String, (LineLengthConfigurationTests) -> () throws -> Void)] {
return [
("testLineLengthConfigurationInitializerSetsLength",
testLineLengthConfigurationInitializerSetsLength),
("testLineLengthConfigurationInitialiserSetsIgnoresURLs",
testLineLengthConfigurationInitialiserSetsIgnoresURLs),
("testLineLengthConfigurationPartialParams",
testLineLengthConfigurationPartialParams),
("testLineLengthConfigurationParams",
testLineLengthConfigurationParams),
("testLineLengthConfigurationThrowsOnBadConfig",
testLineLengthConfigurationThrowsOnBadConfig),
("testLineLengthConfigurationApplyConfigurationWithArray",
testLineLengthConfigurationApplyConfigurationWithArray),
("testLineLengthConfigurationApplyConfigurationWithDictionary",
testLineLengthConfigurationApplyConfigurationWithDictionary),
("testLineLengthConfigurationCompares",
testLineLengthConfigurationCompares)
]
}
}
9 changes: 0 additions & 9 deletions Tests/SwiftLintFrameworkTests/LineLengthRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,3 @@ class LineLengthRuleTests: XCTestCase {
commentDoesntViolate: false, stringDoesntViolate: false)
}
}

extension LineLengthRuleTests {
static var allTests: [(String, (LineLengthRuleTests) -> () throws -> Void)] {
return [
("testLineLength", testLineLength),
("testLineLengthWithIgnoreURLsEnabled", testLineLengthWithIgnoreURLsEnabled)
]
}
}
32 changes: 0 additions & 32 deletions Tests/SwiftLintFrameworkTests/LinterCacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,35 +308,3 @@ class LinterCacheTests: XCTestCase {
validateNewConfigDoesntHitCache(dict: [:], initialConfig: initialConfig)
}
}

extension LinterCacheTests {
static var allTests: [(String, (LinterCacheTests) -> () throws -> Void)] {
return [
("testInitThrowsWhenUsingInvalidCacheFormat", testInitThrowsWhenUsingInvalidCacheFormat),
("testSaveThrowsWithNoLocation", testSaveThrowsWithNoLocation),
("testInitSucceeds", testInitSucceeds),
("testUnchangedFilesReusesCache", testUnchangedFilesReusesCache),
("testConfigFileReorderedReusesCache", testConfigFileReorderedReusesCache),
("testConfigFileWhitespaceAndCommentsChangedOrAddedOrRemovedReusesCache",
testConfigFileWhitespaceAndCommentsChangedOrAddedOrRemovedReusesCache),
("testConfigFileUnrelatedKeysChangedOrAddedOrRemovedReusesCache",
testConfigFileUnrelatedKeysChangedOrAddedOrRemovedReusesCache),
("testChangedFileCausesJustThatFileToBeLintWithCacheUsedForAllOthers",
testChangedFileCausesJustThatFileToBeLintWithCacheUsedForAllOthers),
("testFileRemovedPreservesThatFileInTheCacheAndDoesntCauseAnyOtherFilesToBeLinted",
testFileRemovedPreservesThatFileInTheCacheAndDoesntCauseAnyOtherFilesToBeLinted),
("testCustomRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted",
testCustomRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted),
("testDisabledRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted",
testDisabledRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted),
("testOptInRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted",
testOptInRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted),
("testEnabledRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted",
testEnabledRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted),
("testWhitelistRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted",
testWhitelistRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted),
("testRuleConfigurationChangedOrAddedOrRemovedCausesAllFilesToBeReLinted",
testRuleConfigurationChangedOrAddedOrRemovedCausesAllFilesToBeReLinted)
]
}
}
Loading

0 comments on commit 25a92c4

Please sign in to comment.