mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
Current events have renewed the conversation in our community about the roles of terminology with racist connotations in our software. Many companies and developers are now taking appropriate steps to remove this terminology from their codebases and products. (e.g. [GitHub](https://twitter.com/natfriedman/status/1271253144442253312)) This small rule prevents the use of declarations that contain any of the terms: whitelist, blacklist, master, and slave. It may be appropriate to add more terms to this list now or in the future.
72 lines
2.8 KiB
Swift
72 lines
2.8 KiB
Swift
@testable import SwiftLintFramework
|
|
import XCTest
|
|
|
|
class SourceKitCrashTests: XCTestCase {
|
|
func testAssertHandlerIsNotCalledOnNormalFile() {
|
|
let file = SwiftLintFile(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 SwiftLintFile.structure")
|
|
|
|
assertHandlerCalled = false
|
|
_ = file.syntaxMap
|
|
XCTAssertFalse(assertHandlerCalled,
|
|
"Expects assert handler was not called on accessing SwiftLintFile.syntaxMap")
|
|
|
|
assertHandlerCalled = false
|
|
_ = file.syntaxKindsByLines
|
|
XCTAssertFalse(assertHandlerCalled,
|
|
"Expects assert handler was not called on accessing SwiftLintFile.syntaxKindsByLines")
|
|
|
|
assertHandlerCalled = false
|
|
_ = file.syntaxTokensByLines
|
|
XCTAssertFalse(assertHandlerCalled,
|
|
"Expects assert handler was not called on accessing SwiftLintFile.syntaxTokensByLines")
|
|
}
|
|
|
|
func testAssertHandlerIsCalledOnFileThatCrashedSourceKitService() {
|
|
let file = SwiftLintFile(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 SwiftLintFile.structure")
|
|
|
|
assertHandlerCalled = false
|
|
_ = file.syntaxMap
|
|
XCTAssertTrue(assertHandlerCalled,
|
|
"Expects assert handler was called on accessing SwiftLintFile.syntaxMap")
|
|
|
|
assertHandlerCalled = false
|
|
_ = file.syntaxKindsByLines
|
|
XCTAssertTrue(assertHandlerCalled,
|
|
"Expects assert handler was called on accessing SwiftLintFile.syntaxKindsByLines")
|
|
|
|
assertHandlerCalled = false
|
|
_ = file.syntaxTokensByLines
|
|
XCTAssertTrue(assertHandlerCalled,
|
|
"Expects assert handler was not called on accessing SwiftLintFile.syntaxTokensByLines")
|
|
}
|
|
|
|
func testRulesWithFileThatCrashedSourceKitService() {
|
|
let file = SwiftLintFile(path: #file)!
|
|
file.sourcekitdFailed = true
|
|
file.assertHandler = {
|
|
XCTFail("If this called, rule's SourceKitFreeRule is not properly configured")
|
|
}
|
|
let configuration = Configuration(rulesMode: .only(allRuleIdentifiers))!
|
|
let storage = RuleStorage()
|
|
_ = Linter(file: file, configuration: configuration).collect(into: storage).styleViolations(using: storage)
|
|
file.sourcekitdFailed = false
|
|
file.assertHandler = nil
|
|
}
|
|
}
|