Files
SwiftLint/Tests/SwiftLintFrameworkTests/SourceKitCrashTests.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

74 lines
2.7 KiB
Swift

import Foundation
import SourceKittenFramework
@testable import SwiftLintFramework
import XCTest
class SourceKitCrashTests: XCTestCase {
func testAssertHandlerIsNotCalledOnNormalFile() {
let file = File(contents: "A file didn't crash SourceKitService")
file.sourcekitdFailed = false
var assertHandlerCalled = false
file.assertHandler = { assertHandlerCalled = true }
_ = file.structure
XCTAssertFalse(assertHandlerCalled,
"Expects assert handler was not called on accessing File.structure")
assertHandlerCalled = false
_ = file.syntaxMap
XCTAssertFalse(assertHandlerCalled,
"Expects assert handler was not called on accessing File.syntaxMap")
assertHandlerCalled = false
_ = file.syntaxKindsByLines
XCTAssertFalse(assertHandlerCalled,
"Expects assert handler was not called on accessing File.syntaxKindsByLines")
assertHandlerCalled = false
_ = file.syntaxTokensByLines
XCTAssertFalse(assertHandlerCalled,
"Expects assert handler was not called on accessing File.syntaxTokensByLines")
}
func testAssertHandlerIsCalledOnFileThatCrashedSourceKitService() {
let file = File(contents: "A file crashed SourceKitService")
file.sourcekitdFailed = true
var assertHandlerCalled = false
file.assertHandler = { assertHandlerCalled = true }
_ = file.structure
XCTAssertTrue(assertHandlerCalled,
"Expects assert handler was called on accessing File.structure")
assertHandlerCalled = false
_ = file.syntaxMap
XCTAssertTrue(assertHandlerCalled,
"Expects assert handler was called on accessing File.syntaxMap")
assertHandlerCalled = false
_ = file.syntaxKindsByLines
XCTAssertTrue(assertHandlerCalled,
"Expects assert handler was called on accessing File.syntaxKindsByLines")
assertHandlerCalled = false
_ = file.syntaxTokensByLines
XCTAssertTrue(assertHandlerCalled,
"Expects assert handler was not called on accessing File.syntaxTokensByLines")
}
func testRulesWithFileThatCrashedSourceKitService() {
let file = File(path: #file)!
file.sourcekitdFailed = true
file.assertHandler = {
XCTFail("If this called, rule's SourceKitFreeRule is not properly configured")
}
let configuration = Configuration(rulesMode: .whitelisted(allRuleIdentifiers))!
_ = Linter(file: file, configuration: configuration).styleViolations
file.sourcekitdFailed = false
file.assertHandler = nil
}
}