Enable all tests when using rules_xcodeproj (#4723)
* Revert "Skip tests requiring runfiles support when testing with rules_xcodeproj (#4694)"
This reverts commit 040096a641
.
* Enable all tests when using rules_xcodeproj
Turns out we don't need runfiles support
(https://github.com/buildbuddy-io/rules_xcodeproj/issues/828) since the
tests run outside the sandbox in Xcode, so we can get the path to these
files from the `BUILD_WORKSPACE_DIRECTORY` environment variable that
`bazel test` sets.
This commit is contained in:
parent
3907772163
commit
c84124d8bc
19
BUILD
19
BUILD
|
@ -122,18 +122,13 @@ xcodeproj(
|
||||||
"--progress",
|
"--progress",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
test_action = xcode_schemes.test_action(
|
test_action = xcode_schemes.test_action([
|
||||||
env = {
|
"//Tests:CLITests",
|
||||||
"RUNNING_RULES_XCODEPROJ_TESTS": "TRUE",
|
"//Tests:SwiftLintFrameworkTests",
|
||||||
},
|
"//Tests:GeneratedTests",
|
||||||
targets = [
|
"//Tests:IntegrationTests",
|
||||||
"//Tests:CLITests",
|
"//Tests:ExtraRulesTests",
|
||||||
"//Tests:ExtraRulesTests",
|
]),
|
||||||
"//Tests:GeneratedTests",
|
|
||||||
"//Tests:IntegrationTests",
|
|
||||||
"//Tests:SwiftLintFrameworkTests",
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
top_level_targets = [
|
top_level_targets = [
|
||||||
|
|
|
@ -2,22 +2,20 @@ import Foundation
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
@_spi(TestHelper)
|
@_spi(TestHelper)
|
||||||
import SwiftLintFramework
|
import SwiftLintFramework
|
||||||
import SwiftLintTestHelpers
|
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
private let config: Configuration = {
|
private let config: Configuration = {
|
||||||
let directory = #file.bridge()
|
let bazelWorkspaceDirectory = ProcessInfo.processInfo.environment["BUILD_WORKSPACE_DIRECTORY"]
|
||||||
|
let rootProjectDirectory = bazelWorkspaceDirectory ?? #file.bridge()
|
||||||
.deletingLastPathComponent.bridge()
|
.deletingLastPathComponent.bridge()
|
||||||
.deletingLastPathComponent.bridge()
|
.deletingLastPathComponent.bridge()
|
||||||
.deletingLastPathComponent
|
.deletingLastPathComponent
|
||||||
_ = FileManager.default.changeCurrentDirectoryPath(directory)
|
_ = FileManager.default.changeCurrentDirectoryPath(rootProjectDirectory)
|
||||||
return Configuration(configurationFiles: [Configuration.defaultFileName])
|
return Configuration(configurationFiles: [Configuration.defaultFileName])
|
||||||
}()
|
}()
|
||||||
|
|
||||||
class IntegrationTests: XCTestCase {
|
class IntegrationTests: XCTestCase {
|
||||||
func testSwiftLintLints() throws {
|
func testSwiftLintLints() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
// This is as close as we're ever going to get to a self-hosting linter.
|
// This is as close as we're ever going to get to a self-hosting linter.
|
||||||
let swiftFiles = config.lintableFiles(inPath: "", forceExclude: false)
|
let swiftFiles = config.lintableFiles(inPath: "", forceExclude: false)
|
||||||
XCTAssert(
|
XCTAssert(
|
||||||
|
@ -36,9 +34,7 @@ class IntegrationTests: XCTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSwiftLintAutoCorrects() throws {
|
func testSwiftLintAutoCorrects() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let swiftFiles = config.lintableFiles(inPath: "", forceExclude: false)
|
let swiftFiles = config.lintableFiles(inPath: "", forceExclude: false)
|
||||||
let storage = RuleStorage()
|
let storage = RuleStorage()
|
||||||
let corrections = swiftFiles.parallelFlatMap {
|
let corrections = swiftFiles.parallelFlatMap {
|
||||||
|
|
|
@ -12,9 +12,7 @@ private extension Configuration {
|
||||||
|
|
||||||
extension ConfigurationTests {
|
extension ConfigurationTests {
|
||||||
// MARK: - Rules Merging
|
// MARK: - Rules Merging
|
||||||
func testMerge() throws {
|
func testMerge() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let config0Merge2 = Mock.Config._0.merged(withChild: Mock.Config._2, rootDirectory: "")
|
let config0Merge2 = Mock.Config._0.merged(withChild: Mock.Config._2, rootDirectory: "")
|
||||||
|
|
||||||
XCTAssertFalse(Mock.Config._0.contains(rule: ForceCastRule.self))
|
XCTAssertFalse(Mock.Config._0.contains(rule: ForceCastRule.self))
|
||||||
|
@ -74,9 +72,7 @@ extension ConfigurationTests {
|
||||||
XCTAssertTrue(mergedConfiguration2.contains(rule: ForceTryRule.self))
|
XCTAssertTrue(mergedConfiguration2.contains(rule: ForceTryRule.self))
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCustomRulesMerging() throws {
|
func testCustomRulesMerging() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let mergedConfiguration = Mock.Config._0CustomRules.merged(
|
let mergedConfiguration = Mock.Config._0CustomRules.merged(
|
||||||
withChild: Mock.Config._2CustomRules,
|
withChild: Mock.Config._2CustomRules,
|
||||||
rootDirectory: ""
|
rootDirectory: ""
|
||||||
|
@ -94,9 +90,7 @@ extension ConfigurationTests {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMergingAllowsDisablingParentsCustomRules() throws {
|
func testMergingAllowsDisablingParentsCustomRules() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let mergedConfiguration = Mock.Config._0CustomRules.merged(
|
let mergedConfiguration = Mock.Config._0CustomRules.merged(
|
||||||
withChild: Mock.Config._2CustomRulesDisabled,
|
withChild: Mock.Config._2CustomRulesDisabled,
|
||||||
rootDirectory: ""
|
rootDirectory: ""
|
||||||
|
@ -114,9 +108,7 @@ extension ConfigurationTests {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCustomRulesMergingWithOnlyRulesCase1() throws {
|
func testCustomRulesMergingWithOnlyRulesCase1() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
// The base configuration is in only rules mode
|
// The base configuration is in only rules mode
|
||||||
// The child configuration is in the default rules mode
|
// The child configuration is in the default rules mode
|
||||||
// => all custom rules should be considered
|
// => all custom rules should be considered
|
||||||
|
@ -137,9 +129,7 @@ extension ConfigurationTests {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCustomRulesMergingWithOnlyRulesCase2() throws {
|
func testCustomRulesMergingWithOnlyRulesCase2() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
// The base configuration is in only rules mode
|
// The base configuration is in only rules mode
|
||||||
// The child configuration is in the only rules mode
|
// The child configuration is in the only rules mode
|
||||||
// => only the custom rules from the child configuration should be considered
|
// => only the custom rules from the child configuration should be considered
|
||||||
|
@ -161,9 +151,7 @@ extension ConfigurationTests {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCustomRulesReconfiguration() throws {
|
func testCustomRulesReconfiguration() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
// Custom Rule severity gets reconfigured to "error"
|
// Custom Rule severity gets reconfigured to "error"
|
||||||
let mergedConfiguration = Mock.Config._0CustomRulesOnly.merged(
|
let mergedConfiguration = Mock.Config._0CustomRulesOnly.merged(
|
||||||
withChild: Mock.Config._2CustomRulesReconfig,
|
withChild: Mock.Config._2CustomRulesReconfig,
|
||||||
|
@ -187,23 +175,17 @@ extension ConfigurationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Nested Configurations
|
// MARK: - Nested Configurations
|
||||||
func testLevel0() throws {
|
func testLevel0() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssertEqual(Mock.Config._0.configuration(for: SwiftLintFile(path: Mock.Swift._0)!),
|
XCTAssertEqual(Mock.Config._0.configuration(for: SwiftLintFile(path: Mock.Swift._0)!),
|
||||||
Mock.Config._0)
|
Mock.Config._0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testLevel1() throws {
|
func testLevel1() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssertEqual(Mock.Config._0.configuration(for: SwiftLintFile(path: Mock.Swift._1)!),
|
XCTAssertEqual(Mock.Config._0.configuration(for: SwiftLintFile(path: Mock.Swift._1)!),
|
||||||
Mock.Config._0)
|
Mock.Config._0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testLevel2() throws {
|
func testLevel2() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let config = Mock.Config._0.configuration(for: SwiftLintFile(path: Mock.Swift._2)!)
|
let config = Mock.Config._0.configuration(for: SwiftLintFile(path: Mock.Swift._2)!)
|
||||||
var config2 = Mock.Config._2
|
var config2 = Mock.Config._2
|
||||||
config2.fileGraph = Configuration.FileGraph(rootDirectory: Mock.Dir.level2)
|
config2.fileGraph = Configuration.FileGraph(rootDirectory: Mock.Dir.level2)
|
||||||
|
@ -214,9 +196,7 @@ extension ConfigurationTests {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testLevel3() throws {
|
func testLevel3() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let config = Mock.Config._0.configuration(for: SwiftLintFile(path: Mock.Swift._3)!)
|
let config = Mock.Config._0.configuration(for: SwiftLintFile(path: Mock.Swift._3)!)
|
||||||
var config3 = Mock.Config._3
|
var config3 = Mock.Config._3
|
||||||
config3.fileGraph = Configuration.FileGraph(rootDirectory: Mock.Dir.level3)
|
config3.fileGraph = Configuration.FileGraph(rootDirectory: Mock.Dir.level3)
|
||||||
|
@ -227,9 +207,7 @@ extension ConfigurationTests {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNestedConfigurationForOnePathPassedIn() throws {
|
func testNestedConfigurationForOnePathPassedIn() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
// If a path to one or more configuration files is specified, nested configurations should be ignored
|
// If a path to one or more configuration files is specified, nested configurations should be ignored
|
||||||
let config = Configuration(configurationFiles: [Mock.Yml._0])
|
let config = Configuration(configurationFiles: [Mock.Yml._0])
|
||||||
XCTAssertEqual(
|
XCTAssertEqual(
|
||||||
|
@ -238,9 +216,7 @@ extension ConfigurationTests {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testParentConfigIsIgnoredAsNestedConfiguration() throws {
|
func testParentConfigIsIgnoredAsNestedConfiguration() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
// If a configuration has already been used to build the main config,
|
// If a configuration has already been used to build the main config,
|
||||||
// it should not again be regarded as a nested config
|
// it should not again be regarded as a nested config
|
||||||
XCTAssertEqual(
|
XCTAssertEqual(
|
||||||
|
@ -265,9 +241,7 @@ extension ConfigurationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testValidParentConfig() throws {
|
func testValidParentConfig() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
for path in [Mock.Dir.parentConfigTest1, Mock.Dir.parentConfigTest2] {
|
for path in [Mock.Dir.parentConfigTest1, Mock.Dir.parentConfigTest2] {
|
||||||
FileManager.default.changeCurrentDirectoryPath(path)
|
FileManager.default.changeCurrentDirectoryPath(path)
|
||||||
|
|
||||||
|
@ -328,9 +302,7 @@ extension ConfigurationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Remote Configs
|
// MARK: - Remote Configs
|
||||||
func testValidRemoteChildConfig() throws {
|
func testValidRemoteChildConfig() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.remoteConfigChild)
|
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.remoteConfigChild)
|
||||||
|
|
||||||
assertEqualExceptForFileGraph(
|
assertEqualExceptForFileGraph(
|
||||||
|
@ -349,9 +321,7 @@ extension ConfigurationTests {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testValidRemoteParentConfig() throws {
|
func testValidRemoteParentConfig() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.remoteConfigParent)
|
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.remoteConfigParent)
|
||||||
|
|
||||||
assertEqualExceptForFileGraph(
|
assertEqualExceptForFileGraph(
|
||||||
|
|
|
@ -2,7 +2,6 @@ import Foundation
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
@_spi(TestHelper)
|
@_spi(TestHelper)
|
||||||
@testable import SwiftLintFramework
|
@testable import SwiftLintFramework
|
||||||
import SwiftLintTestHelpers
|
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
// swiftlint:disable file_length
|
// swiftlint:disable file_length
|
||||||
|
@ -55,9 +54,7 @@ class ConfigurationTests: XCTestCase {
|
||||||
XCTAssertFalse(config.allowZeroLintableFiles)
|
XCTAssertFalse(config.allowZeroLintableFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testInitWithRelativePathAndRootPath() throws {
|
func testInitWithRelativePathAndRootPath() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedConfig = Mock.Config._0
|
let expectedConfig = Mock.Config._0
|
||||||
|
|
||||||
let config = Configuration(configurationFiles: [".swiftlint.yml"])
|
let config = Configuration(configurationFiles: [".swiftlint.yml"])
|
||||||
|
@ -218,9 +215,7 @@ class ConfigurationTests: XCTestCase {
|
||||||
XCTAssertEqual(actualExcludedPath, desiredExcludedPath)
|
XCTAssertEqual(actualExcludedPath, desiredExcludedPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testIncludedExcludedRelativeLocationLevel0() throws {
|
func testIncludedExcludedRelativeLocationLevel0() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
// Same as testIncludedPathRelatedToConfigurationFileLocationLevel1(),
|
// Same as testIncludedPathRelatedToConfigurationFileLocationLevel1(),
|
||||||
// but run from the directory the config file resides in
|
// but run from the directory the config file resides in
|
||||||
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
|
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
|
||||||
|
@ -291,9 +286,7 @@ class ConfigurationTests: XCTestCase {
|
||||||
XCTAssertEqual(["directory/File1.swift", "directory/File2.swift"], paths)
|
XCTAssertEqual(["directory/File1.swift", "directory/File2.swift"], paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testLintablePaths() throws {
|
func testLintablePaths() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let paths = Configuration.default.lintablePaths(inPath: Mock.Dir.level0, forceExclude: false)
|
let paths = Configuration.default.lintablePaths(inPath: Mock.Dir.level0, forceExclude: false)
|
||||||
let filenames = paths.map { $0.bridge().lastPathComponent }.sorted()
|
let filenames = paths.map { $0.bridge().lastPathComponent }.sorted()
|
||||||
let expectedFilenames = [
|
let expectedFilenames = [
|
||||||
|
@ -305,9 +298,7 @@ class ConfigurationTests: XCTestCase {
|
||||||
XCTAssertEqual(Set(expectedFilenames), Set(filenames))
|
XCTAssertEqual(Set(expectedFilenames), Set(filenames))
|
||||||
}
|
}
|
||||||
|
|
||||||
func testGlobIncludePaths() throws {
|
func testGlobIncludePaths() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
|
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
|
||||||
let configuration = Configuration(includedPaths: ["**/Level2"])
|
let configuration = Configuration(includedPaths: ["**/Level2"])
|
||||||
let paths = configuration.lintablePaths(inPath: Mock.Dir.level0, forceExclude: true)
|
let paths = configuration.lintablePaths(inPath: Mock.Dir.level0, forceExclude: true)
|
||||||
|
@ -332,34 +323,26 @@ class ConfigurationTests: XCTestCase {
|
||||||
XCTAssertEqual(Mock.Config._0, Mock.Config._0)
|
XCTAssertEqual(Mock.Config._0, Mock.Config._0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testIsNotEqualTo() throws {
|
func testIsNotEqualTo() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssertNotEqual(Mock.Config._0, Mock.Config._2)
|
XCTAssertNotEqual(Mock.Config._0, Mock.Config._2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Testing Custom Configuration File
|
// MARK: - Testing Custom Configuration File
|
||||||
|
|
||||||
func testCustomConfiguration() throws {
|
func testCustomConfiguration() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let file = SwiftLintFile(path: Mock.Swift._0)!
|
let file = SwiftLintFile(path: Mock.Swift._0)!
|
||||||
XCTAssertNotEqual(Mock.Config._0.configuration(for: file),
|
XCTAssertNotEqual(Mock.Config._0.configuration(for: file),
|
||||||
Mock.Config._0Custom.configuration(for: file))
|
Mock.Config._0Custom.configuration(for: file))
|
||||||
}
|
}
|
||||||
|
|
||||||
func testConfigurationWithSwiftFileAsRoot() throws {
|
func testConfigurationWithSwiftFileAsRoot() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let configuration = Configuration(configurationFiles: [Mock.Yml._0])
|
let configuration = Configuration(configurationFiles: [Mock.Yml._0])
|
||||||
|
|
||||||
let file = SwiftLintFile(path: Mock.Swift._0)!
|
let file = SwiftLintFile(path: Mock.Swift._0)!
|
||||||
XCTAssertEqual(configuration.configuration(for: file), configuration)
|
XCTAssertEqual(configuration.configuration(for: file), configuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testConfigurationWithSwiftFileAsRootAndCustomConfiguration() throws {
|
func testConfigurationWithSwiftFileAsRootAndCustomConfiguration() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let configuration = Mock.Config._0Custom
|
let configuration = Mock.Config._0Custom
|
||||||
|
|
||||||
let file = SwiftLintFile(path: Mock.Swift._0)!
|
let file = SwiftLintFile(path: Mock.Swift._0)!
|
||||||
|
@ -412,9 +395,7 @@ class ConfigurationTests: XCTestCase {
|
||||||
|
|
||||||
// MARK: - ExcludeByPrefix option tests
|
// MARK: - ExcludeByPrefix option tests
|
||||||
extension ConfigurationTests {
|
extension ConfigurationTests {
|
||||||
func testExcludeByPrefixExcludedPaths() throws {
|
func testExcludeByPrefixExcludedPaths() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
|
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
|
||||||
let configuration = Configuration(includedPaths: ["Level1"],
|
let configuration = Configuration(includedPaths: ["Level1"],
|
||||||
excludedPaths: ["Level1/Level1.swift",
|
excludedPaths: ["Level1/Level1.swift",
|
||||||
|
@ -435,9 +416,7 @@ extension ConfigurationTests {
|
||||||
XCTAssertEqual([], paths)
|
XCTAssertEqual([], paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testExcludeByPrefixForceExcludesFileNotPresentInExcluded() throws {
|
func testExcludeByPrefixForceExcludesFileNotPresentInExcluded() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
|
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
|
||||||
let configuration = Configuration(includedPaths: ["Level1"],
|
let configuration = Configuration(includedPaths: ["Level1"],
|
||||||
excludedPaths: ["Level1/Level1.swift"])
|
excludedPaths: ["Level1/Level1.swift"])
|
||||||
|
@ -448,9 +427,7 @@ extension ConfigurationTests {
|
||||||
XCTAssertEqual(["Level2.swift", "Level3.swift"], filenames)
|
XCTAssertEqual(["Level2.swift", "Level3.swift"], filenames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testExcludeByPrefixForceExcludesDirectory() throws {
|
func testExcludeByPrefixForceExcludesDirectory() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
|
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
|
||||||
let configuration = Configuration(
|
let configuration = Configuration(
|
||||||
excludedPaths: [
|
excludedPaths: [
|
||||||
|
@ -464,9 +441,7 @@ extension ConfigurationTests {
|
||||||
XCTAssertEqual(["Level0.swift", "Level1.swift"], filenames)
|
XCTAssertEqual(["Level0.swift", "Level1.swift"], filenames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testExcludeByPrefixForceExcludesDirectoryThatIsNotInExcludedButHasChildrenThatAre() throws {
|
func testExcludeByPrefixForceExcludesDirectoryThatIsNotInExcludedButHasChildrenThatAre() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
|
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
|
||||||
let configuration = Configuration(
|
let configuration = Configuration(
|
||||||
excludedPaths: [
|
excludedPaths: [
|
||||||
|
@ -480,9 +455,7 @@ extension ConfigurationTests {
|
||||||
XCTAssertEqual(["Level0.swift"], filenames)
|
XCTAssertEqual(["Level0.swift"], filenames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testExcludeByPrefixGlobExcludePaths() throws {
|
func testExcludeByPrefixGlobExcludePaths() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
|
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
|
||||||
let configuration = Configuration(
|
let configuration = Configuration(
|
||||||
includedPaths: ["Level1"],
|
includedPaths: ["Level1"],
|
||||||
|
@ -525,9 +498,7 @@ extension ConfigurationTests {
|
||||||
//
|
//
|
||||||
// This issue may not be reproducible under normal execution: the cache is in memory, so when a user changes
|
// This issue may not be reproducible under normal execution: the cache is in memory, so when a user changes
|
||||||
// the cachePath from command line and re-runs swiftlint, cache is not reused leading to the correct behavior
|
// the cachePath from command line and re-runs swiftlint, cache is not reused leading to the correct behavior
|
||||||
func testMainInitWithCachePathAndCachedConfig() throws {
|
func testMainInitWithCachePathAndCachedConfig() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let configuration1 = Configuration(
|
let configuration1 = Configuration(
|
||||||
configurationFiles: [],
|
configurationFiles: [],
|
||||||
cachePath: "cache/path/1"
|
cachePath: "cache/path/1"
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
@testable import SwiftLintFramework
|
@testable import SwiftLintFramework
|
||||||
import SwiftLintTestHelpers
|
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
class CustomRulesTests: XCTestCase {
|
class CustomRulesTests: XCTestCase {
|
||||||
|
@ -127,18 +126,14 @@ class CustomRulesTests: XCTestCase {
|
||||||
reason: configs.0.message)])
|
reason: configs.0.message)])
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCustomRulesIncludedDefault() throws {
|
func testCustomRulesIncludedDefault() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
// Violation detected when included is omitted.
|
// Violation detected when included is omitted.
|
||||||
let (_, customRules) = getCustomRules()
|
let (_, customRules) = getCustomRules()
|
||||||
let violations = customRules.validate(file: getTestTextFile())
|
let violations = customRules.validate(file: getTestTextFile())
|
||||||
XCTAssertEqual(violations.count, 1)
|
XCTAssertEqual(violations.count, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCustomRulesIncludedExcludesFile() throws {
|
func testCustomRulesIncludedExcludesFile() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
var (regexConfig, customRules) = getCustomRules(["included": "\\.yml$"])
|
var (regexConfig, customRules) = getCustomRules(["included": "\\.yml$"])
|
||||||
|
|
||||||
var customRuleConfiguration = CustomRulesConfiguration()
|
var customRuleConfiguration = CustomRulesConfiguration()
|
||||||
|
@ -149,9 +144,7 @@ class CustomRulesTests: XCTestCase {
|
||||||
XCTAssertEqual(violations.count, 0)
|
XCTAssertEqual(violations.count, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCustomRulesExcludedExcludesFile() throws {
|
func testCustomRulesExcludedExcludesFile() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
var (regexConfig, customRules) = getCustomRules(["excluded": "\\.txt$"])
|
var (regexConfig, customRules) = getCustomRules(["excluded": "\\.txt$"])
|
||||||
|
|
||||||
var customRuleConfiguration = CustomRulesConfiguration()
|
var customRuleConfiguration = CustomRulesConfiguration()
|
||||||
|
@ -162,9 +155,7 @@ class CustomRulesTests: XCTestCase {
|
||||||
XCTAssertEqual(violations.count, 0)
|
XCTAssertEqual(violations.count, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCustomRulesExcludedArrayExcludesFile() throws {
|
func testCustomRulesExcludedArrayExcludesFile() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
var (regexConfig, customRules) = getCustomRules(["excluded": ["\\.pdf$", "\\.txt$"]])
|
var (regexConfig, customRules) = getCustomRules(["excluded": ["\\.pdf$", "\\.txt$"]])
|
||||||
|
|
||||||
var customRuleConfiguration = CustomRulesConfiguration()
|
var customRuleConfiguration = CustomRulesConfiguration()
|
||||||
|
@ -175,9 +166,7 @@ class CustomRulesTests: XCTestCase {
|
||||||
XCTAssertEqual(violations.count, 0)
|
XCTAssertEqual(violations.count, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCustomRulesCaptureGroup() throws {
|
func testCustomRulesCaptureGroup() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let (_, customRules) = getCustomRules(["regex": #"\ba\s+(\w+)"#,
|
let (_, customRules) = getCustomRules(["regex": #"\ba\s+(\w+)"#,
|
||||||
"capture_group": 1])
|
"capture_group": 1])
|
||||||
let violations = customRules.validate(file: getTestTextFile())
|
let violations = customRules.validate(file: getTestTextFile())
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
import SourceKittenFramework
|
|
||||||
@testable import SwiftLintFramework
|
@testable import SwiftLintFramework
|
||||||
import SwiftLintTestHelpers
|
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
private let fixturesDirectory = #file.bridge()
|
private let fixturesDirectory = "\(TestResources.path)/FileHeaderRuleFixtures"
|
||||||
.deletingLastPathComponent.bridge()
|
|
||||||
.appendingPathComponent("Resources/FileHeaderRuleFixtures")
|
|
||||||
|
|
||||||
class FileHeaderRuleTests: XCTestCase {
|
class FileHeaderRuleTests: XCTestCase {
|
||||||
private func validate(fileName: String, using configuration: Any) throws -> [StyleViolation] {
|
private func validate(fileName: String, using configuration: Any) throws -> [StyleViolation] {
|
||||||
|
@ -132,9 +128,7 @@ class FileHeaderRuleTests: XCTestCase {
|
||||||
skipCommentTests: true, testMultiByteOffsets: false)
|
skipCommentTests: true, testMultiByteOffsets: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testFileHeaderWithRequiredStringUsingFilenamePlaceholder() throws {
|
func testFileHeaderWithRequiredStringUsingFilenamePlaceholder() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let configuration = ["required_string": "// SWIFTLINT_CURRENT_FILENAME"]
|
let configuration = ["required_string": "// SWIFTLINT_CURRENT_FILENAME"]
|
||||||
|
|
||||||
// Non triggering tests
|
// Non triggering tests
|
||||||
|
@ -146,9 +140,7 @@ class FileHeaderRuleTests: XCTestCase {
|
||||||
XCTAssertEqual(try validate(fileName: "FileNameMissing.swift", using: configuration).count, 1)
|
XCTAssertEqual(try validate(fileName: "FileNameMissing.swift", using: configuration).count, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testFileHeaderWithForbiddenStringUsingFilenamePlaceholder() throws {
|
func testFileHeaderWithForbiddenStringUsingFilenamePlaceholder() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let configuration = ["forbidden_string": "// SWIFTLINT_CURRENT_FILENAME"]
|
let configuration = ["forbidden_string": "// SWIFTLINT_CURRENT_FILENAME"]
|
||||||
|
|
||||||
// Non triggering tests
|
// Non triggering tests
|
||||||
|
@ -160,9 +152,7 @@ class FileHeaderRuleTests: XCTestCase {
|
||||||
XCTAssertEqual(try validate(fileName: "FileNameMatchingSimple.swift", using: configuration).count, 1)
|
XCTAssertEqual(try validate(fileName: "FileNameMatchingSimple.swift", using: configuration).count, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testFileHeaderWithRequiredPatternUsingFilenamePlaceholder() throws {
|
func testFileHeaderWithRequiredPatternUsingFilenamePlaceholder() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let configuration1 = ["required_pattern": "// SWIFTLINT_CURRENT_FILENAME\n.*\\d{4}"]
|
let configuration1 = ["required_pattern": "// SWIFTLINT_CURRENT_FILENAME\n.*\\d{4}"]
|
||||||
let configuration2 = ["required_pattern":
|
let configuration2 = ["required_pattern":
|
||||||
"// Copyright © \\d{4}\n// File: \"SWIFTLINT_CURRENT_FILENAME\""]
|
"// Copyright © \\d{4}\n// File: \"SWIFTLINT_CURRENT_FILENAME\""]
|
||||||
|
@ -177,9 +167,7 @@ class FileHeaderRuleTests: XCTestCase {
|
||||||
XCTAssertEqual(try validate(fileName: "FileNameMissing.swift", using: configuration1).count, 1)
|
XCTAssertEqual(try validate(fileName: "FileNameMissing.swift", using: configuration1).count, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testFileHeaderWithForbiddenPatternUsingFilenamePlaceholder() throws {
|
func testFileHeaderWithForbiddenPatternUsingFilenamePlaceholder() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let configuration1 = ["forbidden_pattern": "// SWIFTLINT_CURRENT_FILENAME\n.*\\d{4}"]
|
let configuration1 = ["forbidden_pattern": "// SWIFTLINT_CURRENT_FILENAME\n.*\\d{4}"]
|
||||||
let configuration2 = ["forbidden_pattern": "//.*(\\s|\")SWIFTLINT_CURRENT_FILENAME(\\s|\").*"]
|
let configuration2 = ["forbidden_pattern": "//.*(\\s|\")SWIFTLINT_CURRENT_FILENAME(\\s|\").*"]
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import SourceKittenFramework
|
|
||||||
@testable import SwiftLintFramework
|
@testable import SwiftLintFramework
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
private let fixturesDirectory = #file.bridge()
|
private let fixturesDirectory = "\(TestResources.path)/FileNameRuleFixtures"
|
||||||
.deletingLastPathComponent.bridge()
|
|
||||||
.appendingPathComponent("Resources/FileNameRuleFixtures")
|
|
||||||
|
|
||||||
class FileNameRuleTests: XCTestCase {
|
class FileNameRuleTests: XCTestCase {
|
||||||
private func validate(fileName: String, excludedOverride: [String]? = nil,
|
private func validate(fileName: String, excludedOverride: [String]? = nil,
|
||||||
|
@ -29,92 +26,64 @@ class FileNameRuleTests: XCTestCase {
|
||||||
return rule.validate(file: file)
|
return rule.validate(file: file)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMainDoesntTrigger() throws {
|
func testMainDoesntTrigger() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssert(try validate(fileName: "main.swift").isEmpty)
|
XCTAssert(try validate(fileName: "main.swift").isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testLinuxMainDoesntTrigger() throws {
|
func testLinuxMainDoesntTrigger() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssert(try validate(fileName: "LinuxMain.swift").isEmpty)
|
XCTAssert(try validate(fileName: "LinuxMain.swift").isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testClassNameDoesntTrigger() throws {
|
func testClassNameDoesntTrigger() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssert(try validate(fileName: "MyClass.swift").isEmpty)
|
XCTAssert(try validate(fileName: "MyClass.swift").isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testStructNameDoesntTrigger() throws {
|
func testStructNameDoesntTrigger() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssert(try validate(fileName: "MyStruct.swift").isEmpty)
|
XCTAssert(try validate(fileName: "MyStruct.swift").isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testExtensionNameDoesntTrigger() throws {
|
func testExtensionNameDoesntTrigger() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssert(try validate(fileName: "NSString+Extension.swift").isEmpty)
|
XCTAssert(try validate(fileName: "NSString+Extension.swift").isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNestedExtensionDoesntTrigger() throws {
|
func testNestedExtensionDoesntTrigger() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssert(try validate(fileName: "Notification.Name+Extension.swift").isEmpty)
|
XCTAssert(try validate(fileName: "Notification.Name+Extension.swift").isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNestedTypeSeparatorDoesntTrigger() throws {
|
func testNestedTypeSeparatorDoesntTrigger() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssert(try validate(fileName: "NotificationName+Extension.swift", nestedTypeSeparator: "").isEmpty)
|
XCTAssert(try validate(fileName: "NotificationName+Extension.swift", nestedTypeSeparator: "").isEmpty)
|
||||||
XCTAssert(try validate(fileName: "Notification__Name+Extension.swift", nestedTypeSeparator: "__").isEmpty)
|
XCTAssert(try validate(fileName: "Notification__Name+Extension.swift", nestedTypeSeparator: "__").isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testWrongNestedTypeSeparatorDoesTrigger() throws {
|
func testWrongNestedTypeSeparatorDoesTrigger() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssert(try !validate(fileName: "Notification__Name+Extension.swift", nestedTypeSeparator: ".").isEmpty)
|
XCTAssert(try !validate(fileName: "Notification__Name+Extension.swift", nestedTypeSeparator: ".").isEmpty)
|
||||||
XCTAssert(try !validate(fileName: "NotificationName+Extension.swift", nestedTypeSeparator: "__").isEmpty)
|
XCTAssert(try !validate(fileName: "NotificationName+Extension.swift", nestedTypeSeparator: "__").isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMisspelledNameDoesTrigger() throws {
|
func testMisspelledNameDoesTrigger() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssertEqual(try validate(fileName: "MyStructf.swift").count, 1)
|
XCTAssertEqual(try validate(fileName: "MyStructf.swift").count, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMisspelledNameDoesntTriggerWithOverride() throws {
|
func testMisspelledNameDoesntTriggerWithOverride() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssert(try validate(fileName: "MyStructf.swift", excludedOverride: ["MyStructf.swift"]).isEmpty)
|
XCTAssert(try validate(fileName: "MyStructf.swift", excludedOverride: ["MyStructf.swift"]).isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMainDoesTriggerWithoutOverride() throws {
|
func testMainDoesTriggerWithoutOverride() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssertEqual(try validate(fileName: "main.swift", excludedOverride: []).count, 1)
|
XCTAssertEqual(try validate(fileName: "main.swift", excludedOverride: []).count, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCustomSuffixPattern() throws {
|
func testCustomSuffixPattern() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssert(try validate(fileName: "BoolExtension.swift", suffixPattern: "Extensions?").isEmpty)
|
XCTAssert(try validate(fileName: "BoolExtension.swift", suffixPattern: "Extensions?").isEmpty)
|
||||||
XCTAssert(try validate(fileName: "BoolExtensions.swift", suffixPattern: "Extensions?").isEmpty)
|
XCTAssert(try validate(fileName: "BoolExtensions.swift", suffixPattern: "Extensions?").isEmpty)
|
||||||
XCTAssert(try validate(fileName: "BoolExtensionTests.swift", suffixPattern: "Extensions?|\\+.*").isEmpty)
|
XCTAssert(try validate(fileName: "BoolExtensionTests.swift", suffixPattern: "Extensions?|\\+.*").isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCustomPrefixPattern() throws {
|
func testCustomPrefixPattern() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssert(try validate(fileName: "ExtensionBool.swift", prefixPattern: "Extensions?").isEmpty)
|
XCTAssert(try validate(fileName: "ExtensionBool.swift", prefixPattern: "Extensions?").isEmpty)
|
||||||
XCTAssert(try validate(fileName: "ExtensionsBool.swift", prefixPattern: "Extensions?").isEmpty)
|
XCTAssert(try validate(fileName: "ExtensionsBool.swift", prefixPattern: "Extensions?").isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCustomPrefixAndSuffixPatterns() throws {
|
func testCustomPrefixAndSuffixPatterns() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
XCTAssert(
|
XCTAssert(
|
||||||
try validate(
|
try validate(
|
||||||
fileName: "SLBoolExtension.swift",
|
fileName: "SLBoolExtension.swift",
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
@testable import SwiftLintFramework
|
@testable import SwiftLintFramework
|
||||||
import SwiftLintTestHelpers
|
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
final class GlobTests: XCTestCase {
|
final class GlobTests: XCTestCase {
|
||||||
|
@ -7,65 +6,47 @@ final class GlobTests: XCTestCase {
|
||||||
return testResourcesPath.stringByAppendingPathComponent("ProjectMock")
|
return testResourcesPath.stringByAppendingPathComponent("ProjectMock")
|
||||||
}
|
}
|
||||||
|
|
||||||
func testOnlyGlobForWildcard() throws {
|
func testOnlyGlobForWildcard() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let files = Glob.resolveGlob("foo/bar.swift")
|
let files = Glob.resolveGlob("foo/bar.swift")
|
||||||
XCTAssertEqual(files, ["foo/bar.swift"])
|
XCTAssertEqual(files, ["foo/bar.swift"])
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNoMatchReturnsEmpty() throws {
|
func testNoMatchReturnsEmpty() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("NoFile*.swift"))
|
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("NoFile*.swift"))
|
||||||
XCTAssertTrue(files.isEmpty)
|
XCTAssertTrue(files.isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMatchesFiles() throws {
|
func testMatchesFiles() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("Level*.swift"))
|
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("Level*.swift"))
|
||||||
XCTAssertEqual(files, [mockPath.stringByAppendingPathComponent("Level0.swift")])
|
XCTAssertEqual(files, [mockPath.stringByAppendingPathComponent("Level0.swift")])
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMatchesSingleCharacter() throws {
|
func testMatchesSingleCharacter() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("Level?.swift"))
|
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("Level?.swift"))
|
||||||
XCTAssertEqual(files, [mockPath.stringByAppendingPathComponent("Level0.swift")])
|
XCTAssertEqual(files, [mockPath.stringByAppendingPathComponent("Level0.swift")])
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMatchesOneCharacterInBracket() throws {
|
func testMatchesOneCharacterInBracket() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("Level[01].swift"))
|
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("Level[01].swift"))
|
||||||
XCTAssertEqual(files, [mockPath.stringByAppendingPathComponent("Level0.swift")])
|
XCTAssertEqual(files, [mockPath.stringByAppendingPathComponent("Level0.swift")])
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNoMatchOneCharacterInBracket() throws {
|
func testNoMatchOneCharacterInBracket() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("Level[ab].swift"))
|
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("Level[ab].swift"))
|
||||||
XCTAssertTrue(files.isEmpty)
|
XCTAssertTrue(files.isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMatchesCharacterInRange() throws {
|
func testMatchesCharacterInRange() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("Level[0-9].swift"))
|
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("Level[0-9].swift"))
|
||||||
XCTAssertEqual(files, [mockPath.stringByAppendingPathComponent("Level0.swift")])
|
XCTAssertEqual(files, [mockPath.stringByAppendingPathComponent("Level0.swift")])
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNoMatchCharactersInRange() throws {
|
func testNoMatchCharactersInRange() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("Level[a-z].swift"))
|
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("Level[a-z].swift"))
|
||||||
XCTAssertTrue(files.isEmpty)
|
XCTAssertTrue(files.isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMatchesMultipleFiles() throws {
|
func testMatchesMultipleFiles() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedFiles: Set = [
|
let expectedFiles: Set = [
|
||||||
mockPath.stringByAppendingPathComponent("Level0.swift"),
|
mockPath.stringByAppendingPathComponent("Level0.swift"),
|
||||||
mockPath.stringByAppendingPathComponent("Directory.swift")
|
mockPath.stringByAppendingPathComponent("Directory.swift")
|
||||||
|
@ -75,16 +56,12 @@ final class GlobTests: XCTestCase {
|
||||||
XCTAssertEqual(files.sorted(), expectedFiles.sorted())
|
XCTAssertEqual(files.sorted(), expectedFiles.sorted())
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMatchesNestedDirectory() throws {
|
func testMatchesNestedDirectory() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("Level1/*.swift"))
|
let files = Glob.resolveGlob(mockPath.stringByAppendingPathComponent("Level1/*.swift"))
|
||||||
XCTAssertEqual(files, [mockPath.stringByAppendingPathComponent("Level1/Level1.swift")])
|
XCTAssertEqual(files, [mockPath.stringByAppendingPathComponent("Level1/Level1.swift")])
|
||||||
}
|
}
|
||||||
|
|
||||||
func testGlobstarSupport() throws {
|
func testGlobstarSupport() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedFiles = Set(
|
let expectedFiles = Set(
|
||||||
[
|
[
|
||||||
"Directory.swift",
|
"Directory.swift",
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
@testable import SwiftLintFramework
|
@testable import SwiftLintFramework
|
||||||
import SwiftLintTestHelpers
|
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
class ReporterTests: XCTestCase {
|
class ReporterTests: XCTestCase {
|
||||||
|
@ -51,33 +50,25 @@ class ReporterTests: XCTestCase {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
func testXcodeReporter() throws {
|
func testXcodeReporter() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedOutput = stringFromFile("CannedXcodeReporterOutput.txt")
|
let expectedOutput = stringFromFile("CannedXcodeReporterOutput.txt")
|
||||||
let result = XcodeReporter.generateReport(generateViolations())
|
let result = XcodeReporter.generateReport(generateViolations())
|
||||||
XCTAssertEqual(result, expectedOutput)
|
XCTAssertEqual(result, expectedOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testEmojiReporter() throws {
|
func testEmojiReporter() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedOutput = stringFromFile("CannedEmojiReporterOutput.txt")
|
let expectedOutput = stringFromFile("CannedEmojiReporterOutput.txt")
|
||||||
let result = EmojiReporter.generateReport(generateViolations())
|
let result = EmojiReporter.generateReport(generateViolations())
|
||||||
XCTAssertEqual(result, expectedOutput)
|
XCTAssertEqual(result, expectedOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testGitHubActionsLoggingReporter() throws {
|
func testGitHubActionsLoggingReporter() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedOutput = stringFromFile("CannedGitHubActionsLoggingReporterOutput.txt")
|
let expectedOutput = stringFromFile("CannedGitHubActionsLoggingReporterOutput.txt")
|
||||||
let result = GitHubActionsLoggingReporter.generateReport(generateViolations())
|
let result = GitHubActionsLoggingReporter.generateReport(generateViolations())
|
||||||
XCTAssertEqual(result, expectedOutput)
|
XCTAssertEqual(result, expectedOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testGitLabJUnitReporter() throws {
|
func testGitLabJUnitReporter() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedOutput = stringFromFile("CannedGitLabJUnitReporterOutput.xml")
|
let expectedOutput = stringFromFile("CannedGitLabJUnitReporterOutput.xml")
|
||||||
let result = GitLabJUnitReporter.generateReport(generateViolations())
|
let result = GitLabJUnitReporter.generateReport(generateViolations())
|
||||||
XCTAssertEqual(result, expectedOutput)
|
XCTAssertEqual(result, expectedOutput)
|
||||||
|
@ -95,48 +86,36 @@ class ReporterTests: XCTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testJSONReporter() throws {
|
func testJSONReporter() throws {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedOutput = stringFromFile("CannedJSONReporterOutput.json")
|
let expectedOutput = stringFromFile("CannedJSONReporterOutput.json")
|
||||||
let result = JSONReporter.generateReport(generateViolations())
|
let result = JSONReporter.generateReport(generateViolations())
|
||||||
XCTAssertEqual(try jsonValue(result), try jsonValue(expectedOutput))
|
XCTAssertEqual(try jsonValue(result), try jsonValue(expectedOutput))
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCSVReporter() throws {
|
func testCSVReporter() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedOutput = stringFromFile("CannedCSVReporterOutput.csv")
|
let expectedOutput = stringFromFile("CannedCSVReporterOutput.csv")
|
||||||
let result = CSVReporter.generateReport(generateViolations())
|
let result = CSVReporter.generateReport(generateViolations())
|
||||||
XCTAssertEqual(result, expectedOutput)
|
XCTAssertEqual(result, expectedOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCheckstyleReporter() throws {
|
func testCheckstyleReporter() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedOutput = stringFromFile("CannedCheckstyleReporterOutput.xml")
|
let expectedOutput = stringFromFile("CannedCheckstyleReporterOutput.xml")
|
||||||
let result = CheckstyleReporter.generateReport(generateViolations())
|
let result = CheckstyleReporter.generateReport(generateViolations())
|
||||||
XCTAssertEqual(result, expectedOutput)
|
XCTAssertEqual(result, expectedOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCodeClimateReporter() throws {
|
func testCodeClimateReporter() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedOutput = stringFromFile("CannedCodeClimateReporterOutput.json")
|
let expectedOutput = stringFromFile("CannedCodeClimateReporterOutput.json")
|
||||||
let result = CodeClimateReporter.generateReport(generateViolations())
|
let result = CodeClimateReporter.generateReport(generateViolations())
|
||||||
XCTAssertEqual(result, expectedOutput)
|
XCTAssertEqual(result, expectedOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testJunitReporter() throws {
|
func testJunitReporter() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedOutput = stringFromFile("CannedJunitReporterOutput.xml")
|
let expectedOutput = stringFromFile("CannedJunitReporterOutput.xml")
|
||||||
let result = JUnitReporter.generateReport(generateViolations())
|
let result = JUnitReporter.generateReport(generateViolations())
|
||||||
XCTAssertEqual(result, expectedOutput)
|
XCTAssertEqual(result, expectedOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testHTMLReporter() throws {
|
func testHTMLReporter() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedOutput = stringFromFile("CannedHTMLReporterOutput.html")
|
let expectedOutput = stringFromFile("CannedHTMLReporterOutput.html")
|
||||||
let result = HTMLReporter.generateReport(
|
let result = HTMLReporter.generateReport(
|
||||||
generateViolations(),
|
generateViolations(),
|
||||||
|
@ -146,17 +125,13 @@ class ReporterTests: XCTestCase {
|
||||||
XCTAssertEqual(result, expectedOutput)
|
XCTAssertEqual(result, expectedOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSonarQubeReporter() throws {
|
func testSonarQubeReporter() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedOutput = stringFromFile("CannedSonarQubeReporterOutput.json")
|
let expectedOutput = stringFromFile("CannedSonarQubeReporterOutput.json")
|
||||||
let result = SonarQubeReporter.generateReport(generateViolations())
|
let result = SonarQubeReporter.generateReport(generateViolations())
|
||||||
XCTAssertEqual(try jsonValue(result), try jsonValue(expectedOutput))
|
XCTAssertEqual(try jsonValue(result), try jsonValue(expectedOutput))
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMarkdownReporter() throws {
|
func testMarkdownReporter() {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
let expectedOutput = stringFromFile("CannedMarkdownReporterOutput.md")
|
let expectedOutput = stringFromFile("CannedMarkdownReporterOutput.md")
|
||||||
let result = MarkdownReporter.generateReport(generateViolations())
|
let result = MarkdownReporter.generateReport(generateViolations())
|
||||||
XCTAssertEqual(result, expectedOutput)
|
XCTAssertEqual(result, expectedOutput)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
@_spi(TestHelper)
|
@_spi(TestHelper)
|
||||||
@testable import SwiftLintFramework
|
@testable import SwiftLintFramework
|
||||||
import SwiftLintTestHelpers
|
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
class SourceKitCrashTests: XCTestCase {
|
class SourceKitCrashTests: XCTestCase {
|
||||||
|
@ -49,9 +48,7 @@ class SourceKitCrashTests: XCTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testRulesWithFileThatCrashedSourceKitService() throws {
|
func testRulesWithFileThatCrashedSourceKitService() throws {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
let file = try XCTUnwrap(SwiftLintFile(path: "\(TestResources.path)/ProjectMock/Level0.swift"))
|
||||||
|
|
||||||
let file = SwiftLintFile(path: #file)!
|
|
||||||
file.sourcekitdFailed = true
|
file.sourcekitdFailed = true
|
||||||
file.assertHandler = {
|
file.assertHandler = {
|
||||||
XCTFail("If this called, rule's SourceKitFreeRule is not properly configured")
|
XCTFail("If this called, rule's SourceKitFreeRule is not properly configured")
|
||||||
|
|
|
@ -3,7 +3,11 @@ import XCTest
|
||||||
|
|
||||||
enum TestResources {
|
enum TestResources {
|
||||||
static var path: String {
|
static var path: String {
|
||||||
URL(fileURLWithPath: #file, isDirectory: false)
|
if let rootProjectDirectory = ProcessInfo.processInfo.environment["BUILD_WORKSPACE_DIRECTORY"] {
|
||||||
|
return "\(rootProjectDirectory)/Tests/SwiftLintFrameworkTests/Resources"
|
||||||
|
}
|
||||||
|
|
||||||
|
return URL(fileURLWithPath: #file, isDirectory: false)
|
||||||
.deletingLastPathComponent()
|
.deletingLastPathComponent()
|
||||||
.appendingPathComponent("Resources")
|
.appendingPathComponent("Resources")
|
||||||
.path
|
.path
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import SwiftLintTestHelpers
|
|
||||||
import XCTest
|
import XCTest
|
||||||
import Yams
|
import Yams
|
||||||
|
|
||||||
class YamlSwiftLintTests: XCTestCase {
|
class YamlSwiftLintTests: XCTestCase {
|
||||||
func testFlattenYaml() throws {
|
func testFlattenYaml() throws {
|
||||||
try XCTSkipIf(shouldSkipRulesXcodeprojRunFiles)
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
guard let yamlDict = try Yams.load(yaml: try getTestYaml()) as? [String: Any] else {
|
guard let yamlDict = try Yams.load(yaml: try getTestYaml()) as? [String: Any] else {
|
||||||
XCTFail("Failed to load YAML from file")
|
XCTFail("Failed to load YAML from file")
|
||||||
|
|
|
@ -319,11 +319,6 @@ private func addShebang(_ example: Example) -> Example {
|
||||||
public extension XCTestCase {
|
public extension XCTestCase {
|
||||||
var isRunningWithBazel: Bool { FileManager.default.currentDirectoryPath.contains("bazel-out") }
|
var isRunningWithBazel: Bool { FileManager.default.currentDirectoryPath.contains("bazel-out") }
|
||||||
|
|
||||||
// Enable all tests when runfiles support is added - https://github.com/buildbuddy-io/rules_xcodeproj/issues/828
|
|
||||||
var shouldSkipRulesXcodeprojRunFiles: Bool {
|
|
||||||
ProcessInfo.processInfo.environment["RUNNING_RULES_XCODEPROJ_TESTS"] != nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func verifyRule(_ ruleDescription: RuleDescription,
|
func verifyRule(_ ruleDescription: RuleDescription,
|
||||||
ruleConfiguration: Any? = nil,
|
ruleConfiguration: Any? = nil,
|
||||||
commentDoesntViolate: Bool = true,
|
commentDoesntViolate: Bool = true,
|
||||||
|
|
Loading…
Reference in New Issue