Skip to content

Commit

Permalink
realm#2441 - Add nested configurations tests for custom rules
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulowork committed Dec 26, 2018
1 parent 98c787d commit cd92705
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Tests/SwiftLintFrameworkTests/ConfigurationTests+Nested.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
)
}
}
27 changes: 27 additions & 0 deletions Tests/SwiftLintFrameworkTests/ConfigurationTests+ProjectMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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)
Expand Down

0 comments on commit cd92705

Please sign in to comment.