Provide sources of dependency in AbstractJavaWithLibCompletionTest
Test compiles dependency before running
This commit is contained in:
committed by
Pavel V. Talanov
parent
3bf32c09a9
commit
1072b1943f
Binary file not shown.
@@ -0,0 +1,9 @@
|
|||||||
|
package abc
|
||||||
|
|
||||||
|
public fun abcdAAA1(): Unit {}
|
||||||
|
|
||||||
|
public fun abcdBBB2(i: Int) {}
|
||||||
|
|
||||||
|
public fun Int.abcdCCC3() {}
|
||||||
|
|
||||||
|
public fun Int.abcdDDD4(i: Int) {}
|
||||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
|||||||
|
package abc
|
||||||
|
|
||||||
|
public fun abcdAAA1(): Unit {}
|
||||||
|
|
||||||
|
public fun abcdBBB2(i: Int) {}
|
||||||
|
|
||||||
|
public fun Int.abcdCCC3() {}
|
||||||
|
|
||||||
|
public fun Int.abcdDDD4(i: Int) {}
|
||||||
@@ -27,30 +27,31 @@ import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEdito
|
|||||||
import com.intellij.openapi.vfs.VfsUtil;
|
import com.intellij.openapi.vfs.VfsUtil;
|
||||||
import com.intellij.testFramework.LightProjectDescriptor;
|
import com.intellij.testFramework.LightProjectDescriptor;
|
||||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||||
|
import junit.framework.Assert;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.cli.common.ExitCode;
|
||||||
|
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
|
||||||
|
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
||||||
|
import org.jetbrains.jet.codegen.forTestCompile.ForTestPackJdkAnnotations;
|
||||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||||
import org.jetbrains.jet.plugin.project.TargetPlatform;
|
import org.jetbrains.jet.plugin.project.TargetPlatform;
|
||||||
import org.jetbrains.jet.testing.ConfigLibraryUtil;
|
import org.jetbrains.jet.testing.ConfigLibraryUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public abstract class AbstractJavaWithLibCompletionTest extends JetFixtureCompletionBaseTestCase {
|
public abstract class AbstractJavaWithLibCompletionTest extends JetFixtureCompletionBaseTestCase {
|
||||||
public void doTestWithJar(String testPath) {
|
public void doTestWithJar(String testPath) throws IOException {
|
||||||
|
|
||||||
|
File jarDependency = getOrCompileJarDependency(testPath);
|
||||||
|
assert jarDependency.exists() : "Library file should exist: " + jarDependency.getAbsolutePath();
|
||||||
NewLibraryEditor editor = new NewLibraryEditor();
|
NewLibraryEditor editor = new NewLibraryEditor();
|
||||||
editor.setName("doTestWithJarLib");
|
editor.setName("doTestWithJarLib");
|
||||||
|
editor.addRoot(VfsUtil.getUrlForLibraryRoot(jarDependency), OrderRootType.CLASSES);
|
||||||
File fullDirectoryPath = new File(testPath).getParentFile();
|
|
||||||
String jarLibName = getTestName(false) + ".jar";
|
|
||||||
|
|
||||||
File jarFile = new File(fullDirectoryPath, jarLibName);
|
|
||||||
assert jarFile.exists() : "Library file should exist: " + jarFile.getAbsolutePath();
|
|
||||||
|
|
||||||
editor.addRoot(VfsUtil.getUrlForLibraryRoot(jarFile), OrderRootType.CLASSES);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ConfigLibraryUtil.configureLibrary(myModule, getProjectDescriptor().getSdk(), editor);
|
ConfigLibraryUtil.configureLibrary(myModule, getProjectDescriptor().getSdk(), editor);
|
||||||
CodeInsightTestFixtureImpl.ensureIndexesUpToDate(getProject());
|
CodeInsightTestFixtureImpl.ensureIndexesUpToDate(getProject());
|
||||||
|
|
||||||
doTest(testPath);
|
doTest(testPath);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -83,4 +84,30 @@ public abstract class AbstractJavaWithLibCompletionTest extends JetFixtureComple
|
|||||||
public TargetPlatform getPlatform() {
|
public TargetPlatform getPlatform() {
|
||||||
return TargetPlatform.JVM;
|
return TargetPlatform.JVM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//NOTE: you can just delete existing jar to recompile data for tests that have kotlin dependency
|
||||||
|
@NotNull
|
||||||
|
private File getOrCompileJarDependency(@NotNull String testPath) throws IOException {
|
||||||
|
File fullDirectoryPath = new File(testPath).getParentFile();
|
||||||
|
String jarLibName = getTestName(false) + ".jar";
|
||||||
|
File jarFile = new File(fullDirectoryPath, jarLibName);
|
||||||
|
if (!jarFile.exists()) {
|
||||||
|
compileDependencySources(jarFile, fullDirectoryPath);
|
||||||
|
}
|
||||||
|
return jarFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void compileDependencySources(@NotNull File outputFile, @NotNull File fullDirectoryPath) {
|
||||||
|
File sourcesDir = new File(fullDirectoryPath, getTestName(true) + "Src");
|
||||||
|
File stdlib = ForTestCompileRuntime.runtimeJarForTests();
|
||||||
|
File jdkAnnotations = ForTestPackJdkAnnotations.jdkAnnotationsForTests();
|
||||||
|
ExitCode rv = new K2JVMCompiler().exec(System.out,
|
||||||
|
"-src", sourcesDir.getAbsolutePath(),
|
||||||
|
"-jar", outputFile.getAbsolutePath(),
|
||||||
|
"-noStdlib",
|
||||||
|
"-classpath", stdlib.getAbsolutePath(),
|
||||||
|
"-noJdkAnnotations",
|
||||||
|
"-annotations", jdkAnnotations.getAbsolutePath());
|
||||||
|
Assert.assertEquals("compilation completed with non-zero code: " + rv.getCode(), ExitCode.OK, rv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user