Move ExtraRulesTests to its own target & directory (#4300)
Also create a SwiftLintTestHelpers test target.
This commit is contained in:
parent
8470b65ae9
commit
503f8c506b
|
@ -1,4 +1,5 @@
|
|||
import SwiftLintFramework
|
||||
import SwiftLintTestHelpers
|
||||
import XCTest
|
||||
|
||||
// swiftlint:disable file_length single_test_class type_name
|
||||
|
|
|
@ -59,14 +59,29 @@ let package = Package(
|
|||
name: "SwiftLintFramework",
|
||||
dependencies: frameworkDependencies
|
||||
),
|
||||
.target(
|
||||
name: "SwiftLintTestHelpers",
|
||||
dependencies: [
|
||||
"SwiftLintFramework"
|
||||
],
|
||||
path: "Tests/SwiftLintTestHelpers"
|
||||
),
|
||||
.testTarget(
|
||||
name: "SwiftLintFrameworkTests",
|
||||
dependencies: [
|
||||
"SwiftLintFramework"
|
||||
"SwiftLintFramework",
|
||||
"SwiftLintTestHelpers"
|
||||
],
|
||||
exclude: [
|
||||
"Resources",
|
||||
]
|
||||
),
|
||||
.testTarget(
|
||||
name: "ExtraRulesTests",
|
||||
dependencies: [
|
||||
"SwiftLintFramework",
|
||||
"SwiftLintTestHelpers"
|
||||
]
|
||||
),
|
||||
]
|
||||
)
|
||||
|
|
17
Tests/BUILD
17
Tests/BUILD
|
@ -20,6 +20,18 @@ swift_test(
|
|||
deps = [":CLITests.library"],
|
||||
)
|
||||
|
||||
# SwiftLintTestHelpers
|
||||
|
||||
swift_library(
|
||||
name = "SwiftLintTestHelpers",
|
||||
testonly = True,
|
||||
srcs = glob(["SwiftLintTestHelpers/**/*.swift"]),
|
||||
module_name = "SwiftLintTestHelpers",
|
||||
deps = [
|
||||
"//:SwiftLintFramework",
|
||||
],
|
||||
)
|
||||
|
||||
# SwiftLintFrameworkTests
|
||||
|
||||
filegroup(
|
||||
|
@ -51,6 +63,7 @@ swift_library(
|
|||
module_name = "SwiftLintFrameworkTests",
|
||||
deps = [
|
||||
"//:SwiftLintFramework",
|
||||
":SwiftLintTestHelpers",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -77,8 +90,7 @@ swift_library(
|
|||
name = "ExtraRulesTests.library",
|
||||
testonly = True,
|
||||
srcs = [
|
||||
"SwiftLintFrameworkTests/ExtraRulesTests.swift",
|
||||
"SwiftLintFrameworkTests/TestHelpers.swift",
|
||||
"ExtraRulesTests/ExtraRulesTests.swift",
|
||||
] + select({
|
||||
"@platforms//os:linux": [":ExtraRulesLinuxMain"],
|
||||
"//conditions:default": [],
|
||||
|
@ -86,6 +98,7 @@ swift_library(
|
|||
module_name = "ExtraRulesTests",
|
||||
deps = [
|
||||
"//:SwiftLintFramework",
|
||||
":SwiftLintTestHelpers",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
@testable import SwiftLintFramework
|
||||
import SwiftLintTestHelpers
|
||||
import XCTest
|
||||
|
||||
final class ExtraRulesTests: XCTestCase {
|
|
@ -0,0 +1,3 @@
|
|||
// These imports are re-exported to make them available implicitly to all files.
|
||||
// swiftlint:disable unused_import
|
||||
@_exported import SwiftLintTestHelpers
|
|
@ -1,6 +1,7 @@
|
|||
// Generated using Sourcery 1.8.2 — https://github.com/krzysztofzablocki/Sourcery
|
||||
// DO NOT EDIT
|
||||
import SwiftLintFramework
|
||||
import SwiftLintTestHelpers
|
||||
import XCTest
|
||||
|
||||
// swiftlint:disable file_length single_test_class type_name
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import SwiftLintFramework
|
||||
|
||||
extension RuleDescription {
|
||||
public extension RuleDescription {
|
||||
func with(nonTriggeringExamples: [Example],
|
||||
triggeringExamples: [Example]) -> RuleDescription {
|
||||
return RuleDescription(identifier: identifier,
|
|
@ -41,15 +41,15 @@ private extension SwiftLintFile {
|
|||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
public extension String {
|
||||
func stringByAppendingPathComponent(_ pathComponent: String) -> String {
|
||||
return bridge().appendingPathComponent(pathComponent)
|
||||
}
|
||||
}
|
||||
|
||||
let allRuleIdentifiers = Set(primaryRuleList.list.keys)
|
||||
public let allRuleIdentifiers = Set(primaryRuleList.list.keys)
|
||||
|
||||
extension Configuration {
|
||||
public extension Configuration {
|
||||
func applyingConfiguration(from example: Example) -> Configuration {
|
||||
guard let exampleConfiguration = example.configuration,
|
||||
case let .only(onlyRules) = self.rulesMode,
|
||||
|
@ -60,8 +60,8 @@ extension Configuration {
|
|||
}
|
||||
}
|
||||
|
||||
func violations(_ example: Example, config inputConfig: Configuration = Configuration.default,
|
||||
requiresFileOnDisk: Bool = false) -> [StyleViolation] {
|
||||
public func violations(_ example: Example, config inputConfig: Configuration = Configuration.default,
|
||||
requiresFileOnDisk: Bool = false) -> [StyleViolation] {
|
||||
SwiftLintFile.clearCaches()
|
||||
let config = inputConfig.applyingConfiguration(from: example)
|
||||
let stringStrippingMarkers = example.removingViolationMarkers()
|
||||
|
@ -79,7 +79,7 @@ func violations(_ example: Example, config inputConfig: Configuration = Configur
|
|||
return linter.styleViolations(using: storage).withoutFiles()
|
||||
}
|
||||
|
||||
extension Collection where Element == String {
|
||||
public extension Collection where Element == String {
|
||||
func violations(config: Configuration = Configuration.default, requiresFileOnDisk: Bool = false)
|
||||
-> [StyleViolation] {
|
||||
return map { SwiftLintFile.testFile(withContents: $0, persistToDisk: requiresFileOnDisk) }
|
||||
|
@ -92,7 +92,7 @@ extension Collection where Element == String {
|
|||
}
|
||||
}
|
||||
|
||||
extension Collection where Element: SwiftLintFile {
|
||||
public extension Collection where Element: SwiftLintFile {
|
||||
func violations(config: Configuration = Configuration.default, requiresFileOnDisk: Bool = false)
|
||||
-> [StyleViolation] {
|
||||
let storage = RuleStorage()
|
||||
|
@ -141,7 +141,7 @@ private extension Collection where Element == Correction {
|
|||
}
|
||||
}
|
||||
|
||||
extension Collection where Element == Example {
|
||||
public extension Collection where Element == Example {
|
||||
/// Returns a dictionary with SwiftLint violation markers (↓) removed from keys.
|
||||
///
|
||||
/// - returns: A new `Array`.
|
||||
|
@ -228,12 +228,14 @@ private extension Configuration {
|
|||
// With SwiftSyntax rewriters, the visitors get called with the new nodes after previous mutations have
|
||||
// been applied, so it's not straightforward to translate those back into the original source positions.
|
||||
// So only check the first locations
|
||||
XCTAssertEqual(
|
||||
corrections.first!.location,
|
||||
expectedLocations.first!,
|
||||
#function + ".correction location",
|
||||
file: before.file, line: before.line
|
||||
)
|
||||
if let firstCorrection = corrections.first {
|
||||
XCTAssertEqual(
|
||||
firstCorrection.location,
|
||||
expectedLocations.first,
|
||||
#function + ".correction location",
|
||||
file: before.file, line: before.line
|
||||
)
|
||||
}
|
||||
}
|
||||
XCTAssertEqual(
|
||||
file.contents,
|
||||
|
@ -262,8 +264,8 @@ private extension String {
|
|||
}
|
||||
}
|
||||
|
||||
internal func makeConfig(_ ruleConfiguration: Any?, _ identifier: String,
|
||||
skipDisableCommandTests: Bool = false) -> Configuration? {
|
||||
public func makeConfig(_ ruleConfiguration: Any?, _ identifier: String,
|
||||
skipDisableCommandTests: Bool = false) -> Configuration? {
|
||||
let superfluousDisableCommandRuleIdentifier = SuperfluousDisableCommandRule.description.identifier
|
||||
let identifiers: Set<String> = skipDisableCommandTests ? [identifier]
|
||||
: [identifier, superfluousDisableCommandRuleIdentifier]
|
||||
|
@ -312,7 +314,7 @@ private func addShebang(_ example: Example) -> Example {
|
|||
return example.with(code: "#!/usr/bin/env swift\n\(example.code)")
|
||||
}
|
||||
|
||||
extension XCTestCase {
|
||||
public extension XCTestCase {
|
||||
var isRunningWithBazel: Bool { FileManager.default.currentDirectoryPath.contains("bazel-out") }
|
||||
|
||||
func verifyRule(_ ruleDescription: RuleDescription,
|
Loading…
Reference in New Issue