Hey guys, is there any way to get the current Kotlin target from common code? I am writing a common test but the feature under test is not supported in Kotlin/Native, so I would like to just ignore the test on native. I could extract the test code into a common function and declare a test in every platform but the one to exclude, but that sounds inefficient
🤔 1
r
russhwolf
10/04/2021, 5:01 PM
You can always define your own
expect val platform
and check against that. Or if you want a slightly higher abstraction,
expect val hasFeature
.
j
Joffrey
10/04/2021, 5:03 PM
Yes that's the other option I had considered, but I was trying my luck for a built-in way 😄 Thanks anyway
a
andylamax
10/04/2021, 9:26 PM
You can also have an
expect annotation class
that is only a type alias to the supported platforms.
Then marking your tests with this annotation would effectively only work on the supported platforms
one minor annoyance is that you can't typealias another typealias, so
Copy code
// commonTest
@OptionalExpectation
expect annotation class JvmIgnore
// jvmTest
actual typealias JvmIgnore = kotlin.test.Ignore
doesn't work. but for
nativeTest
it should be fine
j
Joffrey
10/07/2021, 6:03 PM
Sorry for the delay, thanks a lot to both of you for the ideas. I got it to work by using the ignore annotation approach suggested by @ephemient, which indeed does work on native:
Copy code
// commonTest
@OptIn(ExperimentalMultiplatform::class)
@OptionalExpectation
expect annotation class IgnoreOnNative()
// iosTest
actual typealias IgnoreOnNative = kotlin.test.Ignore