From 3d7754e269ec84604d43be97a684bb26b519c6b9 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 23 Mar 2021 06:01:50 +0100 Subject: [testing] wahey, ecj testing works again, and now we can test JDK16 features in it! --- buildScripts/ivy.xml | 2 + buildScripts/tests.ant.xml | 39 +++++++- src/ant/lombok/ant/SimpleTestFormatter.java | 122 ++++++++++++++---------- test/core/src/lombok/RunTestsViaEcj.java | 11 ++- test/stubs/java/lang/Record.java | 3 + test/stubs/java/lang/runtime/ObjectMethods.java | 12 +++ 6 files changed, 134 insertions(+), 55 deletions(-) create mode 100644 test/stubs/java/lang/Record.java create mode 100644 test/stubs/java/lang/runtime/ObjectMethods.java diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml index da46ab91..0da5c3fc 100644 --- a/buildScripts/ivy.xml +++ b/buildScripts/ivy.xml @@ -28,6 +28,7 @@ + @@ -76,6 +77,7 @@ + diff --git a/buildScripts/tests.ant.xml b/buildScripts/tests.ant.xml index 4cd36b9e..9d9e9541 100644 --- a/buildScripts/tests.ant.xml +++ b/buildScripts/tests.ant.xml @@ -55,7 +55,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn - + @@ -165,6 +165,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn + @@ -179,6 +180,42 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn + + + + Running TestEclipse on ecj-@{version} on JVM${ant.java.version}. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ant/lombok/ant/SimpleTestFormatter.java b/src/ant/lombok/ant/SimpleTestFormatter.java index a2a38420..e137d822 100644 --- a/src/ant/lombok/ant/SimpleTestFormatter.java +++ b/src/ant/lombok/ant/SimpleTestFormatter.java @@ -2,6 +2,7 @@ package lombok.ant; import java.io.OutputStream; import java.io.PrintStream; +import java.util.Arrays; import junit.framework.AssertionFailedError; import junit.framework.Test; @@ -11,53 +12,76 @@ import org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter; import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest; public class SimpleTestFormatter implements JUnitResultFormatter { - private PrintStream out = System.out; - - @Override - public void addError(Test test, Throwable error) { - logResult(test, "ERR"); - out.println(error.getMessage()); - } - - @Override - public void addFailure(Test test, AssertionFailedError failure) { - logResult(test, "FAIL"); - out.println(failure.getMessage()); - } - - @Override - public void endTest(Test test) { - logResult(test, "PASS"); - } - - @Override - public void startTest(Test test) { } - - @Override - public void endTestSuite(JUnitTest testSuite) throws BuildException { } - - @Override - public void setOutput(OutputStream out) { - this.out = new PrintStream(out); - } - - @Override - public void setSystemError(String msg) { - if (msg.trim().isEmpty()) return; - out.println(msg); - } - - @Override - public void setSystemOutput(String msg) { - if (msg.trim().isEmpty()) return; - out.println(msg); - } - - @Override - public void startTestSuite(JUnitTest testSuite) throws BuildException { } - - private void logResult(Test test, String result) { - out.println("[" + result + "] " + String.valueOf(test)); - out.flush(); - } + private PrintStream out = System.out; + private Test lastMarked = null; + + @Override + public void addError(Test test, Throwable error) { + lastMarked = test; + logResult(test, "ERR"); + printThrowable(error, false, 2); + } + + private void printThrowable(Throwable throwable, boolean cause, int indent) { + String msg = throwable.getMessage(); + char[] prefixChars = new char[indent]; + Arrays.fill(prefixChars, ' '); + String prefix = new String(prefixChars); + + if (msg == null || msg.isEmpty()) { + out.println(prefix + (cause ? "Caused by " : "") + throwable.getClass()); + } else { + out.println(prefix + (cause ? "Caused by " : "") + throwable.getClass() + ": " + msg); + } + StackTraceElement[] elems = throwable.getStackTrace(); + if (elems != null) for (StackTraceElement elem : elems) { + out.println(prefix + " " + elem); + } + + Throwable c = throwable.getCause(); + if (c != null) printThrowable(c, true, indent + 2); + } + + @Override + public void addFailure(Test test, AssertionFailedError failure) { + lastMarked = test; + logResult(test, "FAIL"); + out.println(failure.getMessage()); + } + + @Override + public void endTest(Test test) { + if (test != lastMarked) logResult(test, "PASS"); + } + + @Override + public void startTest(Test test) { } + + @Override + public void endTestSuite(JUnitTest testSuite) throws BuildException { } + + @Override + public void setOutput(OutputStream out) { + this.out = new PrintStream(out); + } + + @Override + public void setSystemError(String msg) { + if (msg.trim().isEmpty()) return; + out.println(msg); + } + + @Override + public void setSystemOutput(String msg) { + if (msg.trim().isEmpty()) return; + out.println(msg); + } + + @Override + public void startTestSuite(JUnitTest testSuite) throws BuildException { } + + private void logResult(Test test, String result) { + out.println("[" + result + "] " + String.valueOf(test)); + out.flush(); + } } diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index 1c2be160..2e89f99b 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -110,6 +110,11 @@ public class RunTestsViaEcj extends AbstractRunTests { }; } + private ICompilationUnit getSourceUnit(File file, String source) { + if (eclipseAvailable()) return new TestCompilationUnitEclipse(file.getName(), source); + return new TestCompilationUnitEcj(file.getName(), source); + } + @Override public boolean transformCode(Collection messages, StringWriter result, File file, String encoding, Map formatPreferences, int minVersion, boolean checkPositions) throws Throwable { final AtomicReference compilationResult_ = new AtomicReference(); @@ -124,11 +129,7 @@ public class RunTestsViaEcj extends AbstractRunTests { char[] sourceArray = source.toCharArray(); final ICompilationUnit sourceUnit; try { - if (eclipseAvailable()) { - sourceUnit = new TestCompilationUnitEclipse(file.getName(), source); - } else { - sourceUnit = new TestCompilationUnitEcj(file.getName(), source); - } + sourceUnit = getSourceUnit(file, source); } catch (Throwable t) { t.printStackTrace(); return false; diff --git a/test/stubs/java/lang/Record.java b/test/stubs/java/lang/Record.java new file mode 100644 index 00000000..e985bb45 --- /dev/null +++ b/test/stubs/java/lang/Record.java @@ -0,0 +1,3 @@ +package java.lang; + +public abstract class Record {} diff --git a/test/stubs/java/lang/runtime/ObjectMethods.java b/test/stubs/java/lang/runtime/ObjectMethods.java new file mode 100644 index 00000000..519563ae --- /dev/null +++ b/test/stubs/java/lang/runtime/ObjectMethods.java @@ -0,0 +1,12 @@ +package java.lang.runtime; + +// import java.lang.invoke.MethodHandle; +// import java.lang.invoke.MethodHandles; +// import java.lang.invoke.TypeDescriptor; + +public class ObjectMethods { +// public static Object bootstrap(MethodHandles.Lookup lookup, String methodName, TypeDescriptor type, Class recordClass, String names, MethodHandle... getters) throws Throwable { + public static Object bootstrap(Object lookup, String methodName, Object type, Class recordClass, String names, Object... getters) throws Throwable { + return null; + } +} -- cgit