[gui-test] introduce GuiTestOptions; CommandLineProjectTest fix

Introducing GuiTestOptions to specify VM options (such as config and system paths, debug enabling etc) to start IDEA with.

Fix CommandLineProjectTest code example; add tabs converting.
This commit is contained in:
Sergey Karashevich
2017-07-10 13:21:01 +03:00
parent 1075ae4dde
commit 8ecc3ef5bc
4 changed files with 98 additions and 27 deletions
@@ -169,31 +169,30 @@ object GuiTestLocalLauncher {
return resultingArgs
}
private fun getDefaultVmOptions(ide: Ide,
configPath: String = "../config",
systemPath: String = "../system",
bootClasspath: String = "../out/classes/production/boot",
encoding: String = "UTF-8",
isInternal: Boolean = true,
useMenuScreenBar: Boolean = true,
debugPort: Int = 5009,
suspendDebug: String = "n"): List<String> =
listOf<String>()
.plus("-ea")
.plus("-Xbootclasspath/p:$bootClasspath")
.plus("-Dsun.awt.disablegrab=true")
.plus("-Dsun.io.useCanonCaches=false")
.plus("-Djava.net.preferIPv4Stack=true")
.plus("-Dapple.laf.useScreenMenuBar=${useMenuScreenBar.toString()}")
.plus("-Didea.is.internal=${isInternal.toString()}")
.plus("-Didea.config.path=$configPath")
.plus("-Didea.system.path=$systemPath")
.plus("-Dfile.encoding=$encoding")
.plus("-Didea.platform.prefix=${ide.ideType.platformPrefix}")
.plus("-Xdebug")
.plus(
"-Xrunjdwp:transport=dt_socket,server=y,suspend=$suspendDebug,address=$debugPort") //todo: add System.getProperty(...) to customize debug port
/**
* Default VM options to start IntelliJ IDEA (or IDEA-based IDE). To customize options use com.intellij.testGuiFramework.launcher.GuiTestOptions
*/
private fun getDefaultVmOptions(ide: Ide) : List<String> {
return listOf<String>()
.plus("-Xmx${GuiTestOptions.getXmxSize()}m")
.plus("-XX:ReservedCodeCacheSize=150m")
.plus("-XX:+UseConcMarkSweepGC")
.plus("-XX:SoftRefLRUPolicyMSPerMB=50")
.plus("-XX:MaxJavaStackTraceDepth=10000")
.plus("-ea")
.plus("-Xbootclasspath/p:${GuiTestOptions.getBootClasspath()}")
.plus("-Dsun.awt.disablegrab=true")
.plus("-Dsun.io.useCanonCaches=false")
.plus("-Djava.net.preferIPv4Stack=true")
.plus("-Dapple.laf.useScreenMenuBar=${GuiTestOptions.useAppleScreenMenuBar().toString()}")
.plus("-Didea.is.internal=${GuiTestOptions.isInternal().toString()}")
.plus("-Didea.config.path=${GuiTestOptions.getConfigPath()}")
.plus("-Didea.system.path=${GuiTestOptions.getSystemPath()}")
.plus("-Dfile.encoding=${GuiTestOptions.getEncoding()}")
.plus("-Didea.platform.prefix=${ide.ideType.platformPrefix}")
.plus("-Xdebug")
.plus("-Xrunjdwp:transport=dt_socket,server=y,suspend=${GuiTestOptions.suspendDebug()},address=${GuiTestOptions.getDebugPort()}")
}
private fun getCurrentJavaExec(): String {
return PathUtils.getJreBinPath()
@@ -0,0 +1,61 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testGuiFramework.launcher
import com.intellij.openapi.application.PathManager
object GuiTestOptions {
fun getConfigPath(): String = getSystemProperty("idea.config.path", getConfigDefaultPath())
fun getSystemPath(): String = getSystemProperty("idea.system.path", getSystemDefaultPath())
fun isDebug(): Boolean = getSystemProperty("idea.debug.mode", false)
fun suspendDebug(): String = if (isDebug()) "y" else "n"
fun isInternal(): Boolean = getSystemProperty("idea.is.internal", true)
fun useAppleScreenMenuBar(): Boolean = getSystemProperty("apple.laf.useScreenMenuBar", false)
fun getDebugPort(): Int = getSystemProperty("idea.gui.test.debug.port", 5009)
fun getBootClasspath(): String = getSystemProperty("idea.gui.test.bootclasspath", "../out/classes/production/boot")
fun getEncoding(): String = getSystemProperty("idea.gui.test.encoding", "UTF-8")
fun getXmxSize(): Int = getSystemProperty("idea.gui.test.xmx", 512)
fun getConfigDefaultPath(): String {
try {
return "${PathManager.getHomePath()}/config"
}
catch(e: RuntimeException) {
return "../config"
}
}
fun getSystemDefaultPath(): String {
try {
return "${PathManager.getHomePath()}/system"
}
catch(e: RuntimeException) {
return "../system"
}
}
inline fun <reified ReturnType> getSystemProperty(key: String, defaultValue: ReturnType): ReturnType {
val value = System.getProperty(key) ?: return defaultValue
return when (defaultValue) {
is Int -> value.toInt() as ReturnType
is Boolean -> value.toBoolean() as ReturnType
is String -> value as ReturnType
else -> throw Exception("Unable to get returning type of default value (not integer, boolean or string) for key: $key")
}
}
}
@@ -23,5 +23,6 @@
<orderEntry type="library" name="jsr305" level="project" />
<orderEntry type="module" module-name="testFramework" />
<orderEntry type="module" module-name="jps-builders" />
<orderEntry type="module" module-name="diff-impl" scope="TEST" />
</component>
</module>
@@ -15,6 +15,9 @@
*/
package com.intellij.testGuiFramework.tests.community
import com.intellij.diff.comparison.ComparisonPolicy
import com.intellij.diff.comparison.ComparisonUtil
import com.intellij.openapi.ui.MultiLineLabelUI
import com.intellij.openapi.util.text.StringUtil
import com.intellij.testGuiFramework.framework.RunWithIde
import com.intellij.testGuiFramework.impl.GuiTestCase
@@ -33,7 +36,8 @@ public class Main {
public static void main(String[] args) {
// write your code here
}
}"""
}
"""
@Test
fun testProjectCreate() {
@@ -62,8 +66,14 @@ public class Main {
moveTo(1)
}
val editorCode = editor.getCurrentFileContents(false)
assertTrue(StringUtil.convertLineSeparators(codeText) == StringUtil.convertLineSeparators(editorCode!!))
assertTrue(ComparisonUtil.isEquals(codeText.unifyCode(),
editorCode!!.unifyCode(),
ComparisonPolicy.TRIM_WHITESPACES))
closeProject()
}
}
fun String.unifyCode(): String =
MultiLineLabelUI.convertTabs(StringUtil.convertLineSeparators(this), 2)
}