I have a test that I need to run only on Linux.
Is it a better practice to wrap the entire test in #if os(Linux) / #endif or to use the enabled() or disabled() trait and return true/false based on conditional compilation?
I have a test that I need to run only on Linux.
Is it a better practice to wrap the entire test in #if os(Linux) / #endif or to use the enabled() or disabled() trait and return true/false based on conditional compilation?
In my opinion both ways are fine, but I prefer the trait based approach because your test will still appear in the test run report, just marked as skipped.
This keeps the total number of tests consistent across platforms, which is a small ergonomics win when you’re flipping through test run results for different platforms.
"Whichever compiles."
The body of your test must type-check and compile before the @Test attribute/macro is expanded. So if the body of your test requires something specific to Linux, you'll need to use #if os(Linux). If the test compiles but you don't want to run it on other platforms, .disabled() works.
This is, BTW, why we don't offer something like .disabled(on: Linux): half the time it won't help because the test body won't compile in the first place, and having API like that will just cause more confusion.