Skip to content

Commit

Permalink
Add (currently failing) test for #3485
Browse files Browse the repository at this point in the history
  • Loading branch information
fredpi authored and jpsim committed Feb 23, 2021
1 parent 8f216b8 commit c4200f4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Tests/SwiftLintFrameworkTests/ConfigurationTests+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal extension ConfigurationTests {
// MARK: YAML File Paths
enum Yml {
static var _0: String { Dir.level0.stringByAppendingPathComponent(Configuration.defaultFileName) }
static var _0CustomPath: String { Dir.level0.stringByAppendingPathComponent("custom.yml") }
static var _0Custom: String { Dir.level0.stringByAppendingPathComponent("custom.yml") }
static var _0CustomRules: String { Dir.level0.stringByAppendingPathComponent("custom_rules.yml") }
static var _2: String { Dir.level2.stringByAppendingPathComponent(Configuration.defaultFileName) }
static var _2CustomRules: String { Dir.level2.stringByAppendingPathComponent("custom_rules.yml") }
Expand All @@ -59,7 +59,7 @@ internal extension ConfigurationTests {
// MARK: Configurations
enum Config {
static var _0: Configuration { Configuration(configurationFiles: []) }
static var _0CustomPath: Configuration { Configuration(configurationFiles: [Yml._0CustomPath]) }
static var _0Custom: Configuration { Configuration(configurationFiles: [Yml._0Custom]) }
static var _0CustomRules: Configuration { Configuration(configurationFiles: [Yml._0CustomRules]) }
static var _2: Configuration { Configuration(configurationFiles: [Yml._2]) }
static var _2CustomRules: Configuration { Configuration(configurationFiles: [Yml._2CustomRules]) }
Expand Down
20 changes: 18 additions & 2 deletions Tests/SwiftLintFrameworkTests/ConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import XCTest

private let optInRules = primaryRuleList.list.filter({ $0.1.init() is OptInRule }).map({ $0.0 })

// swiftlint:disable file_length type_body_length

class ConfigurationTests: XCTestCase {
// MARK: Setup & Teardown
private var previousWorkingDir: String!
Expand Down Expand Up @@ -168,6 +170,20 @@ class ConfigurationTests: XCTestCase {
)
}

func testIncludedPathRelatedToConfigurationFileLocation() {
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level1)

// The included path "File.swift" should be put relative to the configuration file
// (~> Resources/ProjectMock/File.swift) and not relative to the path where
// SwiftLint is run from (~> Resources/ProjectMock/Level1/File.swift)
let configuration = Configuration(configurationFiles: ["../custom_included.yml"])
let actualIncludedPath = configuration.includedPaths.first!.bridge()
.absolutePathRepresentation(rootDirectory: configuration.rootDirectory)
let desiredIncludedPath = "File.swift".absolutePathRepresentation(rootDirectory: Mock.Dir.level0)

XCTAssertEqual(actualIncludedPath, desiredIncludedPath)
}

private class TestFileManager: LintableFileManager {
func filesToLint(inPath path: String, rootDirectory: String? = nil) -> [String] {
switch path {
Expand Down Expand Up @@ -259,7 +275,7 @@ class ConfigurationTests: XCTestCase {
func testCustomConfiguration() {
let file = SwiftLintFile(path: Mock.Swift._0)!
XCTAssertNotEqual(Mock.Config._0.configuration(for: file),
Mock.Config._0CustomPath.configuration(for: file))
Mock.Config._0Custom.configuration(for: file))
}

func testConfigurationWithSwiftFileAsRoot() {
Expand All @@ -270,7 +286,7 @@ class ConfigurationTests: XCTestCase {
}

func testConfigurationWithSwiftFileAsRootAndCustomConfiguration() {
let configuration = Configuration(configurationFiles: [Mock.Yml._0CustomPath])
let configuration = Mock.Config._0Custom

let file = SwiftLintFile(path: Mock.Swift._0)!
XCTAssertEqual(configuration.configuration(for: file), configuration)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
included:
- "File.swift"

0 comments on commit c4200f4

Please sign in to comment.