Files
SwiftLint/Tests/CoreTests/DisableAllTests.swift
Danny Mösch ac2eda6732 Adopt Swift Testing
# 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
2026-06-06 11:07:04 +02:00

117 lines
4.5 KiB
Swift

import Foundation
import SwiftLintCore
import TestHelpers
import Testing
@Suite(.rulesRegistered)
struct DisableAllTests {
/// Example violations. Could be replaced with other single violations.
private static let violatingPhrases = [
Example("let r = 0"), // Violates identifier_name
Example(#"let myString:String = """#), // Violates colon_whitespace
Example("// TODO: Some todo"), // Violates todo
]
// MARK: Violating Phrase
/// Tests whether example violating phrases trigger when not applying disable rule
@Test(arguments: violatingPhrases)
func violatingPhrase(_ violatingPhrase: Example) {
#expect(violations(violatingPhrase.with(code: violatingPhrase.code + "\n")).count == 1)
}
// MARK: Enable / Disable Base
/// Tests whether swiftlint:disable all protects properly
@Test(arguments: violatingPhrases)
func disableAll(_ violatingPhrase: Example) {
let code = "// swiftlint:disable all\n" + violatingPhrase.code + "\n// swiftlint:enable all\n"
let protectedPhrase = violatingPhrase.with(code: code)
#expect(violations(protectedPhrase).isEmpty)
}
/// Tests whether swiftlint:enable all unprotects properly
@Test(arguments: violatingPhrases)
func enableAll(_ violatingPhrase: Example) {
let unprotectedPhrase = violatingPhrase.with(
code: """
// swiftlint:disable all
\(violatingPhrase.code)
// swiftlint:enable all
\(violatingPhrase.code)\n
""")
#expect(violations(unprotectedPhrase).count == 1)
}
// MARK: Enable / Disable Previous
/// Tests whether swiftlint:disable:previous all protects properly
@Test(arguments: violatingPhrases)
func disableAllPrevious(_ violatingPhrase: Example) {
let protectedPhrase =
violatingPhrase
.with(
code: """
\(violatingPhrase.code)
// swiftlint:disable:previous all\n
""")
#expect(violations(protectedPhrase).isEmpty)
}
/// Tests whether swiftlint:enable:previous all unprotects properly
@Test(arguments: violatingPhrases)
func enableAllPrevious(_ violatingPhrase: Example) {
let unprotectedPhrase = violatingPhrase.with(
code: """
// swiftlint:disable all
\(violatingPhrase.code)
\(violatingPhrase.code)
// swiftlint:enable:previous all
// swiftlint:enable all
""")
#expect(violations(unprotectedPhrase).count == 1)
}
// MARK: Enable / Disable Next
/// Tests whether swiftlint:disable:next all protects properly
@Test(arguments: violatingPhrases)
func disableAllNext(_ violatingPhrase: Example) {
let protectedPhrase = violatingPhrase.with(code: "// swiftlint:disable:next all\n" + violatingPhrase.code)
#expect(violations(protectedPhrase).isEmpty)
}
/// Tests whether swiftlint:enable:next all unprotects properly
@Test(arguments: violatingPhrases)
func enableAllNext(_ violatingPhrase: Example) {
let unprotectedPhrase = violatingPhrase.with(
code: """
// swiftlint:disable all
\(violatingPhrase.code)
// swiftlint:enable:next all
\(violatingPhrase.code)
// swiftlint:enable all
""")
#expect(violations(unprotectedPhrase).count == 1)
}
// MARK: Enable / Disable This
/// Tests whether swiftlint:disable:this all protects properly
@Test(arguments: violatingPhrases)
func disableAllThis(_ violatingPhrase: Example) {
let rawViolatingPhrase = violatingPhrase.code.replacingOccurrences(of: "\n", with: "")
let protectedPhrase = violatingPhrase.with(code: rawViolatingPhrase + "// swiftlint:disable:this all\n")
#expect(violations(protectedPhrase).isEmpty)
}
/// Tests whether swiftlint:enable:next all unprotects properly
@Test(arguments: violatingPhrases)
func enableAllThis(_ violatingPhrase: Example) {
let rawViolatingPhrase = violatingPhrase.code.replacingOccurrences(of: "\n", with: "")
let unprotectedPhrase = violatingPhrase.with(
code: """
// swiftlint:disable all
\(violatingPhrase.code)
\(rawViolatingPhrase)// swiftlint:enable:this all
// swiftlint:enable all
""")
#expect(violations(unprotectedPhrase).count == 1)
}
}