Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator fails to create mock for the simplest PAT #317

Open
2 tasks done
mecoFarid opened this issue Dec 13, 2022 · 0 comments
Open
2 tasks done

Generator fails to create mock for the simplest PAT #317

mecoFarid opened this issue Dec 13, 2022 · 0 comments
Labels
generator bug Causes malformed generated code

Comments

@mecoFarid
Copy link

Overview

Mockingbird site advertises the library as if it supports the Protocols with generic type here https://mockingbirdswift.com/feature-comparison but in reality, it fails for simplest generic protocol.

Example

protocol Mapper{
    associatedtype I
    associatedtype O
    
    func map(i: I) -> O
}

Generated code

private let mkbGenericStaticMockContext = Mockingbird.GenericStaticMockContext()

// MARK: - Mocked Mapper
public final class MapperMock<I, O>: Mappa.Mapper, Mockingbird.Mock {
  typealias MockingbirdSupertype = Mappa.Mapper
  public static var mockingbirdContext: Mockingbird.Context { return mkbGenericStaticMockContext.resolve(["MapperMock<I, O>", Swift.ObjectIdentifier(I.self).debugDescription, Swift.ObjectIdentifier(O.self).debugDescription]) }
  public let mockingbirdContext = Mockingbird.Context(["generator_version": "0.20.0", "module_name": "Mappa"])

  fileprivate init(sourceLocation: Mockingbird.SourceLocation) {
    self.mockingbirdContext.sourceLocation = sourceLocation
    MapperMock.mockingbirdContext.sourceLocation = sourceLocation
  }

  // MARK: Mocked `map`(`i`: I)
  public func `map`(`i`: I) -> O {
    return self.mockingbirdContext.mocking.didInvoke(Mockingbird.SwiftInvocation(selectorName: "`map`(`i`: I) -> O", selectorType: Mockingbird.SelectorType.method, arguments: [Mockingbird.ArgumentMatcher(`i`)], returnType: Swift.ObjectIdentifier((O).self))) {
      self.mockingbirdContext.recordInvocation($0)
      let mkbImpl = self.mockingbirdContext.stubbing.implementation(for: $0)
      if let mkbImpl = mkbImpl as? (I) -> O { return mkbImpl(`i`) }
      if let mkbImpl = mkbImpl as? () -> O { return mkbImpl() }
      for mkbTargetBox in self.mockingbirdContext.proxy.targets(for: $0) {
        switch mkbTargetBox.target {
        case .super:
          break
        case .object:
          break
        }
      }
      if let mkbValue = self.mockingbirdContext.stubbing.defaultValueProvider.value.provideValue(for: (O).self) { return mkbValue }
      self.mockingbirdContext.stubbing.failTest(for: $0, at: self.mockingbirdContext.sourceLocation)
    }
  }

  public func `map`(`i`: @autoclosure () -> I) -> Mockingbird.Mockable<Mockingbird.FunctionDeclaration, (I) -> O, O> {
    return Mockingbird.Mockable<Mockingbird.FunctionDeclaration, (I) -> O, O>(context: self.mockingbirdContext, invocation: Mockingbird.SwiftInvocation(selectorName: "`map`(`i`: I) -> O", selectorType: Mockingbird.SelectorType.method, arguments: [Mockingbird.resolve(`i`)], returnType: Swift.ObjectIdentifier((O).self)))
  }
}

public enum Mapper<I, O> {
}
/// Returns a concrete mock of `Mapper`.
public func mock<I, O>(_ type: Mapper<I, O>.Type, file: StaticString = #file, line: UInt = #line) -> MapperMock<I, O> {
  return MapperMock<I, O>(sourceLocation: Mockingbird.SourceLocation(file, line))
}

Error

Type 'MapperMock<I, O>' does not conform to protocol 'Mapper'

Environment

  • Mockingbird version: 0.20.0
  • Xcode and Swift version: 14.0.1 and 5.7
  • Package manager: CocoaPods
  • Unit testing framework: XCTest
@mecoFarid mecoFarid added the generator bug Causes malformed generated code label Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator bug Causes malformed generated code
Projects
None yet
Development

No branches or pull requests

1 participant