Brightify / Cuckoo

Boilerplate-free mocking framework for Swift!
MIT License
1.67k stars 174 forks source link

Couldn't get Cuckoo 2.0.3 to work #495

Closed sskjames closed 5 months ago

sskjames commented 5 months ago

Had been using Cuckoo 1.x for many years now and I'm very thankful for this great library. However, I couldn't get Cuckoo 2.0.3 to work. Upgraded from 1.10.3 to 2.0.3 and used the new Run script which is defined above the Compile Source phase. Defined a minimal Cuckoofile like this:

output = "MyProjectTests/GeneratedMocks.swift"

[modules.MyProject]
sources = [
    "MyProject/*.swift",
]

However, when trying to build the test target, I get the following error:

/Users/james/MyProjectRoot/Pods/Cuckoo/run: line 89: version: No such file or directory
cuckoonator/SwiftSyntax+convenience.swift:32: Fatal error: Cuckoo error: Expected identifier. Please create an issue.
/Users/james/MyProjectRoot/Pods/Cuckoo/run: line 97:  3402 Trace/BPT trap: 5       "$GENERATOR_PATH" $@
Command PhaseScriptExecution failed with a nonzero exit code

Have I missed some configuration? Appreciate your help.

Zeydi commented 5 months ago

Hi. My configuration is like this and it works.

Cuckoo (2.0.3)

Cuckoofile.toml

[modules.iOSTemplate] <- Name of my project output = "iOSTemplateTests/GeneratedMocks.swift" <- Location of my file imports = [] testableImports = ["iOSTemplate"] <- Name of my project again sources = [ "iOSTemplate/Domain/UseCases/Quote/GetQuotesUseCase.swift", <- My file to mock ]

My script in tests target (Build phases):

if [ $ACTION == "indexbuild" ]; then exit 0 fi

if [ "${ENABLE_PREVIEWS}" = "YES" ]; then exit 0 fi

"${PODS_ROOT}/Cuckoo/run"

I hope this helps!

MatyasKriz commented 5 months ago

Thank you @Zeydi for sharing the working configuration.

@sskjames how are you integrating Cuckoo into your project? There may be a case I have missed because the errors printed are kinda weird.

The first one seems to be an undefined version in the run script while the second is a generator runtime error and the last one I don't even know.

Please try creating a sample project where this problem occurs and sharing it with me, I don't have access to internet for the moment but I'll take a look at it as soon as I can.

stzouvaras commented 5 months ago

Hello @MatyasKriz,

I'm getting the same error. I run the script from CLI. The last working version of cuckoonator is 2.0.2. Above 2.0.2 it doesn't work no matter what I've tried.

My error is: cuckoonator/SwiftSyntax+convenience.swift:44: Fatal error: Cuckoo error: Expected identifier. Please create an issue.

MatyasKriz commented 5 months ago

@stzouvaras thanks for the info, it must be an edge case that I'm missing.

I'll have to add the file path where this happens as well so we can track it down and fix it.

MatyasKriz commented 5 months ago

Please try again with version 2.0.6, the logging there should be better and allow us to find the issue.

stzouvaras commented 5 months ago

Hi @MatyasKriz,

error now is:

cuckoonator/SwiftSyntax+convenience.swift:49: Fatal error: Cuckoo error: Expected identifier. Please create an issue. SwiftSyntax+convenience.swift:49: Fatal error: Cuckoo error: Expected identifier. Please create an issue.

if it helps, with version 2.0.2, which is working, I get the following working messages:

Ignoring unsupported attribute 'propertyWrapper' Ignoring unsupported attribute 'propertyWrapper' Ignoring unsupported attribute 'propertyWrapper' Ignoring unsupported attribute 'propertyWrapper' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'MainActor' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'propertyWrapper' Ignoring unsupported attribute 'propertyWrapper' Ignoring unsupported attribute 'MainActor' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'propertyWrapper' Ignoring unsupported attribute 'MainActor' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'propertyWrapper' Ignoring unsupported attribute 'propertyWrapper' Ignoring unsupported attribute 'propertyWrapper' Ignoring unsupported attribute 'MainActor' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'MainActor' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'MainActor' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'MainActor' Ignoring unsupported attribute 'Published' Ignoring unsupported attribute 'propertyWrapper' Ignoring unsupported attribute 'MainActor' Ignoring unsupported attribute 'Published'

MatyasKriz commented 5 months ago

No, I was tired and forgot to replace the fatalError with throwing an error. 😭

Thanks for trying it out, version 2.0.7 will work as intended.

MatyasKriz commented 5 months ago

Sorry about this, could you please try one more time with 2.0.7? That one should actually print the identifier that's causing the trouble and file path where it occurs.

Also, the "ignoring unsupported attribute" spam has been moved to --verbose in case anyone wants to read it, but most people probably do not and in hindsight it should've been logged there from the start. 😄

stzouvaras commented 5 months ago

Hi @MatyasKriz

error: Can't parse method parameters '_ value: Any?, forKey: Prefs.Key'.

Prefs.Key is:

public struct Prefs {}

public extension Prefs { enum Key: String { case blabla } }

MatyasKriz commented 5 months ago

I see, it's the same thing I fixed for generics a while back. Thank you so much for the error, I'll make sure to add it to the tests in various places and more importantly fix it as soon as I can.

MatyasKriz commented 5 months ago

Found out that the problem is actually Any, it's a keyword, who knew.

I've revamped the identifier matching completely so it's less fragile, it's in release 2.0.8 if you wanna try it.

stzouvaras commented 5 months ago

Found out that the problem is actually Any, it's a keyword, who knew.

I've revamped the identifier matching completely so it's less fragile, it's in release 2.0.8 if you wanna try it.

Hi @MatyasKriz,

2.0.8 works as expected. Thank you for your effort and support.

MatyasKriz commented 5 months ago

Likewise thanks for testing it through this iterative process, @stzouvaras. 🙂