Fix IDE related test problems after adding ability to run test in parallel in compiler configuration

This commit is contained in:
Mikhael Bogdanov
2019-03-26 15:30:42 +01:00
parent 0c60ff0e80
commit f34a2923b5
4 changed files with 29 additions and 8 deletions
@@ -426,6 +426,13 @@ public class KotlinTestUtils {
return normalizeFile(FileUtil.createTempDirectory(name, "", false));
}
@NotNull
public static File tmpDirForReusableLibrary(String name) throws IOException {
File answer = normalizeFile(FileUtil.createTempDirectory(new File(System.getProperty("java.io.tmpdir")), name, ""));
deleteOnShutdown(answer);
return answer;
}
private static File normalizeFile(File file) throws IOException {
// Get canonical file to be sure that it's the same as inside the compiler,
// for example, on Windows, if a canonical path contains any space from FileUtil.createTempDirectory we will get
@@ -433,6 +440,18 @@ public class KotlinTestUtils {
return file.getCanonicalFile();
}
private static void deleteOnShutdown(File file) {
if (filesToDelete.isEmpty()) {
ShutDownTracker.getInstance().registerShutdownTask(() -> {
for (File victim : filesToDelete) {
FileUtil.delete(victim);
}
});
}
filesToDelete.add(file);
}
@NotNull
public static KtFile createFile(@NotNull @NonNls String name, @NotNull String text, @NotNull Project project) {
String shortName = name.substring(name.lastIndexOf('/') + 1);
@@ -410,9 +410,7 @@ public class KotlinTestUtils {
@NotNull
public static File tmpDirForTest(@NotNull String testClassName, @NotNull String testName) throws IOException {
File answer = normalizeFile(FileUtil.createTempDirectory(testClassName, testName));
deleteOnShutdown(answer);
return answer;
return normalizeFile(FileUtil.createTempDirectory(testClassName, testName, false));
}
@NotNull
@@ -422,7 +420,11 @@ public class KotlinTestUtils {
@NotNull
public static File tmpDir(String name) throws IOException {
// We should use this form. otherwise directory will be deleted on each test.
return normalizeFile(FileUtil.createTempDirectory(name, "", false));
}
@NotNull
public static File tmpDirForReusableLibrary(String name) throws IOException {
File answer = normalizeFile(FileUtil.createTempDirectory(new File(System.getProperty("java.io.tmpdir")), name, ""));
deleteOnShutdown(answer);
return answer;
@@ -52,8 +52,8 @@ object MockLibraryUtil {
useJava9: Boolean = false
): File {
return compileLibraryToJar(
sourcesPath, KotlinTestUtils.tmpDir("testLibrary-" + jarName), jarName, addSources,allowKotlinSources, extraOptions, extraClasspath
, useJava9)}
sourcesPath, KotlinTestUtils.tmpDirForReusableLibrary("testLibrary-" + jarName), jarName, addSources, allowKotlinSources, extraOptions, extraClasspath
, useJava9)}
@JvmStatic
@JvmOverloads
@@ -127,7 +127,7 @@ object MockLibraryUtil {
@JvmStatic
fun compileJsLibraryToJar(sourcesPath: String, jarName: String, addSources: Boolean, extraOptions: List<String> = emptyList()): File {
val contentDir = KotlinTestUtils.tmpDir("testLibrary-" + jarName)
val contentDir = KotlinTestUtils.tmpDirForReusableLibrary("testLibrary-" + jarName)
val outDir = File(contentDir, "out")
val outputFile = File(outDir, jarName + ".js")
@@ -181,7 +181,7 @@ abstract class AbstractScriptConfigurationTest : KotlinCompletionTestCase() {
}
if (configureConflictingModule in environment) {
val sharedLib = LocalFileSystem.getInstance().findFileByIoFile(environment["lib-classes"] as File)!!
val sharedLib = VfsUtil.findFileByIoFile(environment["lib-classes"] as File, true)!!
if (module == null) {
myModule = createTestModuleByName("mainModule")
}