From 6d60d03fca22eecf22429f2efafbb9a2fad93612 Mon Sep 17 00:00:00 2001 From: Ornithologist Coder Date: Tue, 9 Jan 2018 14:36:25 +0100 Subject: [PATCH] Moves tests to its own file --- .../Rules/XCTSpecificMatcherRule.swift | 2 +- SwiftLint.xcodeproj/project.pbxproj | 6 ++- .../XCTSpecificMatcherRuleTests.swift | 45 +++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 Tests/SwiftLintFrameworkTests/XCTSpecificMatcherRuleTests.swift diff --git a/Source/SwiftLintFramework/Rules/XCTSpecificMatcherRule.swift b/Source/SwiftLintFramework/Rules/XCTSpecificMatcherRule.swift index 0ef3aba30..c0168830d 100644 --- a/Source/SwiftLintFramework/Rules/XCTSpecificMatcherRule.swift +++ b/Source/SwiftLintFramework/Rules/XCTSpecificMatcherRule.swift @@ -53,7 +53,7 @@ public struct XCTSpecificMatcherRule: ASTRule, OptInRule, ConfigurationProviderR return ["false", "true", "nil"].contains(body) ? body : nil } - // If the call has a "protected" word, provides suggestion based on the first one. + // If the call has "protected" words, provides suggestion based on the first one. guard let parameter = parameters.first, let reason = matcher.suggestion(for: parameter) else { return [] } diff --git a/SwiftLint.xcodeproj/project.pbxproj b/SwiftLint.xcodeproj/project.pbxproj index a76dac891..c140fb185 100644 --- a/SwiftLint.xcodeproj/project.pbxproj +++ b/SwiftLint.xcodeproj/project.pbxproj @@ -103,6 +103,7 @@ 626D02971F31CBCC0054788D /* XCTFailMessageRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 626D02961F31CBCC0054788D /* XCTFailMessageRule.swift */; }; 627BC48D1F9405160004A6C2 /* QuickDiscouragedFocusedTestRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E54FED1F93AD57005B367B /* QuickDiscouragedFocusedTestRule.swift */; }; 629ADD062006302D0009E362 /* DiscouragedOptionalCollectionRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 629ADD052006302D0009E362 /* DiscouragedOptionalCollectionRule.swift */; }; + 627C7A322004F9290053C79D /* XCTSpecificMatcherRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 627C7A312004F9290053C79D /* XCTSpecificMatcherRuleTests.swift */; }; 629C60D91F43906700B4AF92 /* SingleTestClassRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 629C60D81F43906700B4AF92 /* SingleTestClassRule.swift */; }; 62A3E95D209E084000547A86 /* EmptyXCTestMethodRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62A3E95B209E078000547A86 /* EmptyXCTestMethodRule.swift */; }; 62A498561F306A7700D766E4 /* DiscouragedDirectInitConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62A498551F306A7700D766E4 /* DiscouragedDirectInitConfiguration.swift */; }; @@ -536,6 +537,7 @@ 626C16E01F948E1C00BB7475 /* QuickDiscouragedFocusedTestRuleExamples.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickDiscouragedFocusedTestRuleExamples.swift; sourceTree = ""; }; 626D02961F31CBCC0054788D /* XCTFailMessageRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTFailMessageRule.swift; sourceTree = ""; }; 629ADD052006302D0009E362 /* DiscouragedOptionalCollectionRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscouragedOptionalCollectionRule.swift; sourceTree = ""; }; + 627C7A312004F9290053C79D /* XCTSpecificMatcherRuleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTSpecificMatcherRuleTests.swift; sourceTree = ""; }; 629C60D81F43906700B4AF92 /* SingleTestClassRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleTestClassRule.swift; sourceTree = ""; }; 62A3E95B209E078000547A86 /* EmptyXCTestMethodRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyXCTestMethodRule.swift; sourceTree = ""; }; 62A498551F306A7700D766E4 /* DiscouragedDirectInitConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscouragedDirectInitConfiguration.swift; sourceTree = ""; }; @@ -1215,10 +1217,10 @@ D0D1212219E878CC005E4BAA /* Configuration */ = { isa = PBXGroup; children = ( + D0D1213919E878CC005E4BAA /* README.md */, D0D1212319E878CC005E4BAA /* Base */, D0D1212E19E878CC005E4BAA /* iOS */, D0D1213319E878CC005E4BAA /* Mac OS X */, - D0D1213919E878CC005E4BAA /* README.md */, ); name = Configuration; path = Carthage/Checkouts/xcconfigs; @@ -1375,6 +1377,7 @@ D4470D5A1EB76F44008A1B2E /* UnusedOptionalBindingRuleTests.swift */, 006204DD1E1E4E0A00FFFBE1 /* VerticalWhitespaceRuleTests.swift */, F480DC801F2609AB00099465 /* XCTestCase+BundlePath.swift */, + 627C7A312004F9290053C79D /* XCTSpecificMatcherRuleTests.swift */, 3B30C4A01C3785B300E04027 /* YamlParserTests.swift */, 3B12C9C21C320A53000B423F /* YamlSwiftLintTests.swift */, BCB68282216213130078E4C3 /* CompilerProtocolInitRuleTests.swift */, @@ -2129,6 +2132,7 @@ B89F3BCE1FD5EE0200931E59 /* RequiredEnumCaseRuleTestCase.swift in Sources */, C9802F2F1E0C8AEE008AB27F /* TrailingCommaRuleTests.swift in Sources */, 3B63D46F1E1F09DF0057BE35 /* LineLengthRuleTests.swift in Sources */, + 627C7A322004F9290053C79D /* XCTSpecificMatcherRuleTests.swift in Sources */, 3BCC04D41C502BAB006073C3 /* RuleConfigurationTests.swift in Sources */, E809EDA31B8A73FB00399043 /* ConfigurationTests.swift in Sources */, 8F2CC1CD20A6A189006ED34F /* FileNameRuleTests.swift in Sources */, diff --git a/Tests/SwiftLintFrameworkTests/XCTSpecificMatcherRuleTests.swift b/Tests/SwiftLintFrameworkTests/XCTSpecificMatcherRuleTests.swift new file mode 100644 index 000000000..7253081bc --- /dev/null +++ b/Tests/SwiftLintFrameworkTests/XCTSpecificMatcherRuleTests.swift @@ -0,0 +1,45 @@ +// +// XCTSpecificMatcherRuleTests.swift +// SwiftLint +// +// Created by Ornithologist Coder on 1/9/18. +// Copyright © 2018 Realm. All rights reserved. +// + +import SwiftLintFramework +import XCTest + +class XCTSpecificMatcherRuleTests: XCTestCase { + + func testRule() { + verifyRule(XCTSpecificMatcherRule.description) + } + + // MARK: - Additional Tests + + func testEqualNilNil() { + let string = "XCTAssertEqual(nil, nil)" + let violations = self.violations(string) + XCTAssertEqual(violations.count, 1) + XCTAssertEqual(violations.first!.reason, "Prefer the specific matcher 'XCTAssertNil' instead.") + } + + func testEqualTrueTrue() { + let string = "XCTAssertEqual(true, true)" + let violations = self.violations(string) + XCTAssertEqual(violations.count, 1) + XCTAssertEqual(violations.first!.reason, "Prefer the specific matcher 'XCTAssertTrue' instead.") + } + + func testEqualFalseFalse() { + let string = "XCTAssertEqual(false, false)" + let violations = self.violations(string) + XCTAssertEqual(violations.count, 1) + XCTAssertEqual(violations.first!.reason, "Prefer the specific matcher 'XCTAssertFalse' instead.") + } + + private func violations(_ string: String) -> [StyleViolation] { + let config = makeConfig(nil, XCTSpecificMatcherRule.description.identifier)! + return SwiftLintFrameworkTests.violations(string, config: config) + } +}