Skip to content

Commit

Permalink
Compare rule IDs and configurations with reference (#5510)
Browse files Browse the repository at this point in the history
This new test ensures that rule IDs and their option names do not get
changed inadvertently.

The file can easily be updated by running:

```bash
swift run swiftlint rules --config-only --default-config > Tests/IntegrationTests/default_rule_configurations.yml
```
  • Loading branch information
SimplyDanny committed Mar 26, 2024
1 parent 299042a commit 1c0d28f
Show file tree
Hide file tree
Showing 4 changed files with 655 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ let package = Package(
"SwiftLintFramework",
"SwiftLintTestHelpers"
],
exclude: [
"default_rule_configurations.yml"
],
swiftSettings: swiftFeatures
),
.testTarget(
Expand Down
5 changes: 4 additions & 1 deletion Tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ swift_library(

swift_test(
name = "IntegrationTests",
data = ["//:LintInputs"],
data = [
"//:LintInputs",
"IntegrationTests/default_rule_configurations.yml"
],
visibility = ["//visibility:public"],
deps = [":IntegrationTests.library"],
)
Expand Down
17 changes: 17 additions & 0 deletions Tests/IntegrationTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ class IntegrationTests: SwiftLintTestCase {
}
}

func testDefaultConfigurations() {
let defaultConfig = Configuration(rulesMode: .allEnabled).rules
.map { type(of: $0) }
.filter { $0.identifier != "custom_rules" }
.map {
"""
\($0.identifier):
\($0.init().configurationDescription.yaml().indent(by: 2))
"""
}
.joined(separator: "\n")
let referenceFile = URL(fileURLWithPath: #file)
.deletingLastPathComponent()
.appendingPathComponent("default_rule_configurations.yml")
XCTAssertEqual(defaultConfig + "\n", try String(contentsOf: referenceFile))
}

func testSimulateHomebrewTest() {
// Since this test uses the `swiftlint` binary built while building `SwiftLintPackageTests`,
// we run it only on macOS using SwiftPM.
Expand Down
Loading

0 comments on commit 1c0d28f

Please sign in to comment.