aboutsummaryrefslogtreecommitdiff
path: root/src/ant
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2021-03-23 06:01:50 +0100
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2021-03-23 06:01:50 +0100
commit3d7754e269ec84604d43be97a684bb26b519c6b9 (patch)
tree00f6a9e348b6cba0c025b46134ece5f86649f22f /src/ant
parentcc98adac012d0d18c70628eb5e6f1646ce574e8a (diff)
downloadlombok-3d7754e269ec84604d43be97a684bb26b519c6b9.tar.gz
lombok-3d7754e269ec84604d43be97a684bb26b519c6b9.tar.bz2
lombok-3d7754e269ec84604d43be97a684bb26b519c6b9.zip
[testing] wahey, ecj testing works again, and now we can test JDK16 features in it!
Diffstat (limited to 'src/ant')
-rw-r--r--src/ant/lombok/ant/SimpleTestFormatter.java122
1 files changed, 73 insertions, 49 deletions
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();
+ }
}