Fix compileJavaAgainstKotlin tests
- Use another API to get file name out of a javac diagnostic (.getSource().getName()'s behavior changed in JDK 8) - Delete .txt files for those tests which check that javac reported a compilation error; the order and content of declarations in those files is undefined
This commit is contained in:
committed by
Dmitry Jemerov
parent
4edfd0d960
commit
3c96099f7c
@@ -1,13 +0,0 @@
|
||||
package test
|
||||
|
||||
public sealed class Season {
|
||||
private constructor Season()
|
||||
|
||||
public final class Cold : test.Season {
|
||||
public constructor Cold()
|
||||
}
|
||||
|
||||
public final class Warm : test.Season {
|
||||
public constructor Warm()
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package test
|
||||
|
||||
public sealed class Season {
|
||||
private constructor Season()
|
||||
|
||||
public final class Cold : test.Season {
|
||||
public constructor Cold()
|
||||
}
|
||||
|
||||
public final class Warm : test.Season {
|
||||
public constructor Warm()
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package test
|
||||
|
||||
@test.meta public/*package*/ final annotation class MyAnn : kotlin.Annotation {
|
||||
public/*package*/ constructor MyAnn()
|
||||
}
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.ANNOTATION_CLASS}) public final annotation class meta : kotlin.Annotation {
|
||||
public constructor meta()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package test
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CLASS}) public final annotation class classifier : kotlin.Annotation {
|
||||
public constructor classifier()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package test
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CONSTRUCTOR}) public final annotation class constructor : kotlin.Annotation {
|
||||
public constructor constructor()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package test
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {}) public final annotation class empty : kotlin.Annotation {
|
||||
public constructor empty()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package test
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.FIELD}) public final annotation class field : kotlin.Annotation {
|
||||
public constructor field()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package test
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.FUNCTION}) public final annotation class function : kotlin.Annotation {
|
||||
public constructor function()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package test
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.PROPERTY_GETTER}) public final annotation class getter : kotlin.Annotation {
|
||||
public constructor getter()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package test
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.LOCAL_VARIABLE}) public final annotation class local : kotlin.Annotation {
|
||||
public constructor local()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package test
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CLASS, AnnotationTarget.FUNCTION}) public final annotation class multiple : kotlin.Annotation {
|
||||
public constructor multiple()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package test
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.VALUE_PARAMETER}) public final annotation class parameter : kotlin.Annotation {
|
||||
public constructor parameter()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package test
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.PROPERTY}) public final annotation class property : kotlin.Annotation {
|
||||
public constructor property()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package test
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.PROPERTY_SETTER}) public final annotation class setter : kotlin.Annotation {
|
||||
public constructor setter()
|
||||
}
|
||||
@@ -552,7 +552,7 @@ public class KotlinTestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void compileKotlinWithJava(
|
||||
public static boolean compileKotlinWithJava(
|
||||
@NotNull List<File> javaFiles,
|
||||
@NotNull List<File> ktFiles,
|
||||
@NotNull File outDir,
|
||||
@@ -567,12 +567,12 @@ public class KotlinTestUtils {
|
||||
boolean mkdirs = outDir.mkdirs();
|
||||
assert mkdirs : "Not created: " + outDir;
|
||||
}
|
||||
if (!javaFiles.isEmpty()) {
|
||||
compileJavaFiles(javaFiles, Arrays.asList(
|
||||
"-classpath", outDir.getPath() + File.pathSeparator + ForTestCompileRuntime.runtimeJarForTests(),
|
||||
"-d", outDir.getPath()
|
||||
), javaErrorFile);
|
||||
}
|
||||
if (javaFiles.isEmpty()) return true;
|
||||
|
||||
return compileJavaFiles(javaFiles, Arrays.asList(
|
||||
"-classpath", outDir.getPath() + File.pathSeparator + ForTestCompileRuntime.runtimeJarForTests(),
|
||||
"-d", outDir.getPath()
|
||||
), javaErrorFile);
|
||||
}
|
||||
|
||||
public interface TestFileFactory<M, F> {
|
||||
@@ -802,11 +802,11 @@ public class KotlinTestUtils {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public static void compileJavaFiles(@NotNull Collection<File> files, List<String> options) throws IOException {
|
||||
compileJavaFiles(files, options, null);
|
||||
public static boolean compileJavaFiles(@NotNull Collection<File> files, List<String> options) throws IOException {
|
||||
return compileJavaFiles(files, options, null);
|
||||
}
|
||||
|
||||
public static void compileJavaFiles(@NotNull Collection<File> files, List<String> options, @Nullable File javaErrorFile) throws IOException {
|
||||
private static boolean compileJavaFiles(@NotNull Collection<File> files, List<String> options, @Nullable File javaErrorFile) throws IOException {
|
||||
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
|
||||
DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<JavaFileObject>();
|
||||
StandardJavaFileManager fileManager = javaCompiler.getStandardFileManager(diagnosticCollector, Locale.ENGLISH, Charset.forName("utf-8"));
|
||||
@@ -828,13 +828,14 @@ public class KotlinTestUtils {
|
||||
else {
|
||||
assertEqualsToFile(javaErrorFile, errorsToString(diagnosticCollector, false));
|
||||
}
|
||||
return success;
|
||||
} finally {
|
||||
fileManager.close();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String errorsToString(@NotNull DiagnosticCollector<JavaFileObject> diagnosticCollector, boolean humanReadable) {
|
||||
private static String errorsToString(@NotNull DiagnosticCollector<JavaFileObject> diagnosticCollector, boolean humanReadable) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (javax.tools.Diagnostic<? extends JavaFileObject> diagnostic : diagnosticCollector.getDiagnostics()) {
|
||||
if (diagnostic.getKind() != javax.tools.Diagnostic.Kind.ERROR) continue;
|
||||
@@ -843,7 +844,7 @@ public class KotlinTestUtils {
|
||||
builder.append(diagnostic).append("\n");
|
||||
}
|
||||
else {
|
||||
builder.append(diagnostic.getSource().getName()).append(":")
|
||||
builder.append(new File(diagnostic.getSource().toUri()).getName()).append(":")
|
||||
.append(diagnostic.getLineNumber()).append(":")
|
||||
.append(diagnostic.getColumnNumber()).append(":")
|
||||
.append(diagnostic.getCode()).append("\n");
|
||||
|
||||
+5
-3
@@ -65,12 +65,13 @@ public abstract class AbstractCompileJavaAgainstKotlinTest extends TestCaseWithT
|
||||
Assert.assertTrue(ktFilePath.endsWith(".kt"));
|
||||
File ktFile = new File(ktFilePath);
|
||||
File javaFile = new File(ktFilePath.replaceFirst("\\.kt$", ".java"));
|
||||
File expectedFile = new File(ktFilePath.replaceFirst("\\.kt$", ".txt"));
|
||||
File javaErrorFile = new File(ktFilePath.replaceFirst("\\.kt$", ".javaerr.txt"));
|
||||
|
||||
File out = new File(tmpdir, "out");
|
||||
compileKotlinWithJava(Collections.singletonList(javaFile), Collections.singletonList(ktFile),
|
||||
out, getTestRootDisposable(), javaErrorFile);
|
||||
boolean compiledSuccessfully =
|
||||
compileKotlinWithJava(Collections.singletonList(javaFile), Collections.singletonList(ktFile),
|
||||
out, getTestRootDisposable(), javaErrorFile);
|
||||
if (!compiledSuccessfully) return;
|
||||
|
||||
KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(
|
||||
getTestRootDisposable(),
|
||||
@@ -82,6 +83,7 @@ public abstract class AbstractCompileJavaAgainstKotlinTest extends TestCaseWithT
|
||||
PackageViewDescriptor packageView = analysisResult.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
|
||||
assertFalse("Nothing found in package " + LoadDescriptorUtil.TEST_PACKAGE_FQNAME, packageView.isEmpty());
|
||||
|
||||
File expectedFile = new File(ktFilePath.replaceFirst("\\.kt$", ".txt"));
|
||||
validateAndCompareDescriptorWithFile(packageView, CONFIGURATION, expectedFile);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user