From 7594671bb8659a6320dee6c338463d522df24db0 Mon Sep 17 00:00:00 2001 From: Sergey Karashevich Date: Thu, 20 Apr 2017 18:29:36 +0300 Subject: [PATCH] [gui-test] make TestGuiFramework plugin to be supported by IntelliJ-based IDEs; add local test launch (without client-server infrastructure) --- .../testGuiFramework/res/META-INF/plugin.xml | 2 ++ .../testGuiFramework/impl/GuiTestStarter.kt | 36 +++++++++++++------ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/platform/testGuiFramework/res/META-INF/plugin.xml b/platform/testGuiFramework/res/META-INF/plugin.xml index faedc187e860..7e3e9f680e69 100644 --- a/platform/testGuiFramework/res/META-INF/plugin.xml +++ b/platform/testGuiFramework/res/META-INF/plugin.xml @@ -4,6 +4,8 @@ TestGuiFramework JetBrains + com.intellij.modules.lang + diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestStarter.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestStarter.kt index 446da193c821..df2562480c64 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestStarter.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestStarter.kt @@ -19,11 +19,12 @@ import com.intellij.idea.IdeaApplication import com.intellij.openapi.application.ApplicationStarter import com.intellij.openapi.diagnostic.Logger import com.intellij.testGuiFramework.remote.JUnitClient +import org.junit.runner.JUnitCore /** * @author Sergey Karashevich */ -class GuiTestStarter(): IdeaApplication.IdeStarter(), ApplicationStarter { +class GuiTestStarter: IdeaApplication.IdeStarter(), ApplicationStarter { private val LOG = Logger.getInstance(this.javaClass) @@ -35,8 +36,10 @@ class GuiTestStarter(): IdeaApplication.IdeStarter(), ApplicationStarter { System.getProperty(GUI_TEST_HOST) } - val port: Int by lazy { - System.getProperty(GUI_TEST_PORT)!!.toInt() + val port: Int? by lazy { + val guiTestPort = System.getProperty(GUI_TEST_PORT) + if (guiTestPort == null || guiTestPort == PORT_UNDEFINED) null + else guiTestPort.toInt() } val guiTestList: List> by lazy { @@ -56,6 +59,10 @@ class GuiTestStarter(): IdeaApplication.IdeStarter(), ApplicationStarter { override fun getCommandName() = "guitest" + private val PORT_UNDEFINED = "undefined" + + private val HOST_LOCALHOST = "localhost" + override fun premain(args: Array) { processArgs(args) runActivity(args) @@ -73,16 +80,21 @@ class GuiTestStarter(): IdeaApplication.IdeStarter(), ApplicationStarter { guiTestThread.join() if (myClient != null) myClient!!.stopClient() } - fun runActivity(args: Array) { LOG.info("Starting GuiTest activity") guiTestThread.start() } + fun run() { assert(myClient == null) - myClient = JUnitClient(host, port) - myClient!!.runTests(*guiTestList.toTypedArray()) + if (port != null) { + myClient = JUnitClient(host, port!!) + myClient!!.runTests(*guiTestList.toTypedArray()) + } else { + val core = JUnitCore() + core.run(*guiTestList.toTypedArray()) + } } /** @@ -91,10 +103,14 @@ class GuiTestStarter(): IdeaApplication.IdeStarter(), ApplicationStarter { private fun processArgs(args: Array) { val guiTestList = args[1].removeSurrounding("\"") System.setProperty(GUI_TEST_LIST, guiTestList) - val hostArg = args.find { arg -> arg.toLowerCase().startsWith("host") }?.substringAfter("host=") ?: "localhost" - System.setProperty(GUI_TEST_HOST, hostArg.removeSurrounding("\"")) - val portArg = args.find { arg -> arg.toLowerCase().startsWith("port") }?.substringAfter("port=") ?: throw Exception("Unable to read port value from args: $args") - System.setProperty(GUI_TEST_PORT, portArg.removeSurrounding("\"")) + val hostArg : String? = args.find { arg -> arg.toLowerCase().startsWith("host") }?.substringAfter("host=") ?: HOST_LOCALHOST + System.setProperty(GUI_TEST_HOST, hostArg!!.removeSurrounding("\"")) + val portArg : String? = args.find { arg -> arg.toLowerCase().startsWith("port") }?.substringAfter("port=") ?: PORT_UNDEFINED + if (portArg != null) + System.setProperty(GUI_TEST_PORT, portArg.removeSurrounding("\"")) + else + System.setProperty(GUI_TEST_PORT, PORT_UNDEFINED) + LOG.info("Set GUI tests list: $guiTestList") LOG.info("Set GUI tests host: $hostArg") LOG.info("Set GUI tests port: $portArg")