-
Notifications
You must be signed in to change notification settings - Fork 543
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
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>
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.
I looked at this again and I want to address for 3.3.0.
I have option D for you: Since this is an oversight and strackTrace
can be truly null of t.getMessage()
is null
, we should not write non-sense or empty to type
, but leave it out. Rather no output than bad output. My proposal: Since we know that type
can be null, I can remove the requried
in the schema and bump to 3.1.0.
WDYT?
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.
I can remove the requried in the schema and bump to 3.1.0.
I like this idea. it is the easiest option to implement.
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.
Let me then prepare a PR with that change and you can build up on it.
I need to refresh my schema foo with https://www.xfront.com/SchemaVersioning.html and https://www.xfront.com/Versioning.pdf |
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.
@dr29bart All set, please rework your PR to option D.
…out a throwable This closes apache#716
@dr29bart I took the liberty to change your PR. |
...e-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporterTest.java
Outdated
Show resolved
Hide resolved
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.
For me, this is fine now. Are you OK as well?
yes, I am OK to merge. |
…iled result without a throwable This closes apache#716
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.