mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
sm runner: mark assertion errors without comparison as failures (other exceptions as errors)
This commit is contained in:
@@ -22,6 +22,9 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ComparisonFailureData {
|
||||
private static final String ASSERTION_CLASS_NAME = "java.lang.AssertionError";
|
||||
private static final String ASSERTION_FAILED_CLASS_NAME = "junit.framework.AssertionFailedError";
|
||||
|
||||
private final String myExpected;
|
||||
private final String myActual;
|
||||
private final String myFilePath;
|
||||
@@ -61,7 +64,8 @@ public class ComparisonFailureData {
|
||||
public static void registerSMAttributes(ComparisonFailureData notification,
|
||||
String trace,
|
||||
String failureMessage,
|
||||
Map attrs) {
|
||||
Map attrs,
|
||||
Throwable throwable) {
|
||||
|
||||
if (notification != null) {
|
||||
attrs.put("expected", notification.getExpected());
|
||||
@@ -77,11 +81,27 @@ public class ComparisonFailureData {
|
||||
}
|
||||
else {
|
||||
attrs.put("details", trace);
|
||||
attrs.put("error", "true");
|
||||
|
||||
Throwable throwableCause = null;
|
||||
try {
|
||||
throwableCause = throwable.getCause();
|
||||
}
|
||||
catch (Throwable ignored) {}
|
||||
|
||||
if (!isAssertionError(throwable.getClass()) && !isAssertionError(throwableCause != null ? throwableCause.getClass() : null)) {
|
||||
attrs.put("error", "true");
|
||||
}
|
||||
attrs.put("message", failureMessage != null ? failureMessage : "");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAssertionError(Class throwableClass) {
|
||||
if (throwableClass == null) return false;
|
||||
final String throwableClassName = throwableClass.getName();
|
||||
if (throwableClassName.equals(ASSERTION_CLASS_NAME) || throwableClassName.equals(ASSERTION_FAILED_CLASS_NAME)) return true;
|
||||
return isAssertionError(throwableClass.getSuperclass());
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return myFilePath;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.junit.runner.notification.RunListener;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.*;
|
||||
|
||||
public class JUnit4TestListener extends RunListener {
|
||||
@@ -132,14 +131,15 @@ public class JUnit4TestListener extends RunListener {
|
||||
attrs.put("name", JUnit4ReflectionUtil.getMethodName(failure.getDescription()));
|
||||
try {
|
||||
final String trace = failure.getTrace();
|
||||
final ComparisonFailureData notification = createExceptionNotification(failure.getException());
|
||||
ComparisonFailureData.registerSMAttributes(notification, trace, failure.getMessage(), attrs);
|
||||
final Throwable ex = failure.getException();
|
||||
final ComparisonFailureData notification = createExceptionNotification(ex);
|
||||
ComparisonFailureData.registerSMAttributes(notification, trace, failure.getMessage(), attrs, ex);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
final StringWriter stringWriter = new StringWriter();
|
||||
final PrintWriter writer = new PrintWriter(stringWriter);
|
||||
e.printStackTrace(writer);
|
||||
ComparisonFailureData.registerSMAttributes(null, stringWriter.toString(), e.getMessage(), attrs);
|
||||
ComparisonFailureData.registerSMAttributes(null, stringWriter.toString(), e.getMessage(), attrs, e);
|
||||
}
|
||||
finally {
|
||||
myPrintStream.println(ServiceMessage.asString(ServiceMessageTypes.TEST_FAILED, attrs));
|
||||
|
||||
@@ -33,8 +33,6 @@ import java.util.Set;
|
||||
public class JUnit4TestResultsSender extends RunListener {
|
||||
private static final String JUNIT_FRAMEWORK_COMPARISON_NAME = ComparisonFailure.class.getName();
|
||||
private static final String ORG_JUNIT_COMPARISON_NAME = "org.junit.ComparisonFailure";
|
||||
private static final String ASSERTION_CLASS_NAME = AssertionError.class.getName();
|
||||
private static final String ASSERTION_FAILED_CLASS_NAME = "junit.framework.AssertionFailedError";
|
||||
|
||||
private final OutputObjectRegistry myRegistry;
|
||||
private Map myCurrentTestMeters = new HashMap();
|
||||
@@ -49,7 +47,8 @@ public class JUnit4TestResultsSender extends RunListener {
|
||||
final Throwable throwable = failure.getException();
|
||||
|
||||
final Throwable cause = throwable.getCause();
|
||||
if (isAssertionError(throwable.getClass()) || isAssertionError(cause != null ? cause.getClass() : null)) {
|
||||
if (ComparisonFailureData.isAssertionError(throwable.getClass()) ||
|
||||
ComparisonFailureData.isAssertionError(cause != null ? cause.getClass() : null)) {
|
||||
// junit4 makes no distinction between errors and failures
|
||||
doAddFailure(description, throwable);
|
||||
}
|
||||
@@ -97,13 +96,6 @@ public class JUnit4TestResultsSender extends RunListener {
|
||||
return isComparisonFailure(aClass.getSuperclass());
|
||||
}
|
||||
|
||||
private static boolean isAssertionError(Class throwableClass) {
|
||||
if (throwableClass == null) return false;
|
||||
final String throwableClassName = throwableClass.getName();
|
||||
if (throwableClassName.equals(ASSERTION_CLASS_NAME) || throwableClassName.equals(ASSERTION_FAILED_CLASS_NAME)) return true;
|
||||
return isAssertionError(throwableClass.getSuperclass());
|
||||
}
|
||||
|
||||
private static PacketFactory createExceptionNotification(Throwable assertion) {
|
||||
if (assertion instanceof KnownException) return ((KnownException)assertion).getPacketFactory();
|
||||
final ComparisonFailureData notification = JUnit4TestListener.createExceptionNotification(assertion);
|
||||
|
||||
@@ -175,7 +175,7 @@ public class IDEATestNGRemoteListener implements ISuiteListener, IResultListener
|
||||
catch (Throwable e) {
|
||||
notification = null;
|
||||
}
|
||||
ComparisonFailureData.registerSMAttributes(notification, getTrace(ex), failureMessage, attrs);
|
||||
ComparisonFailureData.registerSMAttributes(notification, getTrace(ex), failureMessage, attrs, ex);
|
||||
myPrintStream.println(ServiceMessage.asString(ServiceMessageTypes.TEST_FAILED, attrs));
|
||||
onTestFinished(methodName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user