Test classpath order of sources vs library dependencies
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package test
|
||||
|
||||
import kotlin.jvm.internal.KObject
|
||||
import kotlin.jvm.internal.Intrinsics
|
||||
|
||||
fun foo(): String {
|
||||
// This method call should be resolved to kotlin-runtime.jar
|
||||
val r: String = Intrinsics.stringPlus(":", ")")
|
||||
|
||||
// This method call should be resolved to sources
|
||||
return KObject.methodWhichDoesNotExistInKotlinRuntime()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package kotlin.jvm.internal;
|
||||
|
||||
public class KObject {
|
||||
public static String methodWhichDoesNotExistInKotlinRuntime() {
|
||||
return ":)";
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.test;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.io.ZipUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode;
|
||||
@@ -96,23 +97,14 @@ public class MockLibraryUtil {
|
||||
}
|
||||
|
||||
// Runs compiler in custom class loader to avoid effects caused by replacing Application with another one created in compiler.
|
||||
public static void compileKotlin(@NotNull String sourcesPath, @NotNull File outDir, @NotNull String... extraClasspath) {
|
||||
private static void runCompiler(@NotNull List<String> args) {
|
||||
try {
|
||||
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||
Class<?> compilerClass = getCompilerClass();
|
||||
Object compilerObject = compilerClass.newInstance();
|
||||
Object compiler = compilerClass.newInstance();
|
||||
Method execMethod = compilerClass.getMethod("exec", PrintStream.class, String[].class);
|
||||
|
||||
List<String> classpath = new ArrayList<String>();
|
||||
classpath.add(sourcesPath);
|
||||
Collections.addAll(classpath, extraClasspath);
|
||||
String newClasspath = StringUtil.join(classpath, File.pathSeparator);
|
||||
|
||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||
Enum<?> invocationResult = (Enum<?>) execMethod.invoke(
|
||||
compilerObject, new PrintStream(outStream),
|
||||
new String[] {sourcesPath, "-d", outDir.getAbsolutePath(), "-classpath", newClasspath}
|
||||
);
|
||||
Enum<?> invocationResult = (Enum<?>) execMethod.invoke(compiler, new PrintStream(outStream), ArrayUtil.toStringArray(args));
|
||||
|
||||
assertEquals(new String(outStream.toByteArray()), ExitCode.OK.name(), invocationResult.name());
|
||||
}
|
||||
@@ -121,6 +113,25 @@ public class MockLibraryUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void compileKotlin(@NotNull String sourcesPath, @NotNull File outDir, @NotNull String... extraClasspath) {
|
||||
List<String> classpath = new ArrayList<String>();
|
||||
classpath.add(sourcesPath);
|
||||
Collections.addAll(classpath, extraClasspath);
|
||||
|
||||
List<String> args = new ArrayList<String>();
|
||||
args.add(sourcesPath);
|
||||
args.add("-d");
|
||||
args.add(outDir.getAbsolutePath());
|
||||
args.add("-classpath");
|
||||
args.add(StringUtil.join(classpath, File.pathSeparator));
|
||||
|
||||
runCompiler(args);
|
||||
}
|
||||
|
||||
public static void compileKotlinModule(@NotNull String modulePath) {
|
||||
runCompiler(Arrays.asList("-no-stdlib", "-module", modulePath));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static synchronized Class<?> getCompilerClass() throws IOException, ClassNotFoundException {
|
||||
Class<?> compilerClass = compilerClassRef.get();
|
||||
|
||||
Reference in New Issue
Block a user