From cd92705659ac360e6f9d725e9417f2eaf7709ac3 Mon Sep 17 00:00:00 2001 From: Timofey Solonin Date: Wed, 26 Dec 2018 01:48:17 +0300 Subject: [PATCH] #2441 - Add nested configurations tests for custom rules --- .../ConfigurationTests+Nested.swift | 28 +++++++++++++++++++ .../ConfigurationTests+ProjectMock.swift | 27 ++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/Tests/SwiftLintFrameworkTests/ConfigurationTests+Nested.swift b/Tests/SwiftLintFrameworkTests/ConfigurationTests+Nested.swift index 624c65fe453..8b0417a289e 100644 --- a/Tests/SwiftLintFrameworkTests/ConfigurationTests+Nested.swift +++ b/Tests/SwiftLintFrameworkTests/ConfigurationTests+Nested.swift @@ -85,4 +85,32 @@ extension ConfigurationTests { XCTAssertTrue(mergedConfiguration2.contains(rule: ForceCastRule.self)) XCTAssertTrue(mergedConfiguration2.contains(rule: ForceTryRule.self)) } + + func testNestedConfigurationsWithCustomRulesMerge() { + let mergedConfiguration = projectMockConfig0CustomRules.merge(with: projectMockConfig2CustomRules) + guard let mergedCustomRules = mergedConfiguration.rules.first(where: { $0 is CustomRules }) as? CustomRules + else { + return XCTFail("Custom rule are expected to be present") + } + XCTAssertTrue( + mergedCustomRules.configuration.customRuleConfigurations.contains(where: { $0.identifier == "no_abc" }) + ) + XCTAssertTrue( + mergedCustomRules.configuration.customRuleConfigurations.contains(where: { $0.identifier == "no_abcd" }) + ) + } + + func testNestedConfigurationAllowsDisablingParentsCustomRules() { + let mergedConfiguration = projectMockConfig0CustomRules.merge(with: projectMockConfig2CustomRulesDisabled) + guard let mergedCustomRules = mergedConfiguration.rules.first(where: { $0 is CustomRules }) as? CustomRules + else { + return XCTFail("Custom rule are expected to be present") + } + XCTAssertFalse( + mergedCustomRules.configuration.customRuleConfigurations.contains(where: { $0.identifier == "no_abc" }) + ) + XCTAssertTrue( + mergedCustomRules.configuration.customRuleConfigurations.contains(where: { $0.identifier == "no_abcd" }) + ) + } } diff --git a/Tests/SwiftLintFrameworkTests/ConfigurationTests+ProjectMock.swift b/Tests/SwiftLintFrameworkTests/ConfigurationTests+ProjectMock.swift index 37a2262131b..33d87a7f2e3 100644 --- a/Tests/SwiftLintFrameworkTests/ConfigurationTests+ProjectMock.swift +++ b/Tests/SwiftLintFrameworkTests/ConfigurationTests+ProjectMock.swift @@ -26,10 +26,22 @@ extension ConfigurationTests { return projectMockPathLevel0.stringByAppendingPathComponent("custom.yml") } + var projectMockYAML0CustomRules: String { + return projectMockPathLevel0.stringByAppendingPathComponent("custom_rules.yml") + } + var projectMockYAML2: String { return projectMockPathLevel2.stringByAppendingPathComponent(Configuration.fileName) } + var projectMockYAML2CustomRules: String { + return projectMockPathLevel2.stringByAppendingPathComponent("custom_rules.yml") + } + + var projectMockYAML2CustomRulesDisabled: String { + return projectMockPathLevel2.stringByAppendingPathComponent("custom_rules_disabled.yml") + } + var projectMockSwift0: String { return projectMockPathLevel0.stringByAppendingPathComponent("Level0.swift") } @@ -56,10 +68,25 @@ extension ConfigurationTests { optional: false, quiet: true) } + var projectMockConfig0CustomRules: Configuration { + return Configuration(path: projectMockYAML0CustomRules, rootPath: projectMockPathLevel0, + optional: false, quiet: true) + } + var projectMockConfig2: Configuration { return Configuration(path: projectMockYAML2, optional: false, quiet: true) } + var projectMockConfig2CustomRules: Configuration { + return Configuration(path: projectMockYAML2CustomRules, rootPath: projectMockPathLevel0, + optional: false, quiet: true) + } + + var projectMockConfig2CustomRulesDisabled: Configuration { + return Configuration(path: projectMockYAML2CustomRulesDisabled, rootPath: projectMockPathLevel0, + optional: false, quiet: true) + } + var projectMockConfig3: Configuration { return Configuration(path: Configuration.fileName, rootPath: projectMockPathLevel3, optional: false, quiet: true)