diff --git a/.idea/modules.xml b/.idea/modules.xml index 099a050ea0d5..3381db3cfd17 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -811,9 +811,10 @@ - + + diff --git a/build/bazel-generated-file-list.txt b/build/bazel-generated-file-list.txt index 680c7d60f8e4..e1d49e331885 100644 --- a/build/bazel-generated-file-list.txt +++ b/build/bazel-generated-file-list.txt @@ -1494,9 +1494,10 @@ tools/apiDump/testData tools/devLauncher tools/devLauncher/tests tools/intellij.lambda.sampleTests -tools/intellij.lambda.sampleTests/plugin tools/intellij.lambda.sampleTestsWithFixtures tools/intellij.lambda.sampleTestsWithFixtures/plugin +tools/intellij.lambda.sampleTestsWithPlugin +tools/intellij.lambda.sampleTestsWithPlugin/plugin tools/intellij.lambda.testFramework tools/intellij.lambda.testFramework/plugin tools/intellij.tools.ide.metrics.benchmark diff --git a/platform/remoteDev-util/src/com/intellij/remoteDev/tests/impl/LambdaTestHost.kt b/platform/remoteDev-util/src/com/intellij/remoteDev/tests/impl/LambdaTestHost.kt index 1707012a966c..a3ff9b35c6c5 100644 --- a/platform/remoteDev-util/src/com/intellij/remoteDev/tests/impl/LambdaTestHost.kt +++ b/platform/remoteDev-util/src/com/intellij/remoteDev/tests/impl/LambdaTestHost.kt @@ -196,24 +196,32 @@ open class LambdaTestHost(coroutineScope: CoroutineScope) { LambdaRdIdeType.MONOLITH -> LambdaMonolithContextClass() } - val testModuleId = System.getProperty(TEST_MODULE_ID_PROPERTY_NAME) - ?: error("Test module ID '$TEST_MODULE_ID_PROPERTY_NAME' is not specified") - val testModuleDescriptor = PluginManagerCore.getPluginSet().findEnabledModule(PluginModuleId(testModuleId, PluginModuleId.JETBRAINS_NAMESPACE)) - ?: error("Test plugin with test module '$testModuleId' is not found") + val testModuleDescriptor = run { + val testModuleId = System.getProperty(TEST_MODULE_ID_PROPERTY_NAME) + ?: return@run null + val tmd = PluginManagerCore.getPluginSet().findEnabledModule(PluginModuleId(testModuleId, PluginModuleId.JETBRAINS_NAMESPACE)) + ?: error("Test plugin with test module '$testModuleId' is not found") - assert(testModuleDescriptor.pluginClassLoader != null) { "Test plugin with test module '$testModuleId' is not loaded." + - "Probably due to missing dependencies, see `com.intellij.ide.plugins.ClassLoaderConfigurator#configureContentModule`." } + assert(tmd.pluginClassLoader != null) { + "Test plugin with test module '${testModuleId}' is not loaded." + + "Probably due to missing dependencies, see `com.intellij.ide.plugins.ClassLoaderConfigurator#configureContentModule`." + } + return@run tmd + } - - LOG.info("All test code will be loaded using '${testModuleDescriptor.pluginClassLoader}'") + LOG.info("All test code will be loaded using '${testModuleDescriptor?.pluginClassLoader}'") // Advice for processing events session.runLambda.setSuspend(sessionBgtDispatcher) { _, parameters -> LOG.info("'${parameters.reference}': received lambda execution request") + + assert(testModuleDescriptor != null) { + "Test module descriptor is not set, can't find test class '${parameters.reference}'" + } try { val lambdaReference = parameters.reference - val namedLambdas = findLambdaClasses(lambdaReference = lambdaReference, testModuleDescriptor = testModuleDescriptor, ideContext = ideContext) + val namedLambdas = findLambdaClasses(lambdaReference = lambdaReference, testModuleDescriptor = testModuleDescriptor!!, ideContext = ideContext) val ideAction = namedLambdas.singleOrNull { it.name() == lambdaReference } ?: run { val text = "There is no Action with reference '${lambdaReference}', something went terribly wrong, " + @@ -271,7 +279,7 @@ open class LambdaTestHost(coroutineScope: CoroutineScope) { val urls = serializedLambda.classPath.map { File(it).toURI().toURL() } runLogged(serializedLambda.stepName, 1.minutes) { - URLClassLoader(urls.toTypedArray(), testModuleDescriptor.pluginClassLoader).use { + URLClassLoader(urls.toTypedArray(), testModuleDescriptor?.pluginClassLoader ?: this::class.java.classLoader).use { SerializedLambdaLoader().load(serializedLambda.serializedDataBase64, classLoader = it, context = ideContext) .accept(ideContext) } diff --git a/tools/intellij.lambda.sampleTests/BUILD.bazel b/tools/intellij.lambda.sampleTests/BUILD.bazel index 36761a5c5c71..55d8d5d3e85d 100644 --- a/tools/intellij.lambda.sampleTests/BUILD.bazel +++ b/tools/intellij.lambda.sampleTests/BUILD.bazel @@ -1,24 +1,17 @@ ### auto-generated section `build intellij.lambda.sampleTests` start load("//build:compiler-options.bzl", "create_kotlinc_options") -load("@rules_jvm//:jvm.bzl", "jvm_library", "resourcegroup") +load("@rules_jvm//:jvm.bzl", "jvm_library") create_kotlinc_options( name = "custom_lambda-sampleTests", x_context_parameters = True ) -resourcegroup( - name = "lambda-sampleTests_test_resources", - srcs = glob(["resources/**/*"]), - strip_prefix = "resources" -) - jvm_library( name = "lambda-sampleTests_test_lib", module_name = "intellij.lambda.sampleTests", visibility = ["//visibility:public"], srcs = glob(["tests/**/*.kt", "tests/**/*.java", "tests/**/*.form"], allow_empty = True), - resources = [":lambda-sampleTests_test_resources"], kotlinc_opts = ":custom_lambda-sampleTests", deps = [ "@lib//:kodein-di-jvm", @@ -63,6 +56,7 @@ jvm_library( "//libraries/junit5-pioneer", "@lib//:rd-framework", "@lib//:rd-core", + "//platform/ide-core-impl", ] ) ### auto-generated section `build intellij.lambda.sampleTests` end diff --git a/tools/intellij.lambda.sampleTests/intellij.lambda.sampleTests.iml b/tools/intellij.lambda.sampleTests/intellij.lambda.sampleTests.iml index 81433216ccaf..e324db596c52 100644 --- a/tools/intellij.lambda.sampleTests/intellij.lambda.sampleTests.iml +++ b/tools/intellij.lambda.sampleTests/intellij.lambda.sampleTests.iml @@ -19,7 +19,6 @@ - @@ -60,5 +59,6 @@ + \ No newline at end of file diff --git a/tools/intellij.lambda.sampleTests/resources/META-INF/services/org.junit.jupiter.api.extension.Extension b/tools/intellij.lambda.sampleTests/resources/META-INF/services/org.junit.jupiter.api.extension.Extension deleted file mode 100644 index db25946f7b4d..000000000000 --- a/tools/intellij.lambda.sampleTests/resources/META-INF/services/org.junit.jupiter.api.extension.Extension +++ /dev/null @@ -1 +0,0 @@ -com.intellij.lambda.sampleTests.util.SetLambdaPluginCallback \ No newline at end of file diff --git a/tools/intellij.lambda.sampleTests/tests/com/intellij/lambda/sampleTests/SampleTest.kt b/tools/intellij.lambda.sampleTests/tests/com/intellij/lambda/sampleTests/SampleTest.kt index 3c0ea4314f97..6eed6c8d6ab9 100644 --- a/tools/intellij.lambda.sampleTests/tests/com/intellij/lambda/sampleTests/SampleTest.kt +++ b/tools/intellij.lambda.sampleTests/tests/com/intellij/lambda/sampleTests/SampleTest.kt @@ -1,79 +1,28 @@ // Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.lambda.sampleTests -import com.intellij.ide.plugins.PluginModuleDescriptor import com.intellij.lambda.testFramework.junit.ExecuteInMonolithAndSplitMode -import com.intellij.lambda.testFramework.junit.UltimateTestCases.JpsEmptyProject -import com.intellij.lambda.testFramework.testApi.editor.openFile -import com.intellij.lambda.testFramework.testApi.getProject -import com.intellij.lambda.testFramework.testApi.getProjects -import com.intellij.lambda.testFramework.testApi.utils.tryTimes -import com.intellij.lambda.testFramework.testApi.waitForProject import com.intellij.lambda.testFramework.utils.BackgroundRunWithLambda import com.intellij.openapi.diagnostic.Logger -import com.intellij.openapi.diagnostic.currentClassLogger -import com.intellij.remoteDev.tests.LambdaBackendContext -import com.intellij.remoteDev.tests.LambdaFrontendContext -import com.intellij.remoteDev.tests.impl.LambdaTestHost.Companion.NamedLambda -import com.intellij.remoteDev.tests.modelGenerated.LambdaRdKeyValueEntry -import com.intellij.util.io.createDirectories +import com.intellij.openapi.project.ex.ProjectManagerEx import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.TestTemplate -import kotlin.io.path.createFile -import kotlin.io.path.exists -import kotlin.time.Duration.Companion.seconds @ExecuteInMonolithAndSplitMode class SampleTest { @TestTemplate fun `serialized test`(ide: BackgroundRunWithLambda) = runBlocking { - //works in both modes if - // headless is turned off for monolith in com.intellij.lambda.testFramework.starter.NewContextWithLambdaKt.newContextWithLambda - // as ProjectManager returns empty projects list in headless - JpsEmptyProject.projectInfo.projectDir.resolve("src").resolve("FormattingExamplesExpected.java").let { - if (!it.exists()) { - it.parent.createDirectories() - it.createFile() - } - } ide.apply { - runInBackend { - waitForProject(20.seconds) - } run { - Logger.getInstance("test").warn("Projects: " + getProjects().joinToString { it.name }) + Logger.getInstance("test").warn("Projects: " + ProjectManagerEx.getOpenProjects().joinToString { it.name }) } runInBackend { - Logger.getInstance("test").warn("backend Projects: " + getProject()) - openFile("src/FormattingExamplesExpected.java", waitForReadyState = false, requireFocus = false) + Logger.getInstance("test").warn("backend Projects: " + ProjectManagerEx.getOpenProjects().joinToString { it.name }) } } Unit } - - @TestTemplate - fun `named lambda test`(ide: BackgroundRunWithLambda) = runBlocking { - ide.runNamedLambdaInBackend(HelloBackendOnlyLambda::class) - ide.runNamedLambda(HelloFrontendOnlyLambda::class) - } - - companion object { - class HelloFrontendOnlyLambda(frontendIdeContext: LambdaFrontendContext, plugin: PluginModuleDescriptor) - : NamedLambda(frontendIdeContext, plugin) { - override suspend fun LambdaFrontendContext.lambda(args: List): Any { - return tryTimes(2, "Log") { currentClassLogger().warn("Hi there Frontend") } - } - } - - class HelloBackendOnlyLambda(backendIdeContext: LambdaBackendContext, plugin: PluginModuleDescriptor) - : NamedLambda(backendIdeContext, plugin) { - override suspend fun LambdaBackendContext.lambda(args: List): Any { - return tryTimes(2, "Log") { currentClassLogger().warn("Hi there Backend") } - - } - } - } } diff --git a/tools/intellij.lambda.sampleTests/tests/com/intellij/lambda/sampleTests/util/SetLambdaPluginCallback.kt b/tools/intellij.lambda.sampleTests/tests/com/intellij/lambda/sampleTests/util/SetLambdaPluginCallback.kt deleted file mode 100644 index 499b7acc2699..000000000000 --- a/tools/intellij.lambda.sampleTests/tests/com/intellij/lambda/sampleTests/util/SetLambdaPluginCallback.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.intellij.lambda.sampleTests.util - -import com.intellij.lambda.testFramework.utils.LambdaTestPluginHolder -import org.junit.jupiter.api.extension.AfterAllCallback -import org.junit.jupiter.api.extension.BeforeAllCallback -import org.junit.jupiter.api.extension.ExtensionContext - -class SetLambdaPluginCallback : BeforeAllCallback, AfterAllCallback { - override fun beforeAll(context: ExtensionContext) { - LambdaTestPluginHolder.setupAdditionalLambdaPlugin("intellij.lambda.sampleTests._test", - "intellij.lambda.sampleTests.plugin", - "lambda-sampleTests-plugin") - } - - override fun afterAll(context: ExtensionContext) { - LambdaTestPluginHolder.cleanUpAdditionalLambdaPlugin() - } -} \ No newline at end of file diff --git a/tools/intellij.lambda.sampleTestsWithFixtures/tests/com/intellij/lambda/sampleTestsWithFixtures/util/SetLambdaPluginCallback.kt b/tools/intellij.lambda.sampleTestsWithFixtures/tests/com/intellij/lambda/sampleTestsWithFixtures/util/SetLambdaPluginCallback.kt index dc9a85dba26e..91ea65055a3e 100644 --- a/tools/intellij.lambda.sampleTestsWithFixtures/tests/com/intellij/lambda/sampleTestsWithFixtures/util/SetLambdaPluginCallback.kt +++ b/tools/intellij.lambda.sampleTestsWithFixtures/tests/com/intellij/lambda/sampleTestsWithFixtures/util/SetLambdaPluginCallback.kt @@ -2,15 +2,18 @@ package com.intellij.lambda.sampleTestsWithFixtures.util import com.intellij.lambda.testFramework.utils.LambdaTestPluginHolder +import com.intellij.lambda.testFramework.utils.LambdaTestPluginHolder.defaultLambdaPlugin import org.junit.jupiter.api.extension.AfterAllCallback import org.junit.jupiter.api.extension.BeforeAllCallback import org.junit.jupiter.api.extension.ExtensionContext class SetLambdaPluginCallback : BeforeAllCallback, AfterAllCallback { + val localCustomLambdaPlugin = LambdaTestPluginHolder.AdditionalLambdaPlugin("intellij.lambda.sampleTestsWithFixtures._test", + "intellij.lambda.sampleTestsWithFixtures.plugin", + "lambda-sampleTestsWithFixtures-plugin") + override fun beforeAll(context: ExtensionContext) { - LambdaTestPluginHolder.setupAdditionalLambdaPlugin("intellij.lambda.sampleTestsWithFixtures._test", - "intellij.lambda.sampleTestsWithFixtures.plugin", - "lambda-sampleTestsWithFixtures-plugin") + LambdaTestPluginHolder.setupAdditionalLambdaPlugins(localCustomLambdaPlugin.moduleID, listOf(localCustomLambdaPlugin, defaultLambdaPlugin)) } override fun afterAll(context: ExtensionContext) { diff --git a/tools/intellij.lambda.sampleTestsWithPlugin/BUILD.bazel b/tools/intellij.lambda.sampleTestsWithPlugin/BUILD.bazel new file mode 100644 index 000000000000..0d4fd4fc1e7b --- /dev/null +++ b/tools/intellij.lambda.sampleTestsWithPlugin/BUILD.bazel @@ -0,0 +1,77 @@ +### auto-generated section `build intellij.lambda.sampleTestsWithPlugin` start +load("//build:compiler-options.bzl", "create_kotlinc_options") +load("@rules_jvm//:jvm.bzl", "jvm_library", "resourcegroup") + +create_kotlinc_options( + name = "custom_lambda-sampleTestsWithPlugin", + x_context_parameters = True +) + +resourcegroup( + name = "lambda-sampleTestsWithPlugin_test_resources", + srcs = glob(["resources/**/*"]), + strip_prefix = "resources" +) + +jvm_library( + name = "lambda-sampleTestsWithPlugin_test_lib", + module_name = "intellij.lambda.sampleTestsWithPlugin", + visibility = ["//visibility:public"], + srcs = glob(["tests/**/*.kt", "tests/**/*.java", "tests/**/*.form"], allow_empty = True), + resources = [":lambda-sampleTestsWithPlugin_test_resources"], + kotlinc_opts = ":custom_lambda-sampleTestsWithPlugin", + deps = [ + "@lib//:kodein-di-jvm", + "@lib//:kotlin-stdlib", + "@lib//:kotlin-test", + "@lib//:assert_j", + "//libraries/kotlin/reflect", + "//tools/intellij.tools.ide.starter:ide-starter", + "//tools/intellij.tools.ide.starter.junit5:ide-starter-junit5", + "//tools/intellij.tools.ide.starter.junit5:ide-starter-junit5_test_lib", + "//tools/intellij.tools.ide.starter.driver:ide-starter-driver", + "//tools/intellij.tools.ide.starter.build.server:ide-starter-build-server", + "//platform/core-api:core", + "//platform/core-impl", + "//platform/core-ui", + "//platform/lang-api:lang", + "//platform/lang-impl", + "//platform/platform-api:ide", + "//platform/editor-ui-api:editor-ui", + "//platform/editor-ui-ex:editor-ex", + "//platform/testFramework/junit5", + "//platform/testFramework/junit5:junit5_test_lib", + "//platform/code-style-api:codeStyle", + "//platform/execution-impl", + "//platform/platform-impl:ide-impl", + "//platform/remoteDev-util", + "//platform/remoteDev-util:remoteDev-util_test_lib", + "//platform/analysis-api:analysis", + "//plugins/performanceTesting/core:performanceTesting", + "//plugins/performanceTesting/core:performanceTesting_test_lib", + "//platform/platform-impl/codeinsight-inline:ide-codeinsight-inline", + "//platform/xdebugger-api:debugger", + "//platform/xdebugger-impl:debugger-impl", + "//platform/xdebugger-impl:debugger-impl_test_lib", + "//platform/util/concurrency", + "//platform/util/concurrency:concurrency_test_lib", + "//platform/usageView", + "//tools/intellij.lambda.testFramework:lambda-testFramework", + "//libraries/junit5", + "//libraries/junit5-launcher", + "//libraries/junit5-params", + "//libraries/junit5-pioneer", + "@lib//:rd-framework", + "@lib//:rd-core", + ] +) +### auto-generated section `build intellij.lambda.sampleTestsWithPlugin` end + +### auto-generated section `test intellij.lambda.sampleTestsWithPlugin` start +load("@community//build:tests-options.bzl", "jps_test") + +jps_test( + name = "lambda-sampleTestsWithPlugin_test", + runtime_deps = [":lambda-sampleTestsWithPlugin_test_lib"] +) +### auto-generated section `test intellij.lambda.sampleTestsWithPlugin` end \ No newline at end of file diff --git a/tools/intellij.lambda.sampleTestsWithPlugin/intellij.lambda.sampleTestsWithPlugin.iml b/tools/intellij.lambda.sampleTestsWithPlugin/intellij.lambda.sampleTestsWithPlugin.iml new file mode 100644 index 000000000000..81433216ccaf --- /dev/null +++ b/tools/intellij.lambda.sampleTestsWithPlugin/intellij.lambda.sampleTestsWithPlugin.iml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/intellij.lambda.sampleTests/plugin/BUILD.bazel b/tools/intellij.lambda.sampleTestsWithPlugin/plugin/BUILD.bazel similarity index 59% rename from tools/intellij.lambda.sampleTests/plugin/BUILD.bazel rename to tools/intellij.lambda.sampleTestsWithPlugin/plugin/BUILD.bazel index 1c3fa6439f77..106fe20b071e 100644 --- a/tools/intellij.lambda.sampleTests/plugin/BUILD.bazel +++ b/tools/intellij.lambda.sampleTestsWithPlugin/plugin/BUILD.bazel @@ -1,4 +1,4 @@ -### auto-generated section `build intellij.lambda.sampleTests.plugin` start +### auto-generated section `build intellij.lambda.sampleTestsWithPlugin.plugin` start load("@rules_jvm//:jvm.bzl", "jvm_library", "resourcegroup") resourcegroup( @@ -9,9 +9,9 @@ resourcegroup( jvm_library( name = "plugin_test_lib", - module_name = "intellij.lambda.sampleTests.plugin", + module_name = "intellij.lambda.sampleTestsWithPlugin.plugin", visibility = ["//visibility:public"], srcs = glob([], allow_empty = True), resources = [":plugin_test_resources"] ) -### auto-generated section `build intellij.lambda.sampleTests.plugin` end \ No newline at end of file +### auto-generated section `build intellij.lambda.sampleTestsWithPlugin.plugin` end \ No newline at end of file diff --git a/tools/intellij.lambda.sampleTests/plugin/intellij.lambda.sampleTests.plugin.iml b/tools/intellij.lambda.sampleTestsWithPlugin/plugin/intellij.lambda.sampleTestsWithPlugin.plugin.iml similarity index 100% rename from tools/intellij.lambda.sampleTests/plugin/intellij.lambda.sampleTests.plugin.iml rename to tools/intellij.lambda.sampleTestsWithPlugin/plugin/intellij.lambda.sampleTestsWithPlugin.plugin.iml diff --git a/tools/intellij.lambda.sampleTests/plugin/testResources/META-INF/plugin.xml b/tools/intellij.lambda.sampleTestsWithPlugin/plugin/testResources/META-INF/plugin.xml similarity index 60% rename from tools/intellij.lambda.sampleTests/plugin/testResources/META-INF/plugin.xml rename to tools/intellij.lambda.sampleTestsWithPlugin/plugin/testResources/META-INF/plugin.xml index 7d83c3f9e17a..83dc333db31f 100644 --- a/tools/intellij.lambda.sampleTests/plugin/testResources/META-INF/plugin.xml +++ b/tools/intellij.lambda.sampleTestsWithPlugin/plugin/testResources/META-INF/plugin.xml @@ -1,9 +1,9 @@ - com.intellij.lambda.sampleTests.plugin + com.intellij.lambda.sampleTestsWithPlugin.plugin JetBrains - + diff --git a/tools/intellij.lambda.sampleTestsWithPlugin/resources/META-INF/services/org.junit.jupiter.api.extension.Extension b/tools/intellij.lambda.sampleTestsWithPlugin/resources/META-INF/services/org.junit.jupiter.api.extension.Extension new file mode 100644 index 000000000000..5889ed48dbf8 --- /dev/null +++ b/tools/intellij.lambda.sampleTestsWithPlugin/resources/META-INF/services/org.junit.jupiter.api.extension.Extension @@ -0,0 +1 @@ +com.intellij.lambda.sampleTestsWithPlugin.util.SetLambdaPluginCallback \ No newline at end of file diff --git a/tools/intellij.lambda.sampleTestsWithPlugin/resources/intellij.lambda.sampleTestsWithPlugin._test.xml b/tools/intellij.lambda.sampleTestsWithPlugin/resources/intellij.lambda.sampleTestsWithPlugin._test.xml new file mode 100644 index 000000000000..6fb76a66265d --- /dev/null +++ b/tools/intellij.lambda.sampleTestsWithPlugin/resources/intellij.lambda.sampleTestsWithPlugin._test.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tools/intellij.lambda.sampleTests/tests/com/intellij/lambda/sampleTests/MixedExampleTest.kt b/tools/intellij.lambda.sampleTestsWithPlugin/tests/com/intellij/lambda/sampleTestsWithPlugin/MixedExampleTest.kt similarity index 95% rename from tools/intellij.lambda.sampleTests/tests/com/intellij/lambda/sampleTests/MixedExampleTest.kt rename to tools/intellij.lambda.sampleTestsWithPlugin/tests/com/intellij/lambda/sampleTestsWithPlugin/MixedExampleTest.kt index 8c2122fa7b87..540aa42a5a2e 100644 --- a/tools/intellij.lambda.sampleTests/tests/com/intellij/lambda/sampleTests/MixedExampleTest.kt +++ b/tools/intellij.lambda.sampleTestsWithPlugin/tests/com/intellij/lambda/sampleTestsWithPlugin/MixedExampleTest.kt @@ -1,4 +1,4 @@ -package com.intellij.lambda.sampleTests +package com.intellij.lambda.sampleTestsWithPlugin import com.intellij.lambda.testFramework.junit.ExecuteInMonolithAndSplitMode import com.intellij.lambda.testFramework.utils.BackgroundRunWithLambda diff --git a/tools/intellij.lambda.sampleTestsWithPlugin/tests/com/intellij/lambda/sampleTestsWithPlugin/SampleTest.kt b/tools/intellij.lambda.sampleTestsWithPlugin/tests/com/intellij/lambda/sampleTestsWithPlugin/SampleTest.kt new file mode 100644 index 000000000000..2351dea0afaf --- /dev/null +++ b/tools/intellij.lambda.sampleTestsWithPlugin/tests/com/intellij/lambda/sampleTestsWithPlugin/SampleTest.kt @@ -0,0 +1,79 @@ +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.lambda.sampleTestsWithPlugin + +import com.intellij.ide.plugins.PluginModuleDescriptor +import com.intellij.lambda.testFramework.junit.ExecuteInMonolithAndSplitMode +import com.intellij.lambda.testFramework.junit.UltimateTestCases.JpsEmptyProject +import com.intellij.lambda.testFramework.testApi.editor.openFile +import com.intellij.lambda.testFramework.testApi.getProject +import com.intellij.lambda.testFramework.testApi.getProjects +import com.intellij.lambda.testFramework.testApi.utils.tryTimes +import com.intellij.lambda.testFramework.testApi.waitForProject +import com.intellij.lambda.testFramework.utils.BackgroundRunWithLambda +import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.diagnostic.currentClassLogger +import com.intellij.remoteDev.tests.LambdaBackendContext +import com.intellij.remoteDev.tests.LambdaFrontendContext +import com.intellij.remoteDev.tests.impl.LambdaTestHost.Companion.NamedLambda +import com.intellij.remoteDev.tests.modelGenerated.LambdaRdKeyValueEntry +import com.intellij.util.io.createDirectories +import kotlinx.coroutines.runBlocking +import org.junit.jupiter.api.TestTemplate +import kotlin.io.path.createFile +import kotlin.io.path.exists +import kotlin.time.Duration.Companion.seconds + +@ExecuteInMonolithAndSplitMode +class SampleTest { + @TestTemplate + fun `serialized test`(ide: BackgroundRunWithLambda) = runBlocking { + //works in both modes if + // headless is turned off for monolith in com.intellij.lambda.testFramework.starter.NewContextWithLambdaKt.newContextWithLambda + // as ProjectManager returns empty projects list in headless + JpsEmptyProject.projectInfo.projectDir.resolve("src").resolve("FormattingExamplesExpected.java").let { + if (!it.exists()) { + it.parent.createDirectories() + it.createFile() + } + } + ide.apply { + runInBackend { + waitForProject(20.seconds) + } + + run { + Logger.getInstance("test").warn("Projects: " + getProjects().joinToString { it.name }) + } + + runInBackend { + Logger.getInstance("test").warn("backend Projects: " + getProject()) + openFile("src/FormattingExamplesExpected.java", waitForReadyState = false, requireFocus = false) + } + } + Unit + } + + @TestTemplate + fun `named lambda test`(ide: BackgroundRunWithLambda) = runBlocking { + ide.runNamedLambdaInBackend(HelloBackendOnlyLambda::class) + ide.runNamedLambda(HelloFrontendOnlyLambda::class) + } + + companion object { + class HelloFrontendOnlyLambda(frontendIdeContext: LambdaFrontendContext, plugin: PluginModuleDescriptor) + : NamedLambda(frontendIdeContext, plugin) { + override suspend fun LambdaFrontendContext.lambda(args: List): Any { + return tryTimes(2, "Log") { currentClassLogger().warn("Hi there Frontend") } + } + } + + class HelloBackendOnlyLambda(backendIdeContext: LambdaBackendContext, plugin: PluginModuleDescriptor) + : NamedLambda(backendIdeContext, plugin) { + override suspend fun LambdaBackendContext.lambda(args: List): Any { + return tryTimes(2, "Log") { currentClassLogger().warn("Hi there Backend") } + + } + } + } +} + diff --git a/tools/intellij.lambda.sampleTests/tests/com/intellij/lambda/sampleTests/UnitSplitExampleTest.kt b/tools/intellij.lambda.sampleTestsWithPlugin/tests/com/intellij/lambda/sampleTestsWithPlugin/UnitSplitExampleTest.kt similarity index 88% rename from tools/intellij.lambda.sampleTests/tests/com/intellij/lambda/sampleTests/UnitSplitExampleTest.kt rename to tools/intellij.lambda.sampleTestsWithPlugin/tests/com/intellij/lambda/sampleTestsWithPlugin/UnitSplitExampleTest.kt index 654944d3c1d9..32dd14d1b1aa 100644 --- a/tools/intellij.lambda.sampleTests/tests/com/intellij/lambda/sampleTests/UnitSplitExampleTest.kt +++ b/tools/intellij.lambda.sampleTestsWithPlugin/tests/com/intellij/lambda/sampleTestsWithPlugin/UnitSplitExampleTest.kt @@ -1,4 +1,4 @@ -package com.intellij.lambda.sampleTests +package com.intellij.lambda.sampleTestsWithPlugin import com.intellij.lambda.testFramework.junit.ExecuteInMonolithAndSplitMode import com.intellij.openapi.application.ApplicationManager diff --git a/tools/intellij.lambda.sampleTestsWithPlugin/tests/com/intellij/lambda/sampleTestsWithPlugin/util/SetLambdaPluginCallback.kt b/tools/intellij.lambda.sampleTestsWithPlugin/tests/com/intellij/lambda/sampleTestsWithPlugin/util/SetLambdaPluginCallback.kt new file mode 100644 index 000000000000..9526c99d7a77 --- /dev/null +++ b/tools/intellij.lambda.sampleTestsWithPlugin/tests/com/intellij/lambda/sampleTestsWithPlugin/util/SetLambdaPluginCallback.kt @@ -0,0 +1,20 @@ +package com.intellij.lambda.sampleTestsWithPlugin.util + +import com.intellij.lambda.testFramework.utils.LambdaTestPluginHolder +import com.intellij.lambda.testFramework.utils.LambdaTestPluginHolder.defaultLambdaPlugin +import org.junit.jupiter.api.extension.AfterAllCallback +import org.junit.jupiter.api.extension.BeforeAllCallback +import org.junit.jupiter.api.extension.ExtensionContext + +class SetLambdaPluginCallback : BeforeAllCallback, AfterAllCallback { + val localCustomLambdaPlugin = LambdaTestPluginHolder.AdditionalLambdaPlugin("intellij.lambda.sampleTestsWithPlugin._test", + "intellij.lambda.sampleTestsWithPlugin.plugin", + "lambda-sampleTestsWithPlugin-plugin") + + override fun beforeAll(context: ExtensionContext) { + LambdaTestPluginHolder.setupAdditionalLambdaPlugins(localCustomLambdaPlugin.moduleID, listOf(localCustomLambdaPlugin, defaultLambdaPlugin)) + } + override fun afterAll(context: ExtensionContext) { + LambdaTestPluginHolder.cleanUpAdditionalLambdaPlugin() + } +} \ No newline at end of file diff --git a/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/utils/IdeLambdaStarter.kt b/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/utils/IdeLambdaStarter.kt index fc18bdaef226..1b276911cf41 100644 --- a/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/utils/IdeLambdaStarter.kt +++ b/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/utils/IdeLambdaStarter.kt @@ -69,7 +69,9 @@ object IdeLambdaStarter { applyVMOptionsPatch { addSystemProperty(LambdaTestsConstants.protocolPortPropertyName, testProtocolPort) - addSystemProperty(TEST_MODULE_ID_PROPERTY_NAME, LambdaTestPluginHolder.testModuleId()) + LambdaTestPluginHolder.testModuleId()?.let { + addSystemProperty(TEST_MODULE_ID_PROPERTY_NAME, it) + } } val rdSession = LambdaRdTestSession(lambdaRdIdeType) diff --git a/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/utils/LambdaTestPluginHolder.kt b/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/utils/LambdaTestPluginHolder.kt index 1ae56c72baad..6d9b1e686ff0 100644 --- a/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/utils/LambdaTestPluginHolder.kt +++ b/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/utils/LambdaTestPluginHolder.kt @@ -1,21 +1,26 @@ package com.intellij.lambda.testFramework.utils object LambdaTestPluginHolder { - private data class AdditionalLambdaPlugin(val moduleID: String, val pluginId: String, val pluginDirName: String) + data class AdditionalLambdaPlugin(val moduleID: String, val pluginId: String, val pluginDirName: String) - private var additionalLambdaPlugin: AdditionalLambdaPlugin? = null - private val defaultLambdaPlugin: AdditionalLambdaPlugin = AdditionalLambdaPlugin("intellij.lambda.testFramework", - "intellij.lambda.test.plugin", - "lambda-test-plugin") + private var additionalLambdaPlugins: List = emptyList() + private var mainTestModuleId: String? = null + val defaultLambdaPlugin: AdditionalLambdaPlugin = AdditionalLambdaPlugin("intellij.lambda.testFramework", + "intellij.lambda.test.plugin", + "lambda-test-plugin") - fun testModuleId(): String = additionalLambdaPlugin?.moduleID ?: defaultLambdaPlugin.moduleID - fun additionalPluginIds(): List = listOfNotNull(defaultLambdaPlugin.pluginId, additionalLambdaPlugin?.pluginId) - fun additionalPluginDirNames(): List = listOfNotNull(defaultLambdaPlugin.pluginDirName, additionalLambdaPlugin?.pluginDirName) - fun setupAdditionalLambdaPlugin(moduleID: String, pluginId: String, pluginDirName: String) { - additionalLambdaPlugin = AdditionalLambdaPlugin(moduleID, pluginId, pluginDirName) + fun testModuleId(): String? = mainTestModuleId + fun additionalPluginIds(): List = additionalLambdaPlugins.map { it.pluginId } + fun additionalPluginDirNames(): List = additionalLambdaPlugins.map { it.pluginDirName } + + fun setupAdditionalLambdaPlugins(mainTestModuleId: String, additionalLambdaPlugins: List) { + this.mainTestModuleId = mainTestModuleId + this.additionalLambdaPlugins = additionalLambdaPlugins } + fun cleanUpAdditionalLambdaPlugin() { - additionalLambdaPlugin = null + this.mainTestModuleId = null + this.additionalLambdaPlugins = emptyList() } } \ No newline at end of file