From 4a642a7e3bb5445f5a9e04d2a50caa593ccb7b13 Mon Sep 17 00:00:00 2001 From: Alexandr Zalutskiy Date: Mon, 20 Nov 2023 15:45:38 +0600 Subject: [PATCH] Point verify failure to 'verify' call fixes #57 --- Sources/SwiftMock/InOrder/InOrder.swift | 6 +-- .../SwiftMock/InOrder/InOrderContainer.swift | 8 +-- Sources/SwiftMock/SwiftMock.swift | 2 +- Sources/SwiftMock/Verify/Container.swift | 4 +- Sources/SwiftMock/Verify/MethodCall.swift | 14 ----- .../SwiftMock/Verify/VerifyContainer.swift | 6 ++- .../When/AsyncMethodInvocationContainer.swift | 2 +- ...yncRethrowsMethodInvocationContainer.swift | 2 +- ...AsyncThrowsMethodInvocationContainer.swift | 2 +- .../When/MethodInvocationContainer.swift | 2 +- .../RethrowsMethodInvocationContainer.swift | 2 +- .../ThrowsMethodInvocationContainer.swift | 2 +- .../Configuration.swift | 2 +- Sources/SwiftMockMacros/General.swift | 30 ----------- Sources/SwiftMockMacros/SwiftMockMacro.swift | 12 +++-- .../SwiftSyntaxExtensions/TypeSyntax.swift | 4 -- Sources/SwiftMockMacros/Verify.swift | 53 +++++++++++++++++-- .../Macro/MockMacroAttributeTests.swift | 20 +++---- .../Macro/MockMacroGenericMethodTests.swift | 16 +++--- .../Macro/MockMacroMethodAttributeTests.swift | 16 +++--- .../Macro/MockMacroMethodTests.swift | 24 ++++----- .../Macro/MockMacroSubscriptTests.swift | 28 +++++----- .../SwiftMockTests/Macro/MockMacroTests.swift | 52 +++++++++--------- 23 files changed, 159 insertions(+), 150 deletions(-) diff --git a/Sources/SwiftMock/InOrder/InOrder.swift b/Sources/SwiftMock/InOrder/InOrder.swift index e05ce93..3628d69 100644 --- a/Sources/SwiftMock/InOrder/InOrder.swift +++ b/Sources/SwiftMock/InOrder/InOrder.swift @@ -25,10 +25,10 @@ public struct InOrder { /// - Returns: `Verify` structure specific to the passed mock object. /// /// - Note: You don't have to verify all interactions one-by-one but only those that you are interested in testing in order. - public func verify(_ mock: Mock, times: @escaping TimesMatcher = times(1)) -> Mock.Verify { + public func verify(_ mock: Mock, times: @escaping TimesMatcher = times(1), file: StaticString = #filePath, line: UInt = #line) -> Mock.Verify { guard mocks.contains(where: { $0 === mock }) else { - testFailureReport("") - fatalError("") + testFailureReport("The 'InOrder' doesn't contains such a mock", file, line) + fatalError("The 'InOrder' doesn't contains such a mock", file: (file), line: line) } return Mock.Verify(mock: mock, container: container, times: times) diff --git a/Sources/SwiftMock/InOrder/InOrderContainer.swift b/Sources/SwiftMock/InOrder/InOrderContainer.swift index 4b3ac76..9b0320d 100644 --- a/Sources/SwiftMock/InOrder/InOrderContainer.swift +++ b/Sources/SwiftMock/InOrder/InOrderContainer.swift @@ -33,7 +33,9 @@ class InOrderContainer: CallContainer { matcher match: ArgumentMatcher, times: (Int) -> Bool, type: String, - function: String + function: String, + file: StaticString, + line: UInt ) { var callCount = 0 @@ -42,7 +44,7 @@ class InOrderContainer: CallContainer { let functions = InOrderContainer.functions guard startIndex < calls.count else { - testFailureReport("\(type).\(function): incorrect calls count: \(callCount)") + testFailureReport("\(type).\(function): incorrect calls count: \(callCount)", file, line) return } @@ -66,7 +68,7 @@ class InOrderContainer: CallContainer { lastCheckedIndex = index } guard times(callCount) else { - testFailureReport("\(type).\(function): incorrect calls count: \(callCount)") + testFailureReport("\(type).\(function): incorrect calls count: \(callCount)", file, line) return } diff --git a/Sources/SwiftMock/SwiftMock.swift b/Sources/SwiftMock/SwiftMock.swift index 2600eb9..944c5e9 100644 --- a/Sources/SwiftMock/SwiftMock.swift +++ b/Sources/SwiftMock/SwiftMock.swift @@ -1,7 +1,7 @@ @attached(peer, names: suffixed(Mock)) public macro Mock() = #externalMacro(module: "SwiftMockMacros", type: "MockMacro") -public var testFailureReport: (String) -> Void = { _ in +public var testFailureReport: (String, StaticString, UInt) -> Void = { _, _, _ in assertionFailure("Please import SwiftMockConfiguration module and call 'SwiftMockConfiguration.setUp()' in 'setUp()' method of your XCTestCase subclass.") } diff --git a/Sources/SwiftMock/Verify/Container.swift b/Sources/SwiftMock/Verify/Container.swift index c679731..13e8e16 100644 --- a/Sources/SwiftMock/Verify/Container.swift +++ b/Sources/SwiftMock/Verify/Container.swift @@ -11,6 +11,8 @@ public protocol CallContainer { matcher: ArgumentMatcher, times: TimesMatcher, type: String, - function: String + function: String, + file: StaticString, + line: UInt ) } diff --git a/Sources/SwiftMock/Verify/MethodCall.swift b/Sources/SwiftMock/Verify/MethodCall.swift index 02421bd..d41de68 100644 --- a/Sources/SwiftMock/Verify/MethodCall.swift +++ b/Sources/SwiftMock/Verify/MethodCall.swift @@ -4,18 +4,4 @@ public struct MethodCall { public init(arguments: Arguments) { self.arguments = arguments } - - public static func verify( - in container: [MethodCall], - matcher match: ArgumentMatcher, - times: TimesMatcher, - type: String, - function: String - ) { - let callCount = container.filter { match($0.arguments) }.count - guard times(callCount) else { - testFailureReport("\(type).\(function): incorrect calls count: \(callCount)") - return - } - } } diff --git a/Sources/SwiftMock/Verify/VerifyContainer.swift b/Sources/SwiftMock/Verify/VerifyContainer.swift index 8572c7e..07df6af 100644 --- a/Sources/SwiftMock/Verify/VerifyContainer.swift +++ b/Sources/SwiftMock/Verify/VerifyContainer.swift @@ -27,7 +27,9 @@ public class VerifyContainer: CallContainer { matcher match: ArgumentMatcher, times: (Int) -> Bool, type: String, - function: String + function: String, + file: StaticString, + line: UInt ) { var callCount = 0 var indexes: [Array.Index] = [] @@ -48,7 +50,7 @@ public class VerifyContainer: CallContainer { callCount += 1 } guard times(callCount) else { - testFailureReport("\(type).\(function): incorrect calls count: \(callCount)") + testFailureReport("\(type).\(function): incorrect calls count: \(callCount)", file, line) return } for index in indexes { diff --git a/Sources/SwiftMock/When/AsyncMethodInvocationContainer.swift b/Sources/SwiftMock/When/AsyncMethodInvocationContainer.swift index 55f66b5..4bfffd1 100644 --- a/Sources/SwiftMock/When/AsyncMethodInvocationContainer.swift +++ b/Sources/SwiftMock/When/AsyncMethodInvocationContainer.swift @@ -25,7 +25,7 @@ public final class AsyncMethodInvocationContainer { guard let invocation = invocations.last(where: { invocation in invocation.match(arguments) }) else { - testFailureReport("\(type).\(function): could not find invocation for arguments: \(arguments)") + testFailureReport("\(type).\(function): could not find invocation for arguments: \(arguments)", #file, #line) fatalError("\(type).\(function): could not find invocation for arguments: \(arguments)") } return await invocation.eval(arguments) diff --git a/Sources/SwiftMock/When/AsyncRethrowsMethodInvocationContainer.swift b/Sources/SwiftMock/When/AsyncRethrowsMethodInvocationContainer.swift index 80637cb..77d31e9 100644 --- a/Sources/SwiftMock/When/AsyncRethrowsMethodInvocationContainer.swift +++ b/Sources/SwiftMock/When/AsyncRethrowsMethodInvocationContainer.swift @@ -26,7 +26,7 @@ public final class AsyncRethrowsMethodInvocationContainer { guard let invocation = invocations.last(where: { invocation in invocation.match(arguments) }) else { - testFailureReport("\(type).\(function): could not find invocation for arguments: \(arguments)") + testFailureReport("\(type).\(function): could not find invocation for arguments: \(arguments)", #file, #line) fatalError("\(type).\(function): could not find invocation for arguments: \(arguments)") } return try await invocation.eval(arguments, f) diff --git a/Sources/SwiftMock/When/AsyncThrowsMethodInvocationContainer.swift b/Sources/SwiftMock/When/AsyncThrowsMethodInvocationContainer.swift index 08e8d5f..b2a7f7e 100644 --- a/Sources/SwiftMock/When/AsyncThrowsMethodInvocationContainer.swift +++ b/Sources/SwiftMock/When/AsyncThrowsMethodInvocationContainer.swift @@ -25,7 +25,7 @@ public final class AsyncThrowsMethodInvocationContainer { guard let invocation = invocations.last(where: { invocation in invocation.match(arguments) }) else { - testFailureReport("\(type).\(function): could not find invocation for arguments: \(arguments)") + testFailureReport("\(type).\(function): could not find invocation for arguments: \(arguments)", #file, #line) fatalError("\(type).\(function): could not find invocation for arguments: \(arguments)") } return try await invocation.eval(arguments) diff --git a/Sources/SwiftMock/When/MethodInvocationContainer.swift b/Sources/SwiftMock/When/MethodInvocationContainer.swift index c4d771d..90e519e 100644 --- a/Sources/SwiftMock/When/MethodInvocationContainer.swift +++ b/Sources/SwiftMock/When/MethodInvocationContainer.swift @@ -25,7 +25,7 @@ public final class MethodInvocationContainer { guard let invocation = invocations.last(where: { invocation in invocation.match(arguments) }) else { - testFailureReport("\(type).\(function): could not find invocation for arguments: \(arguments)") + testFailureReport("\(type).\(function): could not find invocation for arguments: \(arguments)", #file, #line) fatalError("\(type).\(function): could not find invocation for arguments: \(arguments)") } return invocation.eval(arguments) diff --git a/Sources/SwiftMock/When/RethrowsMethodInvocationContainer.swift b/Sources/SwiftMock/When/RethrowsMethodInvocationContainer.swift index 9c28da7..f5235b1 100644 --- a/Sources/SwiftMock/When/RethrowsMethodInvocationContainer.swift +++ b/Sources/SwiftMock/When/RethrowsMethodInvocationContainer.swift @@ -26,7 +26,7 @@ public final class RethrowsMethodInvocationContainer { guard let invocation = invocations.last(where: { invocation in invocation.match(arguments) }) else { - testFailureReport("\(type).\(function): could not find invocation for arguments: \(arguments)") + testFailureReport("\(type).\(function): could not find invocation for arguments: \(arguments)", #file, #line) fatalError("\(type).\(function): could not find invocation for arguments: \(arguments)") } return try invocation.eval(arguments, f) diff --git a/Sources/SwiftMock/When/ThrowsMethodInvocationContainer.swift b/Sources/SwiftMock/When/ThrowsMethodInvocationContainer.swift index 05dc7d6..58b2724 100644 --- a/Sources/SwiftMock/When/ThrowsMethodInvocationContainer.swift +++ b/Sources/SwiftMock/When/ThrowsMethodInvocationContainer.swift @@ -25,7 +25,7 @@ public final class ThrowsMethodInvocationContainer { guard let invocation = invocations.last(where: { invocation in invocation.match(arguments) }) else { - testFailureReport("\(type).\(function): could not find invocation for arguments: \(arguments)") + testFailureReport("\(type).\(function): could not find invocation for arguments: \(arguments)", #file, #line) fatalError("\(type).\(function): could not find invocation for arguments: \(arguments)") } return try invocation.eval(arguments) diff --git a/Sources/SwiftMockConfiguration/Configuration.swift b/Sources/SwiftMockConfiguration/Configuration.swift index 6d13f60..59bc012 100644 --- a/Sources/SwiftMockConfiguration/Configuration.swift +++ b/Sources/SwiftMockConfiguration/Configuration.swift @@ -11,7 +11,7 @@ import XCTest public enum SwiftMockConfiguration { public static func setUp() { testFailureReport = { - XCTFail($0) + XCTFail($0, file: $1, line: $2) } } diff --git a/Sources/SwiftMockMacros/General.swift b/Sources/SwiftMockMacros/General.swift index 4e74254..87ec46c 100644 --- a/Sources/SwiftMockMacros/General.swift +++ b/Sources/SwiftMockMacros/General.swift @@ -4,23 +4,6 @@ import SwiftSyntaxBuilder extension MockMacro { // MARK: - Making Method Wrapper Types - static func makeMethodInvocationType( - isAsync: Bool = false, - isThrows: Bool = false, - isRethrows: Bool = false, - arguments: [TypeSyntax] = [], - returnType: TypeSyntax? = nil - ) -> TypeSyntax { - makeMethodWrapperType( - baseName: .identifier("MethodInvocation"), - isAsync: isAsync, - isThrows: isThrows, - isRethrows: isRethrows, - arguments: arguments, - returnType: returnType - ) - } - static func makeMethodSignatureType( isAsync: Bool = false, isThrows: Bool = false, @@ -38,19 +21,6 @@ extension MockMacro { ) } - static func makeMethodCallType( - arguments: [TypeSyntax] - ) -> TypeSyntax { - TypeSyntax( - fromProtocol: IdentifierTypeSyntax( - name: .identifier("MethodCall"), - genericArgumentClause: GenericArgumentClauseSyntax { - GenericArgumentSyntax(argument: makeTupleType(from: arguments)) - } - ) - ) - } - private static func makeMethodWrapperType( baseName: TokenSyntax, isAsync: Bool, diff --git a/Sources/SwiftMockMacros/SwiftMockMacro.swift b/Sources/SwiftMockMacros/SwiftMockMacro.swift index 7af0f29..07948a9 100644 --- a/Sources/SwiftMockMacros/SwiftMockMacro.swift +++ b/Sources/SwiftMockMacros/SwiftMockMacro.swift @@ -246,12 +246,16 @@ public struct MockMacro: PeerMacro { ) } - static func wrapToArgumentMatcher(_ parameterClause: FunctionParameterClauseSyntax) -> FunctionParameterClauseSyntax { - parameterClause.with(\.parameters, FunctionParameterListSyntax { - for parameter in parameterClause.parameters { + static func wrapToArgumentMatcher(_ parameterListSyntax: FunctionParameterListSyntax) -> FunctionParameterListSyntax { + FunctionParameterListSyntax { + for parameter in parameterListSyntax { wrapToArgumentMatcher(parameter) } - }) + } + } + + static func wrapToArgumentMatcher(_ parameterClause: FunctionParameterClauseSyntax) -> FunctionParameterClauseSyntax { + parameterClause.with(\.parameters, wrapToArgumentMatcher(parameterClause.parameters)) } static func packParametersToTupleExpr( diff --git a/Sources/SwiftMockMacros/SwiftSyntaxExtensions/TypeSyntax.swift b/Sources/SwiftMockMacros/SwiftSyntaxExtensions/TypeSyntax.swift index 24b26c6..f6acd9a 100644 --- a/Sources/SwiftMockMacros/SwiftSyntaxExtensions/TypeSyntax.swift +++ b/Sources/SwiftMockMacros/SwiftSyntaxExtensions/TypeSyntax.swift @@ -62,8 +62,4 @@ extension TypeSyntax { } return self.name.trimmed.text == TokenSyntax.keyword(.escaping).text } - - var text: String { - String(trimmed.syntaxTextBytes.map { Unicode.Scalar($0) }.map { Character($0) }) - } } diff --git a/Sources/SwiftMockMacros/Verify.swift b/Sources/SwiftMockMacros/Verify.swift index 853065b..49edff4 100644 --- a/Sources/SwiftMockMacros/Verify.swift +++ b/Sources/SwiftMockMacros/Verify.swift @@ -95,7 +95,14 @@ extension MockMacro { if protocolDecl.isPublic { .public } }) .with(\.signature, FunctionSignatureSyntax( - parameterClause: wrapToArgumentMatcher(funcDecl.signature.parameterClause), + parameterClause: FunctionParameterClauseSyntax { + for parameter in wrapToArgumentMatcher(funcDecl.signature.parameterClause.parameters) { + parameter + } + for paramter in makeFileAndLineParameterClause() { + paramter + } + }, returnClause: ReturnClauseSyntax(type: IdentifierTypeSyntax(name: .identifier("Void"))) )) .with(\.body, makeVerifyBody( @@ -173,7 +180,11 @@ extension MockMacro { let functionParameterClause: FunctionParameterClauseSyntax switch accessorDecl.accessorSpecifier.trimmed.text { case TokenSyntax.keyword(.get).text: - functionParameterClause = FunctionParameterClauseSyntax { } + functionParameterClause = FunctionParameterClauseSyntax { + for property in makeFileAndLineParameterClause() { + property + } + } case TokenSyntax.keyword(.set).text: functionParameterClause = FunctionParameterClauseSyntax { FunctionParameterSyntax( @@ -183,6 +194,9 @@ extension MockMacro { type: wrapToArgumentMatcherType(type: propertyType) ) ) + for property in makeFileAndLineParameterClause() { + property + } } default: fatalError("Unexpected accessor for property. Supported accessors: \"get\" and \"set\"") @@ -262,13 +276,23 @@ extension MockMacro { let functionParameterClause: FunctionParameterClauseSyntax switch accessorDecl.accessorSpecifier.trimmed.text { case TokenSyntax.keyword(.get).text: - functionParameterClause = wrapToArgumentMatcher(subscriptDecl.parameterClause) + functionParameterClause = FunctionParameterClauseSyntax{ + for parameter in wrapToArgumentMatcher(subscriptDecl.parameterClause.parameters) { + parameter + } + for parameter in makeFileAndLineParameterClause() { + parameter + } + } case TokenSyntax.keyword(.set).text: functionParameterClause = FunctionParameterClauseSyntax { for parameter in wrapToArgumentMatcher(subscriptDecl.parameterClause).parameters { parameter } wrapToArgumentMatcher(FunctionParameterSyntax(firstName: "newValue", type: returnType)) + for parameter in makeFileAndLineParameterClause() { + parameter + } } default: let diagnostic = Diagnostic(node: accessorDecl, message: DiagnosticMessage.subscriptAccessorMustBeGetOrSet) @@ -328,10 +352,33 @@ extension MockMacro { label: "function", expression: funcSignatureExpr ) + LabeledExprSyntax( + label: "file", + expression: ExprSyntax(stringLiteral: "file") + ) + LabeledExprSyntax( + label: "line", + expression: ExprSyntax(stringLiteral: "line") + ) } } } + private static func makeFileAndLineParameterClause() -> FunctionParameterListSyntax { + FunctionParameterListSyntax { + FunctionParameterSyntax( + firstName: "file", + type: TypeSyntax(stringLiteral: "StaticString"), + defaultValue: InitializerClauseSyntax(value: ExprSyntax(stringLiteral: "#filePath")) + ) + FunctionParameterSyntax( + firstName: "line", + type: TypeSyntax(stringLiteral: "UInt"), + defaultValue: InitializerClauseSyntax(value: ExprSyntax(stringLiteral: "#line")) + ) + } + } + // MARK: - Integration to other files static func makeVerifyCallStorageProperty( diff --git a/Tests/SwiftMockTests/Macro/MockMacroAttributeTests.swift b/Tests/SwiftMockTests/Macro/MockMacroAttributeTests.swift index fd144a6..34b0e0c 100644 --- a/Tests/SwiftMockTests/Macro/MockMacroAttributeTests.swift +++ b/Tests/SwiftMockTests/Macro/MockMacroAttributeTests.swift @@ -115,9 +115,9 @@ final class MockMacroAttributeTests: XCTestCase { self.container = container self.times = times } - func dynamicallyCall(withArguments phoneNumber: @escaping ArgumentMatcher<[Int]> = any()) -> Void { + func dynamicallyCall(withArguments phoneNumber: @escaping ArgumentMatcher<[Int]> = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0 = phoneNumber - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TelephoneExchangeMock", function: "dynamicallyCall(withArguments:)") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TelephoneExchangeMock", function: "dynamicallyCall(withArguments:)", file: file, line: line) } } let container = VerifyContainer() @@ -170,9 +170,9 @@ final class MockMacroAttributeTests: XCTestCase { self.container = container self.times = times } - func subscriptGetter(dynamicMember member: @escaping ArgumentMatcher = any()) { + func subscriptGetter(dynamicMember member: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher0 = member - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "SomeProtocolMock", function: "subscript(dynamicMember member: String) -> Int { get }") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "SomeProtocolMock", function: "subscript(dynamicMember member: String) -> Int { get }", file: file, line: line) } } let container = VerifyContainer() @@ -227,9 +227,9 @@ final class MockMacroAttributeTests: XCTestCase { self.container = container self.times = times } - func testGetter() { + func testGetter(file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher0: ArgumentMatcher<()> = any() - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TelephoneExchangeMock", function: "test") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TelephoneExchangeMock", function: "test", file: file, line: line) } } let container = VerifyContainer() @@ -283,9 +283,9 @@ final class MockMacroAttributeTests: XCTestCase { self.container = container self.times = times } - func testGetter() { + func testGetter(file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher0: ArgumentMatcher<()> = any() - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TelephoneExchangeMock", function: "test") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TelephoneExchangeMock", function: "test", file: file, line: line) } } let container = VerifyContainer() @@ -339,9 +339,9 @@ final class MockMacroAttributeTests: XCTestCase { self.container = container self.times = times } - func testGetter() { + func testGetter(file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher0: ArgumentMatcher<()> = any() - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TelephoneExchangeMock", function: "test") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TelephoneExchangeMock", function: "test", file: file, line: line) } } let container = VerifyContainer() diff --git a/Tests/SwiftMockTests/Macro/MockMacroGenericMethodTests.swift b/Tests/SwiftMockTests/Macro/MockMacroGenericMethodTests.swift index 1330940..2ad2f5f 100644 --- a/Tests/SwiftMockTests/Macro/MockMacroGenericMethodTests.swift +++ b/Tests/SwiftMockTests/Macro/MockMacroGenericMethodTests.swift @@ -37,9 +37,9 @@ final class MockMacroGenericMethodTests: XCTestCase { self.times = times } public - func call(_ argument: @escaping ArgumentMatcher = any()) -> Void { + func call(_ argument: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0 = argument - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(_:)") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(_:)", file: file, line: line) } } public init() { @@ -94,9 +94,9 @@ final class MockMacroGenericMethodTests: XCTestCase { self.times = times } public - func call(_ argument: @escaping ArgumentMatcher = any()) -> Void { + func call(_ argument: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0 = argument - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(_:) -> T") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(_:) -> T", file: file, line: line) } } public init() { @@ -151,9 +151,9 @@ final class MockMacroGenericMethodTests: XCTestCase { self.times = times } public - func call(_ argument: @escaping ArgumentMatcher = any()) -> Void { + func call(_ argument: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0 = argument - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(_:) -> T") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(_:) -> T", file: file, line: line) } } public init() { @@ -208,9 +208,9 @@ final class MockMacroGenericMethodTests: XCTestCase { self.times = times } public - func call(_ argument: @escaping ArgumentMatcher = any()) -> Void { + func call(_ argument: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0 = argument - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(_:) async throws -> T") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(_:) async throws -> T", file: file, line: line) } } public init() { diff --git a/Tests/SwiftMockTests/Macro/MockMacroMethodAttributeTests.swift b/Tests/SwiftMockTests/Macro/MockMacroMethodAttributeTests.swift index 8fc5f2b..1ae2531 100644 --- a/Tests/SwiftMockTests/Macro/MockMacroMethodAttributeTests.swift +++ b/Tests/SwiftMockTests/Macro/MockMacroMethodAttributeTests.swift @@ -46,9 +46,9 @@ final class MockMacroMethodAttributeTests: XCTestCase { self.times = times } @available(iOS, introduced: 15.1) - func test() -> Void { + func test(file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0: ArgumentMatcher<()> = any() - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test()") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test()", file: file, line: line) } } let container = VerifyContainer() @@ -103,9 +103,9 @@ final class MockMacroMethodAttributeTests: XCTestCase { self.container = container self.times = times } - func test() -> Void { + func test(file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0: ArgumentMatcher<()> = any() - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test()") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test()", file: file, line: line) } } let container = VerifyContainer() @@ -159,9 +159,9 @@ final class MockMacroMethodAttributeTests: XCTestCase { self.container = container self.times = times } - func test() -> Void { + func test(file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0: ArgumentMatcher<()> = any() - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test()") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test()", file: file, line: line) } } let container = VerifyContainer() @@ -215,9 +215,9 @@ final class MockMacroMethodAttributeTests: XCTestCase { self.container = container self.times = times } - func test() -> Void { + func test(file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0: ArgumentMatcher<()> = any() - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test()") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test()", file: file, line: line) } } let container = VerifyContainer() diff --git a/Tests/SwiftMockTests/Macro/MockMacroMethodTests.swift b/Tests/SwiftMockTests/Macro/MockMacroMethodTests.swift index 73e3b73..f1efd6a 100644 --- a/Tests/SwiftMockTests/Macro/MockMacroMethodTests.swift +++ b/Tests/SwiftMockTests/Macro/MockMacroMethodTests.swift @@ -43,9 +43,9 @@ final class MockMacroMethodTests: XCTestCase { self.container = container self.times = times } - func test(_ f: @escaping ArgumentMatcher<(Int) -> Void> = any()) -> Void { + func test(_ f: @escaping ArgumentMatcher<(Int) -> Void> = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0 = f - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test(_:)") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test(_:)", file: file, line: line) } } let container = VerifyContainer() @@ -96,9 +96,9 @@ final class MockMacroMethodTests: XCTestCase { self.container = container self.times = times } - func test(_ f: @escaping ArgumentMatcher = any()) -> Void { + func test(_ f: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0 = f - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test(_:)") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test(_:)", file: file, line: line) } } let container = VerifyContainer() @@ -149,9 +149,9 @@ final class MockMacroMethodTests: XCTestCase { self.container = container self.times = times } - func test(_ f: @escaping ArgumentMatcher<(Int) throws -> Void> = any()) -> Void { + func test(_ f: @escaping ArgumentMatcher<(Int) throws -> Void> = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0 = f - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test(_:) rethrows") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test(_:) rethrows", file: file, line: line) } } let container = VerifyContainer() @@ -204,9 +204,9 @@ final class MockMacroMethodTests: XCTestCase { self.container = container self.times = times } - func test(_ f: @escaping ArgumentMatcher<(Int) throws -> Void> = any()) -> Void { + func test(_ f: @escaping ArgumentMatcher<(Int) throws -> Void> = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0 = f - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test(_:) async rethrows") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test(_:) async rethrows", file: file, line: line) } } let container = VerifyContainer() @@ -259,9 +259,9 @@ final class MockMacroMethodTests: XCTestCase { self.container = container self.times = times } - func test(_ f: @escaping ArgumentMatcher = any()) -> Void { + func test(_ f: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0 = f - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test(_:)") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test(_:)", file: file, line: line) } } let container = VerifyContainer() @@ -312,9 +312,9 @@ final class MockMacroMethodTests: XCTestCase { self.container = container self.times = times } - func test(_ f: @escaping ArgumentMatcher = any()) -> Void { + func test(_ f: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0 = f - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test(_:)") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "test(_:)", file: file, line: line) } } let container = VerifyContainer() diff --git a/Tests/SwiftMockTests/Macro/MockMacroSubscriptTests.swift b/Tests/SwiftMockTests/Macro/MockMacroSubscriptTests.swift index f24b51f..a7808fd 100644 --- a/Tests/SwiftMockTests/Macro/MockMacroSubscriptTests.swift +++ b/Tests/SwiftMockTests/Macro/MockMacroSubscriptTests.swift @@ -36,9 +36,9 @@ final class MockMacroSubscriptTests: XCTestCase { self.container = container self.times = times } - public func subscriptGetter(_ value: @escaping ArgumentMatcher = any()) { + public func subscriptGetter(_ value: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher0 = value - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "subscript(_ value: Int) -> Int { get }") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "subscript(_ value: Int) -> Int { get }", file: file, line: line) } } public init() { @@ -94,14 +94,14 @@ final class MockMacroSubscriptTests: XCTestCase { self.container = container self.times = times } - public func subscriptGetter(_ value: @escaping ArgumentMatcher = any()) { + public func subscriptGetter(_ value: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher0 = value - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "subscript(_ value: Int) -> Int { get set }") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "subscript(_ value: Int) -> Int { get set }", file: file, line: line) } - public func subscriptSetter(_ value: @escaping ArgumentMatcher = any(), newValue: @escaping ArgumentMatcher = any()) { + public func subscriptSetter(_ value: @escaping ArgumentMatcher = any(), newValue: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher1 = newValue let argumentMatcher0 = zip(value, argumentMatcher1) - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "subscript(_ value: Int) -> Int { get set }") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "subscript(_ value: Int) -> Int { get set }", file: file, line: line) } } public init() { @@ -170,14 +170,14 @@ final class MockMacroSubscriptTests: XCTestCase { self.container = container self.times = times } - public func subscriptGetter(_ value: @escaping ArgumentMatcher = any()) { + public func subscriptGetter(_ value: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher0 = value - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "subscript(_ value: T) -> T { get set }") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "subscript(_ value: T) -> T { get set }", file: file, line: line) } - public func subscriptSetter(_ value: @escaping ArgumentMatcher = any(), newValue: @escaping ArgumentMatcher = any()) { + public func subscriptSetter(_ value: @escaping ArgumentMatcher = any(), newValue: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher1 = newValue let argumentMatcher0 = zip(value, argumentMatcher1) - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "subscript(_ value: T) -> T { get set }") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "subscript(_ value: T) -> T { get set }", file: file, line: line) } } public init() { @@ -246,10 +246,10 @@ final class MockMacroSubscriptTests: XCTestCase { self.container = container self.times = times } - public func subscriptGetter(_ value0: @escaping ArgumentMatcher = any(), _ value1: @escaping ArgumentMatcher = any()) { + public func subscriptGetter(_ value0: @escaping ArgumentMatcher = any(), _ value1: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher1 = value1 let argumentMatcher0 = zip(value0, argumentMatcher1) - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "subscript(_ value0: Int, _ value1: Int) -> Int { get }") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "subscript(_ value0: Int, _ value1: Int) -> Int { get }", file: file, line: line) } } public init() { @@ -276,8 +276,8 @@ final class MockMacroSubscriptTests: XCTestCase { macros: testMacros, indentationWidth: .tab ) -#else + #else throw XCTSkip("macros are only supported when running tests for the host platform") -#endif + #endif } } diff --git a/Tests/SwiftMockTests/Macro/MockMacroTests.swift b/Tests/SwiftMockTests/Macro/MockMacroTests.swift index 448122f..fce70f1 100644 --- a/Tests/SwiftMockTests/Macro/MockMacroTests.swift +++ b/Tests/SwiftMockTests/Macro/MockMacroTests.swift @@ -105,9 +105,9 @@ final class MockMacroTests: XCTestCase { self.times = times } public - func call() -> Void { + func call(file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0: ArgumentMatcher<()> = any() - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call()") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call()", file: file, line: line) } } public init() { @@ -161,9 +161,9 @@ final class MockMacroTests: XCTestCase { self.container = container self.times = times } - public func propGetter() { + public func propGetter(file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher0: ArgumentMatcher<()> = any() - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "prop") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "prop", file: file, line: line) } } public init() { @@ -217,13 +217,13 @@ final class MockMacroTests: XCTestCase { self.container = container self.times = times } - public func propGetter() { + public func propGetter(file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher0: ArgumentMatcher<()> = any() - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "prop") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "prop", file: file, line: line) } - public func propSetter(_ value: @escaping ArgumentMatcher) { + public func propSetter(_ value: @escaping ArgumentMatcher, file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher0 = value - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "prop=") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "prop=", file: file, line: line) } } public init() { @@ -289,9 +289,9 @@ final class MockMacroTests: XCTestCase { self.container = container self.times = times } - public func propGetter() { + public func propGetter(file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher0: ArgumentMatcher<()> = any() - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "prop throws") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "prop throws", file: file, line: line) } } public init() { @@ -345,9 +345,9 @@ final class MockMacroTests: XCTestCase { self.container = container self.times = times } - public func propGetter() { + public func propGetter(file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher0: ArgumentMatcher<()> = any() - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "prop async") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "prop async", file: file, line: line) } } public init() { @@ -401,9 +401,9 @@ final class MockMacroTests: XCTestCase { self.container = container self.times = times } - public func propGetter() { + public func propGetter(file: StaticString = #filePath, line: UInt = #line) { let argumentMatcher0: ArgumentMatcher<()> = any() - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "prop async throws") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "prop async throws", file: file, line: line) } } public init() { @@ -458,9 +458,9 @@ final class MockMacroTests: XCTestCase { self.times = times } public - func call() -> Void { + func call(file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0: ArgumentMatcher<()> = any() - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call() -> Int") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call() -> Int", file: file, line: line) } } public init() { @@ -515,9 +515,9 @@ final class MockMacroTests: XCTestCase { self.times = times } public - func call(argument: @escaping ArgumentMatcher = any()) -> Void { + func call(argument: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher0 = argument - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(argument:)") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(argument:)", file: file, line: line) } } public init() { @@ -572,10 +572,10 @@ final class MockMacroTests: XCTestCase { self.times = times } public - func call(argument0: @escaping ArgumentMatcher = any(), argument1: @escaping ArgumentMatcher = any()) -> Void { + func call(argument0: @escaping ArgumentMatcher = any(), argument1: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher1 = argument1 let argumentMatcher0 = zip(argument0, argumentMatcher1) - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(argument0:argument1:)") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(argument0:argument1:)", file: file, line: line) } } public init() { @@ -631,10 +631,10 @@ final class MockMacroTests: XCTestCase { self.times = times } public - func call(argument0: @escaping ArgumentMatcher = any(), argument1: @escaping ArgumentMatcher = any()) -> Void { + func call(argument0: @escaping ArgumentMatcher = any(), argument1: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher1 = argument1 let argumentMatcher0 = zip(argument0, argumentMatcher1) - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(argument0:argument1:) throws -> Int") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(argument0:argument1:) throws -> Int", file: file, line: line) } } public init() { @@ -690,10 +690,10 @@ final class MockMacroTests: XCTestCase { self.times = times } public - func call(argument0: @escaping ArgumentMatcher = any(), argument1: @escaping ArgumentMatcher = any()) -> Void { + func call(argument0: @escaping ArgumentMatcher = any(), argument1: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher1 = argument1 let argumentMatcher0 = zip(argument0, argumentMatcher1) - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(argument0:argument1:) async -> Int") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(argument0:argument1:) async -> Int", file: file, line: line) } } public init() { @@ -749,10 +749,10 @@ final class MockMacroTests: XCTestCase { self.times = times } public - func call(argument0: @escaping ArgumentMatcher = any(), argument1: @escaping ArgumentMatcher = any()) -> Void { + func call(argument0: @escaping ArgumentMatcher = any(), argument1: @escaping ArgumentMatcher = any(), file: StaticString = #filePath, line: UInt = #line) -> Void { let argumentMatcher1 = argument1 let argumentMatcher0 = zip(argument0, argumentMatcher1) - container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(argument0:argument1:) async throws -> Int") + container.verify(mock: mock, matcher: argumentMatcher0, times: times, type: "TestMock", function: "call(argument0:argument1:) async throws -> Int", file: file, line: line) } } public init() {