Files
SwiftLint/Tests/SwiftLintFrameworkTests/IntegrationTests.swift
T
JP Simard b83e0991b9 Remove all file headers
The MIT license doesn't require that all files be prepended with this
licensing or copyright information. Realm confirmed that they're ok with this
change. This will enable some companies to contribute to SwiftLint and the
date & authorship information will remain accessible via git source control.
2018-05-04 13:42:02 -07:00

57 lines
2.0 KiB
Swift

import Foundation
import SourceKittenFramework
import SwiftLintFramework
import XCTest
let config: Configuration = {
let directory = #file.bridge()
.deletingLastPathComponent.bridge()
.deletingLastPathComponent.bridge()
.deletingLastPathComponent
_ = FileManager.default.changeCurrentDirectoryPath(directory)
return Configuration(path: Configuration.fileName)
}()
class IntegrationTests: XCTestCase {
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)
XCTAssert(swiftFiles.map({ $0.path! }).contains(#file), "current file should be included")
let violations = swiftFiles.flatMap {
Linter(file: $0, configuration: config).styleViolations
}
violations.forEach { violation in
violation.location.file!.withStaticString {
XCTFail(violation.reason, file: $0, line: UInt(violation.location.line!))
}
}
}
func testSwiftLintAutoCorrects() {
let swiftFiles = config.lintableFiles(inPath: "", forceExclude: false)
let corrections = swiftFiles.flatMap { Linter(file: $0, configuration: config).correct() }
for correction in corrections {
correction.location.file!.withStaticString {
XCTFail(correction.ruleDescription.description,
file: $0, line: UInt(correction.location.line!))
}
}
}
}
extension String {
func withStaticString(_ closure: (StaticString) -> Void) {
withCString {
let rawPointer = $0._rawValue
let byteSize = lengthOfBytes(using: .utf8)._builtinWordValue
let isASCII = true._getBuiltinLogicValue()
let staticString = StaticString(_builtinStringLiteral: rawPointer,
utf8CodeUnitCount: byteSize,
isASCII: isASCII)
closure(staticString)
}
}
}