New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SUREFIRE-2232] StatelessXmlReporter: handle failed test result without a throwable #716
base: master
Are you sure you want to change the base?
Conversation
ppw.addAttribute("type", new StringTokenizer(stackTrace).nextToken()); | ||
ppw.addAttribute( | ||
"type", | ||
isBlank(stackTrace) ? "UndefinedException" : new StringTokenizer(stackTrace).nextToken()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you reuse the approach from line 451?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean indexOf
approach or to use value as is
?
I didn't want to leave a chance for type
to be null. What non-null value can be used here?
The stackTrace
StatelessXmlReporter#439 var may be null:
public String getStackTrace(boolean trimStackTrace) {
StackTraceWriter w = original.getStackTraceWriter();
return w == null ? null : (trimStackTrace ? w.writeTrimmedTraceToString() : w.writeTraceToString());
}
At the same time surefire's XSD requires type
XSD
<xs:element name="error" nillable="true" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="message" type="xs:string"/>
<xs:attribute name="type" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
The goal is to handle stack traces like:
// has message
junit.framework.ComparisonFailure:
Expected :fail at foo
Actual :faild at foo
// does not have message
java.lang.AssertionError
at org.junit.Assert.fail(Assert.java:87)
at org.junit.Assert.fail(Assert.java:96)
// or stack trace is missing (empty String)
Please, let me know if this alternative is more preferable:
Option A
if (report.getStackTraceWriter() != null) {
//noinspection ThrowableResultOfMethodCallIgnored
SafeThrowable t = report.getStackTraceWriter().getThrowable();
if (t != null) {
int delimiter = StringUtils.indexOfAny(stackTrace, ":", "\t", "\n", "\r", "\f");
String type = delimiter == -1 ? stackTrace : stackTrace.substring(0, delimiter);
ppw.addAttribute("type", Objects.toString(type, "UndefinedException"));
}
}
Option B
SafeThrowable t = report.getStackTraceWriter().getThrowable();
if (t != null) {
if (t.getMessage() != null) {
int delimiter = stackTrace.indexOf(":");
String type = delimiter == -1 ? stackTrace : stackTrace.substring(0, delimiter);
ppw.addAttribute("type", type);
} else {
ppw.addAttribute(
"type",
isBlank(stackTrace) ? stackTrace : new StringTokenizer(stackTrace).nextToken());
}
}
Option C
SafeThrowable t = report.getStackTraceWriter().getThrowable();
if (t != null) {
if (t.getMessage() != null) {
int delimiter = stackTrace.indexOf(":");
String type = delimiter == -1 ? stackTrace : stackTrace.substring(0, delimiter);
ppw.addAttribute("type", type);
} else {
int delimiter = StringUtils.indexOfAny(stackTrace, "\t", "\n", "\r", "\f");
String type = delimiter == -1 ? stackTrace : stackTrace.substring(0, delimiter);
ppw.addAttribute("type", type);
}
}
</details>
The fix is to set a hardcoded value -
UndefinedException
aserror type
in case stack trace is empty.checklist
Following this checklist to help us incorporate your contribution quickly and easily:for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without
pulling in other changes.
[SUREFIRE-XXX] - Fixes bug in ApproximateQuantiles
,where you replace
SUREFIRE-XXX
with the appropriate JIRA issue. Best practiceis to use the JIRA issue title in the pull request title and in the first line of the
commit message.
mvn clean install
to make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
mvn -Prun-its clean install
).If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.