Proper message reporting
This commit is contained in:
@@ -55,6 +55,7 @@ import org.junit.Assert;
|
|||||||
import javax.tools.*;
|
import javax.tools.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -369,17 +370,35 @@ public class JetTestUtils {
|
|||||||
|
|
||||||
public static void compileJavaFiles(@NotNull Collection<File> files, List<String> options) throws IOException {
|
public static void compileJavaFiles(@NotNull Collection<File> files, List<String> options) throws IOException {
|
||||||
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
|
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
|
||||||
StandardJavaFileManager fileManager = javaCompiler.getStandardFileManager(null, Locale.ENGLISH, Charset.forName("utf-8"));
|
DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<JavaFileObject>();
|
||||||
|
StandardJavaFileManager fileManager = javaCompiler.getStandardFileManager(diagnosticCollector, Locale.ENGLISH, Charset.forName("utf-8"));
|
||||||
try {
|
try {
|
||||||
Iterable<? extends JavaFileObject> javaFileObjectsFromFiles = fileManager.getJavaFileObjectsFromFiles(files);
|
Iterable<? extends JavaFileObject> javaFileObjectsFromFiles = fileManager.getJavaFileObjectsFromFiles(files);
|
||||||
JavaCompiler.CompilationTask task = javaCompiler.getTask(null, fileManager, null, options, null, javaFileObjectsFromFiles);
|
|
||||||
|
|
||||||
Assert.assertTrue(task.call());
|
JavaCompiler.CompilationTask task = javaCompiler.getTask(
|
||||||
|
new StringWriter(), // do not write to System.err
|
||||||
|
fileManager,
|
||||||
|
diagnosticCollector,
|
||||||
|
options,
|
||||||
|
null,
|
||||||
|
javaFileObjectsFromFiles);
|
||||||
|
|
||||||
|
Assert.assertTrue(errorsToString(diagnosticCollector), task.call());
|
||||||
} finally {
|
} finally {
|
||||||
fileManager.close();
|
fileManager.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String errorsToString(DiagnosticCollector<JavaFileObject> diagnosticCollector) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (javax.tools.Diagnostic<? extends JavaFileObject> diagnostic : diagnosticCollector.getDiagnostics()) {
|
||||||
|
if (diagnostic.getKind() == javax.tools.Diagnostic.Kind.ERROR) {
|
||||||
|
builder.append(diagnostic).append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public static void assertAllTestsPresentByMetadata(
|
public static void assertAllTestsPresentByMetadata(
|
||||||
@NotNull Class<?> testCaseClass,
|
@NotNull Class<?> testCaseClass,
|
||||||
@NotNull String generatorClassFqName,
|
@NotNull String generatorClassFqName,
|
||||||
|
|||||||
Reference in New Issue
Block a user