Fix tests in the gradle environment

This commit is contained in:
Ilya Chernikov
2017-08-02 12:28:56 +02:00
parent f053ed968f
commit 628927782a
11 changed files with 59 additions and 21 deletions
@@ -711,7 +711,19 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
result = invokeBoxInSeparateProcess(classLoader, aClass);
}
else {
result = (String) method.invoke(null);
ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader();
if (savedClassLoader != classLoader) {
// otherwise the test infrastructure used in the test may conflict with the one from the context classloader
Thread.currentThread().setContextClassLoader(classLoader);
}
try {
result = (String) method.invoke(null);
}
finally {
if (savedClassLoader != classLoader) {
Thread.currentThread().setContextClassLoader(savedClassLoader);
}
}
}
assertEquals("OK", result);
}
@@ -75,7 +75,8 @@ public class ForTestCompileRuntime {
@NotNull
@Deprecated
public static File[] runtimeClassesForTests() {
return new File[] { assertExists(new File("dist/builtins")), assertExists(new File("libraries/stdlib/build/classes/builtins")), assertExists(new File("libraries/stdlib/build/classes/main")) };
// TODO: replace hardcoded path with something flexible
return new File[] { assertExists(new File("dist/builtins")), assertExists(new File("build/kotlin-stdlib/classes/java/builtins")), assertExists(new File("build/kotlin-stdlib/classes/java/main")) };
}
@NotNull
@@ -16,9 +16,13 @@
package org.jetbrains.kotlin.jvm.runtime
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.checkers.KotlinMultiFileTestWithJava
import org.jetbrains.kotlin.codegen.GenerationUtils
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.jetbrains.kotlin.config.ContentRoot
import org.jetbrains.kotlin.config.JVMConfigurationKeys
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
@@ -133,6 +137,9 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
val environment = KotlinTestUtils.createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(
myTestRootDisposable, ConfigurationKind.ALL, jdkKind
)
for (root in environment.configuration.getList(JVMConfigurationKeys.CONTENT_ROOTS)) {
LOG.info("root: " + root.toString())
}
val ktFile = KotlinTestUtils.createFile(file.path, text, environment.project)
GenerationUtils.compileFileTo(ktFile, environment, tmpdir)
}
@@ -247,3 +254,5 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
}
}
private val LOG = Logger.getInstance(KotlinMultiFileTestWithJava::class.java)
@@ -345,7 +345,8 @@ public class KotlinTestUtils {
@NotNull
public static String getHomeDirectory() {
File resourceRoot = PathUtil.getResourcePathForClass(KotlinTestUtils.class);
return FileUtil.toSystemIndependentName(resourceRoot.getParentFile().getParentFile().getParent());
// TODO: very fragile logic, consider more robust home dir detection
return FileUtil.toSystemIndependentName(resourceRoot.getParentFile().getParentFile().getParentFile().getParent());
}
public static File findMockJdkRtJar() {
@@ -20,6 +20,7 @@ import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.impl.ApplicationInfoImpl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.io.FileSystemUtil;
@@ -27,6 +28,7 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.rt.execution.junit.FileComparisonFailure;
import com.intellij.testFramework.TestLoggerFactory;
import com.intellij.util.ReflectionUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.hash.HashMap;
@@ -61,6 +63,10 @@ public abstract class KtUsefulTestCase extends TestCase {
private Application application;
static {
Logger.setFactory(TestLoggerFactory.class);
}
@NotNull
protected final Disposable myTestRootDisposable = new TestDisposable();
@@ -243,8 +249,10 @@ public abstract class KtUsefulTestCase extends TestCase {
logPerClassCost(setupCost, TOTAL_SETUP_COST_MILLIS);
runTest();
TestLoggerFactory.onTestFinished(true);
}
catch (Throwable running) {
TestLoggerFactory.onTestFinished(false);
exception = running;
}
finally {