Skip to content

Commit be463b3

Browse files
cleanup [platform]: Add EelSource(limitLocalRunPlatform) argument to filter local execution by OS.
In some rare cases you need to filter your test by local OS. This hack gives this ability, but do not use it unless you know what you are doing. GitOrigin-RevId: b70d2145a3be78d878ba0ca0572fe14bfe8866e0
1 parent a7107e5 commit be463b3

4 files changed

Lines changed: 38 additions & 15 deletions

File tree

platform/testFramework/junit5/eel/test/params/api/EelHolder.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
22
package com.intellij.platform.testFramework.junit5.eel.params.api
33

4-
import com.intellij.execution.target.EelTargetEnvironmentRequest
54
import com.intellij.execution.target.TargetEnvironmentConfiguration
65
import com.intellij.platform.eel.EelApi
76
import com.intellij.testFramework.junit5.eel.EelFixtureFilter

platform/testFramework/junit5/eel/test/params/api/EelSource.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
1+
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
22
package com.intellij.platform.testFramework.junit5.eel.params.api
33

44
import com.intellij.platform.testFramework.junit5.eel.params.impl.junit5.EelArgumentsProvider
@@ -13,10 +13,12 @@ import kotlin.annotation.AnnotationTarget.VALUE_PARAMETER
1313

1414
/**
1515
* Mark your parametrized test that accepts [EelHolder]
16-
* See [TestApplicationWithEel]
16+
* See [TestApplicationWithEel].
17+
*
18+
* [limitLocalRunPlatform] is very special and highly unrecommended hack to skip local executions on various OSes.
1719
*/
1820
@ArgumentsSource(EelArgumentsProvider::class)
1921
@CartesianArgumentsSource(EelCartesianArgumentsProvider::class)
2022
@TestOnly
2123
@Target(ANNOTATION_CLASS, VALUE_PARAMETER, CONSTRUCTOR, FUNCTION)
22-
annotation class EelSource
24+
annotation class EelSource(val limitLocalRunPlatform: TestPlatform = TestPlatform.ANY)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
package com.intellij.platform.testFramework.junit5.eel.params.api
3+
4+
import com.intellij.execution.Platform
5+
6+
enum class TestPlatform(internal val eelPlatform: Platform?) {
7+
POSIX(Platform.UNIX), WINDOWS(Platform.WINDOWS), ANY(null)
8+
}

platform/testFramework/junit5/eel/test/params/impl/junit5/providersJUnit5.kt

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
1+
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
22
package com.intellij.platform.testFramework.junit5.eel.params.impl.junit5
33

4+
import com.intellij.execution.Platform
45
import com.intellij.platform.testFramework.junit5.eel.params.api.EelHolder
56
import com.intellij.platform.testFramework.junit5.eel.params.api.EelHolderImpl
7+
import com.intellij.platform.testFramework.junit5.eel.params.api.EelSource
68
import com.intellij.platform.testFramework.junit5.eel.params.api.LocalEelHolder
79
import com.intellij.platform.testFramework.junit5.eel.params.impl.providers.getIjentTestProviders
810
import com.intellij.platform.testFramework.junit5.eel.params.spi.EelIjentTestProvider
911
import org.jetbrains.annotations.TestOnly
1012
import org.junit.jupiter.api.extension.ExtensionContext
1113
import org.junit.jupiter.params.provider.Arguments
1214
import org.junit.jupiter.params.provider.ArgumentsProvider
15+
import org.junit.jupiter.params.support.ParameterDeclarations
1316
import org.junit.platform.commons.util.AnnotationUtils
1417
import org.junitpioneer.jupiter.cartesian.CartesianParameterArgumentsProvider
1518
import java.lang.reflect.AnnotatedElement
@@ -19,31 +22,42 @@ import kotlin.jvm.optionals.getOrElse
1922

2023
@TestOnly
2124
internal class EelArgumentsProvider : ArgumentsProvider {
22-
override fun provideArguments(context: ExtensionContext): Stream<out Arguments> =
23-
getProvidersAsStream(context).map(Arguments::of)
25+
override fun provideArguments(
26+
parameters: ParameterDeclarations,
27+
context: ExtensionContext,
28+
): Stream<out Arguments> =
29+
getProvidersAsStream(context, parameters.sourceElement).map(Arguments::of)
2430
}
2531

2632
@TestOnly
2733
internal class EelCartesianArgumentsProvider : CartesianParameterArgumentsProvider<EelHolder> {
2834
override fun provideArguments(
2935
context: ExtensionContext,
3036
parameter: Parameter,
31-
): Stream<EelHolder> = getProvidersAsStream(context)
37+
): Stream<EelHolder> = getProvidersAsStream(context, parameter)
3238
}
3339

3440
@TestOnly
35-
private fun getProvidersAsStream(context: ExtensionContext): Stream<EelHolder> {
36-
val providers: Array<EelHolder> = arrayOf<EelHolder>(LocalEelHolder) + getIjentTestProviders().flatMap { provider ->
41+
private fun getProvidersAsStream(context: ExtensionContext, eelHolderElem: AnnotatedElement): Stream<EelHolder> {
42+
// parametrized classes might not have EelSource
43+
val limitLocalPlatform = eelHolderElem.getAnnotation(EelSource::class.java)?.limitLocalRunPlatform?.eelPlatform
44+
val allowLocal = limitLocalPlatform == null || limitLocalPlatform == Platform.current()
3745

38-
val annotatedElement: AnnotatedElement = arrayOf(context.testMethod, context.testClass).first { it.isPresent }.getOrElse {
39-
error("No method nor class has ${EelHolder::class} argument")
40-
}
41-
createHolders(provider, annotatedElement)
46+
// method or class might have mandatory (e.g. WslTest) annotation
47+
val elemForMandatoryAnno: AnnotatedElement = arrayOf(context.testMethod, context.testClass).first { it.isPresent }.getOrElse {
48+
error("No method nor class has ${EelHolder::class} argument")
49+
}
50+
val localProvider: Array<EelHolder> = if (allowLocal) arrayOf(LocalEelHolder) else emptyArray<EelHolder>()
51+
val providers: Array<EelHolder> = localProvider + getIjentTestProviders().flatMap { provider ->
52+
createHolders(provider, elemForMandatoryAnno)
4253
}.toTypedArray<EelHolder>()
4354
return Stream.of(*providers)
4455
}
4556

46-
private fun <T : Annotation> createHolders(provider: EelIjentTestProvider<T>, annotatedElement: AnnotatedElement): List<EelHolderImpl<T>> {
57+
private fun <T : Annotation> createHolders(
58+
provider: EelIjentTestProvider<T>,
59+
annotatedElement: AnnotatedElement,
60+
): List<EelHolderImpl<T>> {
4761
val annotations =
4862
AnnotationUtils.findRepeatableAnnotations(annotatedElement, provider.mandatoryAnnotationClass.java)
4963
return if (annotations.isEmpty()) {

0 commit comments

Comments
 (0)