diff --git a/compiler/tests/org/jetbrains/jet/JetTestUtils.java b/compiler/tests/org/jetbrains/jet/JetTestUtils.java index 72e693a1aa0..790114813a5 100644 --- a/compiler/tests/org/jetbrains/jet/JetTestUtils.java +++ b/compiler/tests/org/jetbrains/jet/JetTestUtils.java @@ -55,6 +55,7 @@ import org.junit.Assert; import javax.tools.*; import java.io.File; import java.io.IOException; +import java.io.StringWriter; import java.lang.reflect.Method; import java.nio.charset.Charset; import java.util.*; @@ -369,17 +370,35 @@ public class JetTestUtils { public static void compileJavaFiles(@NotNull Collection files, List options) throws IOException { JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler(); - StandardJavaFileManager fileManager = javaCompiler.getStandardFileManager(null, Locale.ENGLISH, Charset.forName("utf-8")); + DiagnosticCollector diagnosticCollector = new DiagnosticCollector(); + StandardJavaFileManager fileManager = javaCompiler.getStandardFileManager(diagnosticCollector, Locale.ENGLISH, Charset.forName("utf-8")); try { Iterable 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 { fileManager.close(); } } + private static String errorsToString(DiagnosticCollector diagnosticCollector) { + StringBuilder builder = new StringBuilder(); + for (javax.tools.Diagnostic diagnostic : diagnosticCollector.getDiagnostics()) { + if (diagnostic.getKind() == javax.tools.Diagnostic.Kind.ERROR) { + builder.append(diagnostic).append("\n"); + } + } + return builder.toString(); + } + public static void assertAllTestsPresentByMetadata( @NotNull Class testCaseClass, @NotNull String generatorClassFqName,