@@ -54,7 +54,7 @@ class MockoloTestCase: XCTestCase {
5454 }
5555 }
5656
57- func verify( srcContent: String , mockContent: String ? = nil , dstContent: String , header: String = " " , declType: FindTargetDeclType = . protocolType, useTemplateFunc: Bool = false , useMockObservable : Bool = false , testableImports: [ String ] = [ ] , allowSetCallCount: Bool = false , mockFinal: Bool = false , enableFuncArgsHistory: Bool = false , dstFilePath: String ? = nil , concurrencyLimit: Int ? = 1 , disableCombineDefaultValues: Bool = false ) {
57+ func verify( srcContent: String , mockContent: String ? = nil , dstContent: String , header: String = " " , declType: FindTargetDeclType = . protocolType, useTemplateFunc: Bool = false , testableImports: [ String ] = [ ] , allowSetCallCount: Bool = false , mockFinal: Bool = false , enableFuncArgsHistory: Bool = false , dstFilePath: String ? = nil , concurrencyLimit: Int ? = 1 , disableCombineDefaultValues: Bool = false , file : StaticString = #filePath , line : UInt = #line ) {
5858 let dstFilePath = dstFilePath ?? defaultDstFilePath
5959 var mockList : [ String ] ?
6060 if let mock = mockContent {
@@ -63,10 +63,10 @@ class MockoloTestCase: XCTestCase {
6363 }
6464 mockList? . append ( mock)
6565 }
66- try ? verify ( srcContents: [ srcContent] , mockContents: mockList, dstContent: dstContent, header: header, declType: declType, useTemplateFunc: useTemplateFunc, useMockObservable : useMockObservable , testableImports: testableImports, allowSetCallCount: allowSetCallCount, mockFinal: mockFinal, enableFuncArgsHistory: enableFuncArgsHistory, dstFilePath: dstFilePath, concurrencyLimit: concurrencyLimit, disableCombineDefaultValues: disableCombineDefaultValues)
66+ try ? verify ( srcContents: [ srcContent] , mockContents: mockList, dstContent: dstContent, header: header, declType: declType, useTemplateFunc: useTemplateFunc, testableImports: testableImports, allowSetCallCount: allowSetCallCount, mockFinal: mockFinal, enableFuncArgsHistory: enableFuncArgsHistory, dstFilePath: dstFilePath, concurrencyLimit: concurrencyLimit, disableCombineDefaultValues: disableCombineDefaultValues, file : file , line : line )
6767 }
6868
69- func verifyThrows( srcContent: String , mockContent: String ? = nil , dstContent: String , header: String = " " , declType: FindTargetDeclType = . protocolType, useTemplateFunc: Bool = false , useMockObservable : Bool = false , testableImports: [ String ] = [ ] , allowSetCallCount: Bool = false , mockFinal: Bool = false , enableFuncArgsHistory: Bool = false , dstFilePath: String ? = nil , concurrencyLimit: Int ? = 1 , disableCombineDefaultValues: Bool = false , errorHandler: ( Error ) -> Void = { _ in } ) {
69+ func verifyThrows( srcContent: String , mockContent: String ? = nil , dstContent: String , header: String = " " , declType: FindTargetDeclType = . protocolType, useTemplateFunc: Bool = false , testableImports: [ String ] = [ ] , allowSetCallCount: Bool = false , mockFinal: Bool = false , enableFuncArgsHistory: Bool = false , dstFilePath: String ? = nil , concurrencyLimit: Int ? = 1 , disableCombineDefaultValues: Bool = false , errorHandler: ( Error ) -> Void = { _ in } , file : StaticString = #filePath , line : UInt = #line ) {
7070 let dstFilePath = dstFilePath ?? defaultDstFilePath
7171 var mockList : [ String ] ?
7272 if let mock = mockContent {
@@ -76,13 +76,13 @@ class MockoloTestCase: XCTestCase {
7676 mockList? . append ( mock)
7777 }
7878 XCTAssertThrowsError (
79- try verify ( srcContents: [ srcContent] , mockContents: mockList, dstContent: dstContent, header: header, declType: declType, useTemplateFunc: useTemplateFunc, useMockObservable : useMockObservable , testableImports: testableImports, allowSetCallCount: allowSetCallCount, mockFinal: mockFinal, enableFuncArgsHistory: enableFuncArgsHistory, dstFilePath: dstFilePath, concurrencyLimit: concurrencyLimit, disableCombineDefaultValues: disableCombineDefaultValues) ,
79+ try verify ( srcContents: [ srcContent] , mockContents: mockList, dstContent: dstContent, header: header, declType: declType, useTemplateFunc: useTemplateFunc, testableImports: testableImports, allowSetCallCount: allowSetCallCount, mockFinal: mockFinal, enableFuncArgsHistory: enableFuncArgsHistory, dstFilePath: dstFilePath, concurrencyLimit: concurrencyLimit, disableCombineDefaultValues: disableCombineDefaultValues, file : file , line : line ) ,
8080 " No error was thrown " ,
8181 errorHandler
8282 )
8383 }
8484
85- func verify( srcContents: [ String ] , mockContents: [ String ] ? , dstContent: String , header: String , declType: FindTargetDeclType , useTemplateFunc: Bool , useMockObservable : Bool , testableImports: [ String ] = [ ] , allowSetCallCount: Bool , mockFinal: Bool , enableFuncArgsHistory: Bool , dstFilePath: String , concurrencyLimit: Int ? , disableCombineDefaultValues: Bool ) throws {
85+ func verify( srcContents: [ String ] , mockContents: [ String ] ? , dstContent: String , header: String , declType: FindTargetDeclType , useTemplateFunc: Bool , testableImports: [ String ] = [ ] , allowSetCallCount: Bool , mockFinal: Bool , enableFuncArgsHistory: Bool , dstFilePath: String , concurrencyLimit: Int ? , disableCombineDefaultValues: Bool , file : StaticString = #filePath , line : UInt = #line ) throws {
8686 var index = 0
8787 srcFilePathsCount = srcContents. count
8888 mockFilePathsCount = mockContents? . count ?? 0
@@ -91,7 +91,7 @@ class MockoloTestCase: XCTestCase {
9191 if index < srcContents. count {
9292 let srcCreated = FileManager . default. createFile ( atPath: srcFilePaths [ index] , contents: src. data ( using: . utf8) , attributes: nil )
9393 index += 1
94- XCTAssert ( srcCreated)
94+ XCTAssert ( srcCreated, file : file , line : line )
9595 }
9696 }
9797
@@ -108,7 +108,7 @@ class MockoloTestCase: XCTestCase {
108108 \( macroEnd)
109109 """
110110 let mockCreated = FileManager . default. createFile ( atPath: mockFilePaths [ index] , contents: formattedMockContent. data ( using: . utf8) , attributes: nil )
111- XCTAssert ( mockCreated)
111+ XCTAssert ( mockCreated, file : file , line : line )
112112 }
113113 }
114114
@@ -134,11 +134,47 @@ class MockoloTestCase: XCTestCase {
134134 concurrencyLimit: concurrencyLimit)
135135 let output = ( try ? String ( contentsOf: URL ( fileURLWithPath: self . defaultDstFilePath) , encoding: . utf8) ) ?? " "
136136 let outputContents = output. components ( separatedBy: . newlines) . filter { !$0. isEmpty && !$0. allSatisfy ( \. isWhitespace) }
137- let fixtureContents = dstContent. components ( separatedBy: . newlines) . filter { !$0. isEmpty && !$0. allSatisfy ( \. isWhitespace) }
137+ let fixtureContents = """
138+ \( headerStr)
139+ \( macroStart)
140+ \( dstContent)
141+ \( macroEnd)
142+ """ . components ( separatedBy: . newlines) . filter { !$0. isEmpty && !$0. allSatisfy ( \. isWhitespace) }
138143 if fixtureContents. isEmpty {
139- throw XCTSkip ( " empty fixture " )
144+ throw XCTSkip ( " empty fixture " , file: file, line: line)
145+ }
146+
147+ let diff = lightDiff ( old: outputContents, new: fixtureContents)
148+ if !diff. isEmpty {
149+ print ( " output: \n \( output) " )
150+ XCTFail ( " diff: \n " + " \( diff. joined ( separator: " \n " ) ) " , file: file, line: line)
151+ }
152+ }
153+ }
154+
155+ func lightDiff( old: [ String ] , new: [ String ] ) -> [ String ] {
156+ return new. difference ( from: old)
157+ . sorted { l, r in
158+ return l. offset < r. offset
159+ }
160+ . map { change in
161+ switch change {
162+ case . remove( _, let element, _) :
163+ return " - \( element) "
164+ case . insert( _, let element, _) :
165+ return " + \( element) "
166+ }
167+ }
168+ }
169+
170+ extension CollectionDifference . Change {
171+ var offset : Int {
172+ switch self {
173+ case . insert( let offset, _, _) :
174+ return offset
175+ case . remove( let offset, _, _) :
176+ return offset
140177 }
141- XCTAssert ( outputContents. contains ( subArray: fixtureContents) , " output: \n " + output)
142178 }
143179}
144180
0 commit comments