Minor, refactor system properties in CodegenTestCase

This commit is contained in:
Alexander Udalov
2019-04-03 17:51:01 +02:00
parent b602c08773
commit e191eef10a
2 changed files with 17 additions and 21 deletions
@@ -78,9 +78,9 @@ import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getGene
public abstract class CodegenTestCase extends KtUsefulTestCase {
private static final String DEFAULT_TEST_FILE_NAME = "a_test";
private static final String DEFAULT_JVM_TARGET_FOR_TEST = "kotlin.test.default.jvm.target";
private static final String JAVA_COMPILATION_TARGET = "kotlin.test.java.compilation.target";
private static final String RUN_BOX_TEST_IN_SEPARATE_PROCESS_PORT = "kotlin.test.box.in.separate.process.port";
private static final String DEFAULT_JVM_TARGET = System.getProperty("kotlin.test.default.jvm.target");
public static final String BOX_IN_SEPARATE_PROCESS_PORT = System.getProperty("kotlin.test.box.in.separate.process.port");
private static final String JAVA_COMPILATION_TARGET = System.getProperty("kotlin.test.java.compilation.target");
protected KotlinCoreEnvironment myEnvironment;
protected CodegenTestFiles myFiles;
@@ -91,9 +91,6 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
protected String coroutinesPackage = "";
protected ConfigurationKind configurationKind = ConfigurationKind.JDK_ONLY;
private final String defaultJvmTarget = System.getProperty(DEFAULT_JVM_TARGET_FOR_TEST);
private final String boxInSeparateProcessPort = System.getProperty(RUN_BOX_TEST_IN_SEPARATE_PROCESS_PORT);
private final String javaCompilationTarget = System.getProperty(JAVA_COMPILATION_TARGET);
protected final void createEnvironmentWithMockJdkAndIdeaAnnotations(
@NotNull ConfigurationKind configurationKind,
@@ -626,11 +623,11 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
}
private void setCustomDefaultJvmTarget(CompilerConfiguration configuration) {
private static void setCustomDefaultJvmTarget(CompilerConfiguration configuration) {
JvmTarget target = configuration.get(JVMConfigurationKeys.JVM_TARGET);
if (target == null && defaultJvmTarget != null) {
JvmTarget value = JvmTarget.fromString(defaultJvmTarget);
assert value != null : "Can't construct JvmTarget for " + defaultJvmTarget;
if (target == null && DEFAULT_JVM_TARGET != null) {
JvmTarget value = JvmTarget.fromString(DEFAULT_JVM_TARGET);
assert value != null : "Can't construct JvmTarget for " + DEFAULT_JVM_TARGET;
configuration.put(JVMConfigurationKeys.JVM_TARGET, value);
}
}
@@ -715,7 +712,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
}
@NotNull
protected List<String> extractJavacOptions(@NotNull List<TestFile> files) {
protected static List<String> extractJavacOptions(@NotNull List<TestFile> files) {
List<String> javacOptions = new ArrayList<>(0);
for (TestFile file : files) {
javacOptions.addAll(InTextDirectivesUtils.findListWithPrefixes(file.content, "// JAVAC_OPTIONS:"));
@@ -724,12 +721,12 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
return javacOptions;
}
private void updateJavacOptions(List<String> javacOptions) {
if (javaCompilationTarget != null && !javacOptions.contains("-target")) {
private static void updateJavacOptions(@NotNull List<String> javacOptions) {
if (JAVA_COMPILATION_TARGET != null && !javacOptions.contains("-target")) {
javacOptions.add("-source");
javacOptions.add(javaCompilationTarget);
javacOptions.add(JAVA_COMPILATION_TARGET);
javacOptions.add("-target");
javacOptions.add(javaCompilationTarget);
javacOptions.add(JAVA_COMPILATION_TARGET);
}
}
@@ -832,7 +829,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
protected void callBoxMethodAndCheckResult(URLClassLoader classLoader, Class<?> aClass, Method method)
throws IOException, IllegalAccessException, InvocationTargetException {
String result;
if (boxInSeparateProcessPort != null) {
if (BOX_IN_SEPARATE_PROCESS_PORT != null) {
result = invokeBoxInSeparateProcess(classLoader, aClass);
}
else {
@@ -864,6 +861,6 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
classPath.add(0, outDir.toURI().toURL());
}
return new TestProxy(Integer.valueOf(boxInSeparateProcessPort), aClass.getCanonicalName(), classPath).runTest();
return new TestProxy(Integer.valueOf(BOX_IN_SEPARATE_PROCESS_PORT), aClass.getCanonicalName(), classPath).runTest();
}
}
@@ -6,7 +6,7 @@
package org.jetbrains.kotlin.codegen.jdk
import org.jetbrains.kotlin.codegen.*
import org.jetbrains.kotlin.codegen.CodegenTestCase.RUN_BOX_TEST_IN_SEPARATE_PROCESS_PORT
import org.jetbrains.kotlin.codegen.CodegenTestCase.BOX_IN_SEPARATE_PROCESS_PORT
import org.jetbrains.kotlin.test.RunOnlyJdk6Test
import org.jetbrains.kotlin.test.SuiteRunnerForCustomJdk
import org.junit.AfterClass
@@ -49,8 +49,7 @@ class JvmTarget6OnJvm6 : CustomJvmTargetOnJvmBaseTest() {
System.getProperty("kotlin.test.box.in.separate.process.server.classpath") ?: System.getProperty("java.class.path")
println("Server classpath: $classpath")
val port = System.getProperty(RUN_BOX_TEST_IN_SEPARATE_PROCESS_PORT)
?: error("$RUN_BOX_TEST_IN_SEPARATE_PROCESS_PORT is not specified")
val port = BOX_IN_SEPARATE_PROCESS_PORT ?: error("kotlin.test.box.in.separate.process.port is not specified")
val builder = ProcessBuilder(executable, "-cp", classpath, main, port)
builder.inheritIO()
@@ -94,4 +93,4 @@ class JvmTarget9OnJvm9 : CustomJvmTargetOnJvmBaseTest()
class JvmTarget6OnJvmLast : CustomJvmTargetOnJvmBaseTest()
@RunWith(SuiteRunnerForCustomJdk::class)
class JvmTarget8OnJvmLast : CustomJvmTargetOnJvmBaseTest()
class JvmTarget8OnJvmLast : CustomJvmTargetOnJvmBaseTest()