Brightify / Cuckoo

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

Migrate to v2 with SPM package.swift #508

Open soucolline opened 1 month ago

soucolline commented 1 month ago

Hello,

I'm trying to migrate to v2 using SPM with a package.swift file. I'm updating the dependency to 2.0.9 .package(url: "https://github.com/Brightify/Cuckoo.git", exact: "2.0.9"), But then I don't have access to the CuckooPluginSingleFile mentioned in the doc. Is it only in the case where you install it from Xcode ?

Even if I try to launch my tests i'm getting this warning about the file being stalled from my DerivedData, so I supposed it's existing even though i'm not importing it in the Run Build Tools Plug-ins phase Screenshot 2024-08-02 at 11 38 36 AM

Am I missing something there or the install from a Package.swift is not supported ?

Thanks

soucolline commented 1 month ago

After some investigations I managed to run the CockkoPluginSingleFile by adding

plugins: [
    .plugin(name: "CuckooPluginSingleFile", package: "Cuckoo")
]

to my package definition but now i'm getting the same errors as mentioned in this issue

MatyasKriz commented 1 month ago

Hey, @soucolline, that message is not an error per se, it's only a disclaimer when multiple outputs are defined in Cuckoofile, but I agree that it should be fixed and hidden when the Swift build tool plugin forces the derived data mock output.

However, it shouldn't cause any issues otherwise, do the mocks not get generated? Unfortunately I think it's not possible to generate the mocks anywhere else as a Swift build tool plugin, maybe an investigation is in order.

soucolline commented 1 month ago

Hey @MatyasKriz thanks for the answer, the mocks are generated on the derivedData folder when I specify the plugin option in my Package.swift

If it's impossible to generate mocks outside of the derivedData maybe a third option with a CLI to generate the mocks whenever you want could work ? So that you don't have to rely on the plugin or a script phase

MatyasKriz commented 1 month ago

I'm not sure I understand, you can simply call the run script as defined in the script phase and it will work as you need, you can call it whenever you want and have the mocks generated.

Did I miss something?

soucolline commented 1 month ago

Oh ok I didn't see I could do that. I've tried running cuckoonator script and the mocks are created at the right location with it. I'll continue to dig a bit but it sounds good

soucolline commented 1 month ago

Ok I've migrated everything to 2.0.9 and it's working fine !

The only thing a bit annoying is that Cuckoo is located in the derived data because of how SPM works, the name of the folder is always changing so if I clean the project i need to find again the location of Cuckoo + rerun the run file which takes a bit of time to compile.

I'm wondering if it's technically possible to make a complete CLI of Cuckoo (which you would download from homebrew for exemple) ? This way you completely abstract the code generation from Xcode or a dependency manager and it can be run from anywhere (as long as you specify the location of the TOML file)

MatyasKriz commented 1 month ago

I think there's nothing preventing the creation of a CLI which manages the Cuckoonator version (this would allow specifying it in Cuckoofile as well, sounds cool), fetching it if it's not present and running it.

Unfortunately I don't have enough free time on my hands to implement it in the foreseeable future.

soucolline commented 1 month ago

For sure that's an idea worth exploring, I'll try to play a bit with it on my side

soucolline commented 3 weeks ago

Hey @MatyasKriz, I've played a bit with it this week-end and ended up making this repository : https://github.com/soucolline/homebrew-cuckoo

It's simply storing the Cuckoonator binary and then you can install it globally using homebrew

brew tap soucolline/homebrew-cuckoo
brew install cuckoonator

This way you can run cuckoonator whenever you want from the root of you project to generate the mocks

I find it a great installation + run alternative as it is not dependant on any package manager and can be installed the same using cocoapods / carthage and SPM and doesn't require any script phase or plugin.

I'll be maintaining and using it for my work and personal projects but if you want to officially support it one day it's only uploading a targ.gz of the Cuckoonator executable (I've used this https://bharathvaj-ganesan.medium.com/how-to-publish-your-nodejs-application-on-homebrew-7a24de9ea973)

MatyasKriz commented 3 weeks ago

Thanks for letting me know, perhaps some users will prefer this way of distribution. 🙂

I've been thinking of making the distributed binary a Cuckoonator manager, so that it will automatically make sure it's using the correct generator version to match the project's, but is customizable through Cuckoofile if needed.

nalounguyen commented 4 days ago

Ok I've migrated everything to 2.0.9 and it's working fine !

The only thing a bit annoying is that Cuckoo is located in the derived data because of how SPM works, the name of the folder is always changing so if I clean the project i need to find again the location of Cuckoo + rerun the run file which takes a bit of time to compile.

I'm wondering if it's technically possible to make a complete CLI of Cuckoo (which you would download from homebrew for exemple) ? This way you completely abstract the code generation from Xcode or a dependency manager and it can be run from anywhere (as long as you specify the location of the TOML file)

Hi @soucolline , I have the same issue, and this is my workaround

Screenshot 2024-09-08 at 15 36 00

Then I also created .sh file and can run with cmd.