mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
# Conflicts: # Tests/BuiltInRulesTests/FileHeaderRuleTests.swift # Tests/BuiltInRulesTests/FileNameNoSpaceRuleTests.swift # Tests/BuiltInRulesTests/IndentationWidthRuleTests.swift # Tests/CoreTests/RegexConfigurationTests.swift # Tests/CoreTests/SwiftLintFileTests.swift # Tests/FileSystemAccessTests/BaselineTests.swift # Tests/FileSystemAccessTests/ConfigurationTests+Mock.swift # Tests/FileSystemAccessTests/ConfigurationTests.swift # Tests/FileSystemAccessTests/GlobTests.swift # Tests/FileSystemAccessTests/MultipleConfigurationsTests.swift # Tests/FileSystemAccessTests/ReporterTests.swift # Tests/FileSystemAccessTests/SourceKitCrashTests.swift # Tests/FrameworkTests/CustomRulesTests.swift # Tests/FrameworkTests/LinterCacheTests.swift # Tests/FrameworkTests/RuleConfigurationTests.swift # Tests/FrameworkTests/SwiftVersionTests.swift # Tests/GeneratedTests/GeneratedTests_02.swift # Tests/GeneratedTests/GeneratedTests_03.swift # Tests/GeneratedTests/GeneratedTests_04.swift # Tests/GeneratedTests/GeneratedTests_05.swift # Tests/GeneratedTests/GeneratedTests_06.swift # Tests/GeneratedTests/GeneratedTests_07.swift # Tests/GeneratedTests/GeneratedTests_08.swift # Tests/GeneratedTests/GeneratedTests_09.swift # Tests/GeneratedTests/GeneratedTests_10.swift # Tests/IntegrationTests/ConfigPathResolutionTests.swift # Tests/IntegrationTests/IntegrationTests.swift # Tests/TestHelpers/TestHelpers.swift
66 lines
2.2 KiB
Swift
66 lines
2.2 KiB
Swift
import TestHelpers
|
|
import Testing
|
|
|
|
@testable import SwiftLintBuiltInRules
|
|
@testable import SwiftLintCore
|
|
|
|
@Suite(.rulesRegistered)
|
|
struct NoEmptyBlockConfigurationTests {
|
|
@Test
|
|
func defaultConfiguration() {
|
|
let config = NoEmptyBlockConfiguration()
|
|
#expect(config.severityConfiguration.severity == .warning)
|
|
#expect(config.enabledBlockTypes == NoEmptyBlockConfiguration.CodeBlockType.all)
|
|
}
|
|
|
|
@Test
|
|
func applyingCustomConfiguration() throws {
|
|
var config = NoEmptyBlockConfiguration()
|
|
try config.apply(
|
|
configuration: [
|
|
"severity": "error",
|
|
"disabled_block_types": ["function_bodies"],
|
|
] as [String: any Sendable]
|
|
)
|
|
#expect(config.severityConfiguration.severity == .error)
|
|
#expect(config.enabledBlockTypes == Set([.initializerBodies, .statementBlocks, .closureBlocks]))
|
|
}
|
|
|
|
@Test
|
|
func invalidKeyInCustomConfiguration() async throws {
|
|
let console = try await Issue.captureConsole {
|
|
var config = NoEmptyBlockConfiguration()
|
|
try config.apply(configuration: ["invalidKey": "error"])
|
|
}
|
|
#expect(
|
|
console == "warning: Configuration for 'no_empty_block' rule contains the invalid key(s) 'invalidKey'."
|
|
)
|
|
}
|
|
|
|
@Test
|
|
func invalidTypeOfCustomConfiguration() {
|
|
var config = NoEmptyBlockConfiguration()
|
|
#expect(throws: Issue.invalidConfiguration(ruleID: NoEmptyBlockRule.identifier)) {
|
|
try config.apply(configuration: "invalidKey")
|
|
}
|
|
}
|
|
|
|
@Test
|
|
func invalidTypeOfValueInCustomConfiguration() {
|
|
var config = NoEmptyBlockConfiguration()
|
|
#expect(throws: Issue.invalidConfiguration(ruleID: NoEmptyBlockRule.identifier)) {
|
|
try config.apply(configuration: ["severity": "foo"])
|
|
}
|
|
}
|
|
|
|
@Test
|
|
func consoleDescription() throws {
|
|
var config = NoEmptyBlockConfiguration()
|
|
try config.apply(configuration: ["disabled_block_types": ["initializer_bodies", "statement_blocks"]])
|
|
#expect(
|
|
RuleConfigurationDescription.from(configuration: config).oneLiner()
|
|
== "severity: warning; disabled_block_types: [initializer_bodies, statement_blocks]"
|
|
)
|
|
}
|
|
}
|