Using SKitten to create LinuxMain.swift file
Would it be possible? I've been trying to make a decent python script to do this, but the lack of semantics makes it fragile: I can't know whether a class inherits from XCTest or know the relationship between two classes in different files. E.g: Foo inherits from Bar, and Bar inherits from XCTest, but in an extension. The combinations are endless, which seriously limits what I can make with just regexes. I'd need to make a compiler to address those issues 😅
Which brings me to SourceKit and therefore, SourceKitten. Could I do something like this:
- In a directory, get all Swift files and extract the classes that inherit from XCTest from them.
- Then, for each class, extract the names of all test methods that belong to it.
Just that would suffice. The rest is easy and does not require semantic knowledge (it's just string manipulation from then on).
Could I do this with SourceKitten?
I think you can achieve your goal by creating a Sourcery Template.
Yes... that's what I guessed. It looks promising, but the problem is that atm Sourcery isn't available for Linux u.u
Ah... That's unlucky. You can still create a tool based on SourceKitten for your goal.
Where should I start reading? Is there documentation on SKitten's API?
You can try executing sourcekitten structure --file path_to_your_source_file on every file in your test folder and collect json formatted outputs from sourcekitten.
Thank you! I'm starting to understand what the meaning of that JSON's fields are. I'm gonna see how far I can take this! :)
I gave a talk at App Builders 2016 demonstrating how you can use the sourcekitten CLI and jq to generate LinuxMain.swift, which might be a good starting point for you (slide 28):
- https://realm.io/news/appbuilders-jp-simard-sourcekit
- https://speakerdeck.com/jpsim/sourcekit-and-you
You could easily map the ideas from the CLI proof of concept to do so using SourceKittenFramework directly.