Files
SwiftLint/Source/SwiftLintFramework/Rules/Lint/TestCaseAccessibilityRuleExamples.swift
T
Keith Smiley 7976b74615 Add test functions with parameters to TestCaseAccessibilityRule (#3612)
If a function starts with `test` but takes some parameters, it is not
actually a test.
2021-04-26 20:04:04 +00:00

141 lines
2.9 KiB
Swift

internal struct TestCaseAccessibilityRuleExamples {
static let nonTriggeringExamples = [
// Valid XCTestCase class
Example("""
let foo: String?
class FooTests: XCTestCase {
static let allTests: [String] = []
private let foo: String {
let nestedMember = "hi"
return nestedMember
}
override static func setUp() {
super.setUp()
}
override func setUp() {
super.setUp()
}
override func setUpWithError() throws {
try super.setUpWithError()
}
override static func tearDown() {
super.tearDown()
}
override func tearDown() {
super.tearDown()
}
override func tearDownWithError() {
try super.tearDownWithError()
}
override func someFutureXCTestFunction() {
super.someFutureXCTestFunction()
}
func testFoo() {
XCTAssertTrue(true)
}
func testBar() {
func nestedFunc() {}
}
private someFunc(hasParam: Bool) {}
}
"""),
Example("""
class FooTests: XCTestCase {
func allowedPrefixTestFoo() {}
}
""", configuration: ["allowed_prefixes": ["allowedPrefix"]]),
// Not an XCTestCase class
Example("""
class Foobar {
func setUp() {}
func tearDown() {}
func testFoo() {}
}
""")
]
static let triggeringExamples = [
Example("""
class FooTests: XCTestCase {
↓var foo: String?
↓let bar: String?
↓static func foo() {}
↓func setUp(withParam: String) {}
↓func foobar() {}
↓func not_testBar() {}
↓enum Nested {}
↓static func testFoo() {}
↓static func allTests() {}
↓func testFoo(hasParam: Bool) {}
}
final class BarTests: XCTestCase {
↓class Nested {}
}
""")
]
static let corrections = [
Example("""
class TotoTests: XCTestCase {
↓var foo: Bar?
↓struct Baz {}
override func setUp() {}
override func tearDown() {}
func testFoo() {}
func testBar() {}
↓func helperFunction() {}
}
"""):
Example("""
class TotoTests: XCTestCase {
private var foo: Bar?
private struct Baz {}
override func setUp() {}
override func tearDown() {}
func testFoo() {}
func testBar() {}
private func helperFunction() {}
}
""")
]
}