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 { public abstract class CodegenTestCase extends KtUsefulTestCase {
private static final String DEFAULT_TEST_FILE_NAME = "a_test"; 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 DEFAULT_JVM_TARGET = System.getProperty("kotlin.test.default.jvm.target");
private static final String JAVA_COMPILATION_TARGET = "kotlin.test.java.compilation.target"; public static final String BOX_IN_SEPARATE_PROCESS_PORT = System.getProperty("kotlin.test.box.in.separate.process.port");
private static final String RUN_BOX_TEST_IN_SEPARATE_PROCESS_PORT = "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 KotlinCoreEnvironment myEnvironment;
protected CodegenTestFiles myFiles; protected CodegenTestFiles myFiles;
@@ -91,9 +91,6 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
protected String coroutinesPackage = ""; protected String coroutinesPackage = "";
protected ConfigurationKind configurationKind = ConfigurationKind.JDK_ONLY; 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( protected final void createEnvironmentWithMockJdkAndIdeaAnnotations(
@NotNull ConfigurationKind configurationKind, @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); JvmTarget target = configuration.get(JVMConfigurationKeys.JVM_TARGET);
if (target == null && defaultJvmTarget != null) { if (target == null && DEFAULT_JVM_TARGET != null) {
JvmTarget value = JvmTarget.fromString(defaultJvmTarget); JvmTarget value = JvmTarget.fromString(DEFAULT_JVM_TARGET);
assert value != null : "Can't construct JvmTarget for " + defaultJvmTarget; assert value != null : "Can't construct JvmTarget for " + DEFAULT_JVM_TARGET;
configuration.put(JVMConfigurationKeys.JVM_TARGET, value); configuration.put(JVMConfigurationKeys.JVM_TARGET, value);
} }
} }
@@ -715,7 +712,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
} }
@NotNull @NotNull
protected List<String> extractJavacOptions(@NotNull List<TestFile> files) { protected static List<String> extractJavacOptions(@NotNull List<TestFile> files) {
List<String> javacOptions = new ArrayList<>(0); List<String> javacOptions = new ArrayList<>(0);
for (TestFile file : files) { for (TestFile file : files) {
javacOptions.addAll(InTextDirectivesUtils.findListWithPrefixes(file.content, "// JAVAC_OPTIONS:")); javacOptions.addAll(InTextDirectivesUtils.findListWithPrefixes(file.content, "// JAVAC_OPTIONS:"));
@@ -724,12 +721,12 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
return javacOptions; return javacOptions;
} }
private void updateJavacOptions(List<String> javacOptions) { private static void updateJavacOptions(@NotNull List<String> javacOptions) {
if (javaCompilationTarget != null && !javacOptions.contains("-target")) { if (JAVA_COMPILATION_TARGET != null && !javacOptions.contains("-target")) {
javacOptions.add("-source"); javacOptions.add("-source");
javacOptions.add(javaCompilationTarget); javacOptions.add(JAVA_COMPILATION_TARGET);
javacOptions.add("-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) protected void callBoxMethodAndCheckResult(URLClassLoader classLoader, Class<?> aClass, Method method)
throws IOException, IllegalAccessException, InvocationTargetException { throws IOException, IllegalAccessException, InvocationTargetException {
String result; String result;
if (boxInSeparateProcessPort != null) { if (BOX_IN_SEPARATE_PROCESS_PORT != null) {
result = invokeBoxInSeparateProcess(classLoader, aClass); result = invokeBoxInSeparateProcess(classLoader, aClass);
} }
else { else {
@@ -864,6 +861,6 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
classPath.add(0, outDir.toURI().toURL()); 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 package org.jetbrains.kotlin.codegen.jdk
import org.jetbrains.kotlin.codegen.* 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.RunOnlyJdk6Test
import org.jetbrains.kotlin.test.SuiteRunnerForCustomJdk import org.jetbrains.kotlin.test.SuiteRunnerForCustomJdk
import org.junit.AfterClass 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") System.getProperty("kotlin.test.box.in.separate.process.server.classpath") ?: System.getProperty("java.class.path")
println("Server classpath: $classpath") println("Server classpath: $classpath")
val port = System.getProperty(RUN_BOX_TEST_IN_SEPARATE_PROCESS_PORT) val port = BOX_IN_SEPARATE_PROCESS_PORT ?: error("kotlin.test.box.in.separate.process.port is not specified")
?: error("$RUN_BOX_TEST_IN_SEPARATE_PROCESS_PORT is not specified")
val builder = ProcessBuilder(executable, "-cp", classpath, main, port) val builder = ProcessBuilder(executable, "-cp", classpath, main, port)
builder.inheritIO() builder.inheritIO()