Skip to content

Commit ca86e5d

Browse files
committed
Add a performance test for the whitespace linter.
1 parent 5d38f55 commit ca86e5d

File tree

4 files changed

+104
-6
lines changed

4 files changed

+104
-6
lines changed

Package.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,31 +95,39 @@ let package = Package(
9595
]
9696
),
9797
.testTarget(
98-
name: "SwiftFormatPrettyPrintTests",
98+
name: "SwiftFormatCoreTests",
9999
dependencies: [
100100
"SwiftFormatConfiguration",
101101
"SwiftFormatCore",
102-
"SwiftFormatPrettyPrint",
103-
"SwiftFormatRules",
102+
"SwiftSyntax",
103+
]
104+
),
105+
.testTarget(
106+
name: "SwiftFormatPerformanceTests",
107+
dependencies: [
104108
"SwiftFormatTestSupport",
109+
"SwiftFormatWhitespaceLinter",
105110
"SwiftSyntax",
106111
]
107112
),
108113
.testTarget(
109-
name: "SwiftFormatWhitespaceLinterTests",
114+
name: "SwiftFormatPrettyPrintTests",
110115
dependencies: [
111116
"SwiftFormatConfiguration",
112117
"SwiftFormatCore",
118+
"SwiftFormatPrettyPrint",
119+
"SwiftFormatRules",
113120
"SwiftFormatTestSupport",
114-
"SwiftFormatWhitespaceLinter",
115121
"SwiftSyntax",
116122
]
117123
),
118124
.testTarget(
119-
name: "SwiftFormatCoreTests",
125+
name: "SwiftFormatWhitespaceLinterTests",
120126
dependencies: [
121127
"SwiftFormatConfiguration",
122128
"SwiftFormatCore",
129+
"SwiftFormatTestSupport",
130+
"SwiftFormatWhitespaceLinter",
123131
"SwiftSyntax",
124132
]
125133
),

Tests/LinuxMain.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import XCTest
22

33
import SwiftFormatConfigurationTests
44
import SwiftFormatCoreTests
5+
import SwiftFormatPerformanceTests
56
import SwiftFormatPrettyPrintTests
67
import SwiftFormatRulesTests
78
import SwiftFormatTests
@@ -10,6 +11,7 @@ import SwiftFormatWhitespaceLinterTests
1011
var tests = [XCTestCaseEntry]()
1112
tests += SwiftFormatConfigurationTests.__allTests()
1213
tests += SwiftFormatCoreTests.__allTests()
14+
tests += SwiftFormatPerformanceTests.__allTests()
1315
tests += SwiftFormatPrettyPrintTests.__allTests()
1416
tests += SwiftFormatRulesTests.__allTests()
1517
tests += SwiftFormatTests.__allTests()
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import SwiftFormatTestSupport
2+
import SwiftFormatWhitespaceLinter
3+
import SwiftSyntax
4+
import XCTest
5+
6+
final class WhitespaceLinterPerformanceTests: DiagnosingTestCase {
7+
func testWhitespaceLinterPerformance() {
8+
let input = String(
9+
repeating: """
10+
import SomeModule
11+
public class SomeClass : SomeProtocol
12+
{
13+
var someProperty : SomeType {
14+
get{5}set{doSomething()}
15+
}
16+
public
17+
func
18+
someFunctionName
19+
(
20+
firstArg : FirstArgument , secondArg :
21+
SecondArgument){
22+
doSomeThings()
23+
}}
24+
25+
""",
26+
count: 20
27+
)
28+
let expected = String(
29+
repeating: """
30+
import SomeModule
31+
public class SomeClass: SomeProtocol {
32+
var someProperty: SomeType {
33+
get { 5 }
34+
set { doSomething() }
35+
}
36+
public func someFunctionName(
37+
firstArg: FirstArgument,
38+
secondArg: SecondArgument
39+
) {
40+
doSomeThings()
41+
}
42+
}
43+
44+
""",
45+
count: 20
46+
)
47+
48+
measure { performWhitespaceLint(input: input, expected: expected) }
49+
}
50+
51+
/// Perform whitespace linting by comparing the input text from the user with the expected
52+
/// formatted text, using the default configuration.
53+
///
54+
/// - Parameters:
55+
/// - input: The user's input text.
56+
/// - expected: The formatted text.
57+
private func performWhitespaceLint(input: String, expected: String) {
58+
let sourceFileSyntax: SourceFileSyntax
59+
do {
60+
sourceFileSyntax = try SyntaxParser.parse(source: input)
61+
} catch {
62+
XCTFail("Parsing failed with error: \(error)")
63+
return
64+
}
65+
66+
let context = makeContext(sourceFileSyntax: sourceFileSyntax)
67+
let linter = WhitespaceLinter(user: input, formatted: expected, context: context)
68+
linter.lint()
69+
}
70+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#if !canImport(ObjectiveC)
2+
import XCTest
3+
4+
extension WhitespaceLinterPerformanceTests {
5+
// DO NOT MODIFY: This is autogenerated, use:
6+
// `swift test --generate-linuxmain`
7+
// to regenerate.
8+
static let __allTests__WhitespaceLinterPerformanceTests = [
9+
("testWhitespaceLinterPerformance", testWhitespaceLinterPerformance),
10+
]
11+
}
12+
13+
public func __allTests() -> [XCTestCaseEntry] {
14+
return [
15+
testCase(WhitespaceLinterPerformanceTests.__allTests__WhitespaceLinterPerformanceTests),
16+
]
17+
}
18+
#endif

0 commit comments

Comments
 (0)