Files
SwiftLint/Source/SwiftLintFramework/Rules/Lint/EmptyXCTestMethodRuleExamples.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

159 lines
3.1 KiB
Swift

internal struct EmptyXCTestMethodRuleExamples {
static let nonTriggeringExamples = [
// Valid XCTestCase class
Example("""
class TotoTests: XCTestCase {
var foobar: Foobar?
override func setUp() {
super.setUp()
foobar = Foobar()
}
override func tearDown() {
foobar = nil
super.tearDown()
}
func testFoo() {
XCTAssertTrue(foobar?.foo)
}
func testBar() {
// comment...
XCTAssertFalse(foobar?.bar)
// comment...
}
}
"""),
// Not an XCTestCase class
Example("""
class Foobar {
func setUp() {}
func tearDown() {}
func testFoo() {}
}
"""),
// Methods with parameters
Example("""
class TotoTests: XCTestCase {
func setUp(with object: Foobar) {}
func tearDown(object: Foobar) {}
func testFoo(_ foo: Foobar) {}
func testBar(bar: (String) -> Int) {}
}
"""),
// Asserts in one line
Example("""
class TotoTests: XCTestCase {
func testFoo() { XCTAssertTrue(foobar?.foo) }
func testBar() { XCTAssertFalse(foobar?.bar) }
}
""")
]
static let triggeringExamples = [
// XCTestCase class with empty methods
Example("""
class TotoTests: XCTestCase {
override ↓func setUp() {
}
override ↓func tearDown() {
}
↓func testFoo() {
}
↓func testBar() {
}
func helperFunction() {
}
}
"""),
Example("""
class TotoTests: XCTestCase {
override ↓func setUp() {}
override ↓func tearDown() {}
↓func testFoo() {}
func helperFunction() {}
}
"""),
// XCTestCase class with comments (and blank lines)
Example("""
class TotoTests: XCTestCase {
override ↓func setUp() {
// comment...
}
override ↓func tearDown() {
// comment...
// comment...
}
↓func testFoo() {
// comment...
// comment...
// comment...
}
↓func testBar() {
/*
* comment...
*
* comment...
*
* comment...
*/
}
func helperFunction() {
}
}
"""),
// Two XCTestCase classes on the same file
Example("""
class FooTests: XCTestCase {
override ↓func setUp() {}
}
class BarTests: XCTestCase {
↓func testFoo() {}
}
""")
]
}