@@ -281,85 +281,75 @@ final class ConfigurationTests: SwiftLintTestCase {
281281 XCTAssertEqual ( actualExcludedPath, desiredExcludedPath)
282282 }
283283
284- private class TestFileManager : LintableFileManager {
285- func filesToLint( inPath path: String , rootDirectory _: String ? = nil ) -> [ String ] {
286- var filesToLint : [ String ] = [ ]
287- switch path {
288- case " directory " : filesToLint = [
289- " directory/File1.swift " ,
290- " directory/File2.swift " ,
291- " directory/excluded/Excluded.swift " ,
292- " directory/ExcludedFile.swift " ,
293- ]
294- case " directory/excluded " : filesToLint = [ " directory/excluded/Excluded.swift " ]
295- case " directory/ExcludedFile.swift " : filesToLint = [ " directory/ExcludedFile.swift " ]
296- default : XCTFail ( " Should not be called with path \( path) " )
297- }
298- return filesToLint. absolutePathsStandardized ( )
299- }
300-
301- func modificationDate( forFileAtPath _: String ) -> Date ? {
302- nil
303- }
304-
305- func isFile( atPath path: String ) -> Bool {
306- path. hasSuffix ( " .swift " )
307- }
308- }
309-
310284 func testExcludedPaths( ) {
311- let fileManager = TestFileManager ( )
285+ XCTAssert ( FileManager . default . changeCurrentDirectoryPath ( Mock . Dir . exclusionTests ) )
312286 let configuration = Configuration (
313287 includedPaths: [ " directory " ] ,
314288 excludedPaths: [ " directory/excluded " , " directory/ExcludedFile.swift " ]
315289 )
316290
317- let paths = configuration. lintablePaths ( inPath: " " ,
318- forceExclude: false ,
319- excludeByPrefix: false ,
320- fileManager: fileManager)
321- XCTAssertEqual ( [ " directory/File1.swift " , " directory/File2.swift " ] . absolutePathsStandardized ( ) , paths)
291+ let paths = configuration. lintablePaths (
292+ inPath: " " ,
293+ forceExclude: false ,
294+ excludeByPrefix: false
295+ )
296+
297+ assertEqual ( [ " directory/File1.swift " , " directory/File2.swift " ] , paths)
322298 }
323299
324300 func testForceExcludesFile( ) {
325- let fileManager = TestFileManager ( )
301+ XCTAssert ( FileManager . default . changeCurrentDirectoryPath ( Mock . Dir . exclusionTests ) )
326302 let configuration = Configuration ( excludedPaths: [ " directory/ExcludedFile.swift " ] )
327- let paths = configuration. lintablePaths ( inPath: " directory/ExcludedFile.swift " ,
328- forceExclude: true ,
329- excludeByPrefix: false ,
330- fileManager: fileManager)
331- XCTAssertEqual ( [ ] , paths)
303+
304+ let paths = configuration. lintablePaths (
305+ inPath: " directory/ExcludedFile.swift " ,
306+ forceExclude: true ,
307+ excludeByPrefix: false
308+ )
309+
310+ XCTAssert ( paths. isEmpty)
332311 }
333312
334313 func testForceExcludesFileNotPresentInExcluded( ) {
335- let fileManager = TestFileManager ( )
336- let configuration = Configuration ( includedPaths: [ " directory " ] ,
337- excludedPaths: [ " directory/ExcludedFile.swift " , " directory/excluded " ] )
338- let paths = configuration. lintablePaths ( inPath: " " ,
339- forceExclude: true ,
340- excludeByPrefix: false ,
341- fileManager: fileManager)
342- XCTAssertEqual ( [ " directory/File1.swift " , " directory/File2.swift " ] . absolutePathsStandardized ( ) , paths)
314+ XCTAssert ( FileManager . default. changeCurrentDirectoryPath ( Mock . Dir. exclusionTests) )
315+ let configuration = Configuration (
316+ includedPaths: [ " directory " ] ,
317+ excludedPaths: [ " directory/ExcludedFile.swift " , " directory/excluded " ]
318+ )
319+
320+ let paths = configuration. lintablePaths (
321+ inPath: " " ,
322+ forceExclude: true ,
323+ excludeByPrefix: false
324+ )
325+
326+ assertEqual ( [ " directory/File1.swift " , " directory/File2.swift " ] , paths)
343327 }
344328
345329 func testForceExcludesDirectory( ) {
346- let fileManager = TestFileManager ( )
347- let configuration = Configuration ( excludedPaths: [ " directory/excluded " , " directory/ExcludedFile.swift " ] )
348- let paths = configuration. lintablePaths ( inPath: " directory " ,
349- forceExclude: true ,
350- excludeByPrefix: false ,
351- fileManager: fileManager)
352- XCTAssertEqual ( [ " directory/File1.swift " , " directory/File2.swift " ] . absolutePathsStandardized ( ) , paths)
330+ XCTAssert ( FileManager . default. changeCurrentDirectoryPath ( Mock . Dir. exclusionTests) )
331+ let configuration = Configuration ( excludedPaths: [ " directory/excluded " ] )
332+
333+ let paths = configuration. lintablePaths (
334+ inPath: " directory " ,
335+ forceExclude: true ,
336+ excludeByPrefix: false
337+ )
338+
339+ assertEqual ( [ " directory/File1.swift " , " directory/File2.swift " , " directory/ExcludedFile.swift " ] , paths)
353340 }
354341
355342 func testForceExcludesDirectoryThatIsNotInExcludedButHasChildrenThatAre( ) {
356- let fileManager = TestFileManager ( )
357- let configuration = Configuration ( excludedPaths: [ " directory/excluded " , " directory/ExcludedFile.swift " ] )
358- let paths = configuration. lintablePaths ( inPath: " directory " ,
359- forceExclude: true ,
360- excludeByPrefix: false ,
361- fileManager: fileManager)
362- XCTAssertEqual ( [ " directory/File1.swift " , " directory/File2.swift " ] . absolutePathsStandardized ( ) , paths)
343+ XCTAssert ( FileManager . default. changeCurrentDirectoryPath ( Mock . Dir. exclusionTests) )
344+ let configuration = Configuration ( excludedPaths: [ " directory/ExcludedFile.swift " ] )
345+
346+ let paths = configuration. lintablePaths (
347+ inPath: " directory " ,
348+ forceExclude: true ,
349+ excludeByPrefix: false
350+ )
351+
352+ assertEqual ( [ " directory/File1.swift " , " directory/File2.swift " , " directory/excluded/Excluded.swift " ] , paths)
363353 }
364354
365355 func testLintablePaths( ) {
@@ -621,6 +611,18 @@ extension ConfigurationTests {
621611 XCTAssertEqual ( configuration1. cachePath, " cache/path/1 " )
622612 XCTAssertEqual ( configuration2. cachePath, " cache/path/1 " )
623613 }
614+
615+ private func assertEqual( _ relativeExpectedPaths: [ String ] ,
616+ _ actualPaths: [ String ] ,
617+ file: StaticString = #filePath,
618+ line: UInt = #line) {
619+ XCTAssertEqual (
620+ relativeExpectedPaths. absolutePathsStandardized ( ) . sorted ( ) ,
621+ actualPaths. sorted ( ) ,
622+ file: file,
623+ line: line
624+ )
625+ }
624626}
625627
626628private extension Sequence where Element == String {
0 commit comments