Skip to content

Commit d881cd1

Browse files
committed
Modify tests to check the rule and the pipline have the same findings.
Previously we only tested the rule in isolation. This mean we weren't actually checking the pipeline respected the SyntaxVisitorContinueKind. Regardless of what the pipeline did, the tests would respect the continue kind because they run the rule itself. Now we run the rule in isolation and the pipeline and assert that they have the same findings. This ensures the rule behaves as expected (or atleast as tested) when run in the pipeline.
1 parent c6386ad commit d881cd1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Tests/SwiftFormatTests/Rules/LintOrFormatRuleTestCase.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@ class LintOrFormatRuleTestCase: DiagnosingTestCase {
5050
context: context,
5151
file: file,
5252
line: line)
53+
54+
var emittedPipelineFindings = [Finding]()
55+
// Disable default rules, so only select rule runs in pipeline
56+
configuration.rules = [type.ruleName: true]
57+
let pipeline = SwiftLinter(
58+
configuration: configuration,
59+
findingConsumer: { emittedPipelineFindings.append($0) })
60+
pipeline.debugOptions.insert(.disablePrettyPrint)
61+
try! pipeline.lint(
62+
syntax: sourceFileSyntax,
63+
operatorTable: OperatorTable.standardOperators,
64+
assumingFileURL: URL(string: file.description)!)
65+
66+
// Check that pipeline produces the same findings as the isolated linter rule
67+
assertFindings(
68+
expected: findings,
69+
markerLocations: markedText.markers,
70+
emittedFindings: emittedPipelineFindings,
71+
context: context,
72+
file: file,
73+
line: line)
5374
}
5475

5576
/// Asserts that the result of applying a formatter to the provided input code yields the output.
@@ -111,5 +132,20 @@ class LintOrFormatRuleTestCase: DiagnosingTestCase {
111132
printTokenStream: false,
112133
whitespaceOnly: false
113134
).prettyPrint()
135+
136+
var emittedPipelineFindings = [Finding]()
137+
// Disable default rules, so only select rule runs in pipeline
138+
configuration.rules = [formatType.ruleName: true]
139+
let pipeline = SwiftFormatter(
140+
configuration: configuration, findingConsumer: { emittedPipelineFindings.append($0) })
141+
pipeline.debugOptions.insert(.disablePrettyPrint)
142+
var pipelineActual = ""
143+
try! pipeline.format(
144+
syntax: sourceFileSyntax, operatorTable: OperatorTable.standardOperators,
145+
assumingFileURL: nil, to: &pipelineActual)
146+
assertStringsEqualWithDiff(pipelineActual, expected)
147+
assertFindings(
148+
expected: findings, markerLocations: markedInput.markers,
149+
emittedFindings: emittedPipelineFindings, context: context, file: file, line: line)
114150
}
115151
}

0 commit comments

Comments
 (0)