Hey guys, is there any way to get the current Kotl...
# multiplatform
j
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
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
Yes that's the other option I had considered, but I was trying my luck for a built-in way 😄 Thanks anyway
a
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
e
declare it with @OptionalExpectation to omit the
actual
on the platforms where you don't want it
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
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