There is an option in the swift package manager
swift test --generate-linuxmain that generates the
Tests/LinuxMain.swift needed for testing on Linux systems. In order to generate this file, the test target is compiled first and a number of
XCTestManifest.swift files are generated. However, if one renames one test, the next time the command is run, the target won't be able to compile and so the corresponding manifest cannot be updated.
The only workarounds seem to be to rename the test manually in the manifest too or to delete the manifest file before running the command. I think this is slightly suboptimal.
Thanks @yxckjhasdkjh, this is definitely a bug and SwiftPM should do the right thing. Do you mind filing a JIRA for this? Here are the instructions.
FWIW, in our codebase we've dropped the standard way and implemented an own script using Sourcery (there are enough blog posts etc. about how to do this). Reasoning:
- We want to generate LinuxMain in a pre-commit hook. But the standard way needs to compile the whole code which means every commit becomes incredibly slow.
- It also means that code that doesn't compile can't be properly commited (could arguably be a good thing, but still).
- the standard way generates too many files (test manifest files). This is annoying: every time I add a new test target, I have to update my .swiflint.yml (to exclude the new manifest) and the git hook (to automatically add that manifest to the commit), and also it's annoying for code review
- And our approach doesn't suffer from the bug mentioned in this thread.
So, all in all, the way SPM generates LinuxMain turns out not to be practicable for us.
Thank you! Those are great points. I'll see what I can do to address some of them as part of SR-7754.