Files
SwiftLint/Tests/SwiftLintFrameworkTests/CompilerProtocolInitRuleTests.swift
T
Zev Eisenberg fcf848608e Add Inline test failure messages (#3040)
* Add Example wrapper in order to display test failures inline when running in Xcode.
* Stop using Swift 5.1-only features so we can compile on Xcode 10.2.
* Wrap strings in Example.
* Add Changelog entry.
* Wrap all examples in Example struct.
* Better and more complete capturing of line numbers.
* Fix broken test.
* Better test traceability.
* Address or disable linting warnings.
* Add documentation comments.
* Disable linter for a few cases.
* Limit mutability and add copy-and-mutate utility functions.
* Limit scope of mutability.
2020-02-02 10:35:37 +02:00

42 lines
1.4 KiB
Swift

@testable import SwiftLintFramework
import XCTest
class CompilerProtocolInitRuleTests: XCTestCase {
private let ruleID = CompilerProtocolInitRule.description.identifier
func testWithDefaultConfiguration() {
verifyRule(CompilerProtocolInitRule.description)
}
func testViolationMessageForExpressibleByIntegerLiteral() throws {
let config = try XCTUnwrap(makeConfig(nil, ruleID))
let allViolations = violations(Example("let a = NSNumber(integerLiteral: 1)"), config: config)
let compilerProtocolInitViolation = allViolations.first { $0.ruleIdentifier == ruleID }
let violation = try XCTUnwrap(
compilerProtocolInitViolation,
"A compiler protocol init violation should have been triggered!"
)
XCTAssertEqual(
violation.reason,
"The initializers declared in compiler protocol ExpressibleByIntegerLiteral shouldn't be called directly."
)
}
}
// https://bugs.swift.org/browse/SR-11501
#if compiler(<5.1) || (SWIFT_PACKAGE && os(macOS))
private enum UnwrapError: Error {
case missingValue
}
private func XCTUnwrap<T>(_ expression: @autoclosure () throws -> T?,
_ message: @autoclosure () -> String = "") throws -> T {
if let value = try expression() {
return value
} else {
throw UnwrapError.missingValue
}
}
#endif