uber / mockolo

Efficient Mock Generator for Swift
Apache License 2.0
805 stars 85 forks source link

Add async function support #166

Closed sidepelican closed 2 years ago

sidepelican commented 2 years ago

Add support for async function requirement. reasync keyword is considered in SwiftSyntax, but it is not implemented in swift5.5, so ignoring it.

Example:

protocol P {
    func f(arg: Int) async throws
}
private(set) var fCallCount = 0
var fHandler: ((Int) async throws -> ())?
func f(arg: Int) async throws  {
    fCallCount += 1
    if let fHandler = fHandler {
        try await fHandler(arg)
    }

} 

NOTE: such new swift5.5 feaatures are not in target of this PR

EspressoCup commented 2 years ago

Thanks for adding this support. Please address the test failures.

Copied: /Users/runner/work/mockolo/mockolo/Tests/TestFuncs/TestFuncAsync/FuncAsyncTests.swift:6:9: error: call can throw but is not marked with 'try' 98 super.setUpWithError() 99 ^~~~~~~~~~~~~~~~~~~~~~ 100 /Users/runner/work/mockolo/mockolo/Tests/TestFuncs/TestFuncAsync/FuncAsyncTests.swift:6:9: note: did you mean to use 'try'? 101 super.setUpWithError() 102 ^ 103 try 104 /Users/runner/work/mockolo/mockolo/Tests/TestFuncs/TestFuncAsync/FuncAsyncTests.swift:6:9: note: did you mean to handle error as optional value? 105 super.setUpWithError() 106 ^ 107 try? 108 /Users/runner/work/mockolo/mockolo/Tests/TestFuncs/TestFuncAsync/FuncAsyncTests.swift:6:9: note: did you mean to disable error propagation? 109 super.setUpWithError() 110 ^ 111 try! 112 error: fatalError

sidepelican commented 2 years ago

@EspressoCup Thanks for the review! I fixed the careless mistake.