olamy commented on code in PR #3489:
URL: https://github.com/apache/maven-surefire/pull/3489#discussion_r4335018367
##########
surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/LauncherAdapter.java:
##########
@@ -57,15 +66,44 @@ void execute(LauncherDiscoveryRequest discoveryRequest,
TestExecutionListener...
void executeWithoutCancellationToken(
LauncherDiscoveryRequest discoveryRequest,
TestExecutionListener... listeners) {
- delegate.execute(discoveryRequest, listeners);
+ try {
+ delegate.execute(discoveryRequest, listeners);
+ } catch (JUnitException e) {
+ throw withRootCauseMessage(e);
+ }
}
private void executeWithCancellationToken(
LauncherDiscoveryRequest discoveryRequest,
TestExecutionListener... listeners) {
Method executeMethod =
requireNonNull(EXECUTE_METHOD_WITH_LAUNCHER_EXECUTION_REQUEST_PARAMETER);
Object executionRequest = createExecutionRequest(discoveryRequest,
listeners);
- ReflectionUtils.invokeMethodWithArray(delegate, executeMethod,
executionRequest);
+ try {
+ ReflectionUtils.invokeMethodWithArray(delegate, executeMethod,
executionRequest);
+ } catch (JUnitException e) {
+ throw withRootCauseMessage(e);
+ } catch (SurefireReflectionException e) {
+ if (e.getCause() instanceof JUnitException) {
+ throw withRootCauseMessage((JUnitException) e.getCause());
+ }
+ throw e;
+ }
+ }
+
+ private static JUnitException withRootCauseMessage(JUnitException failure)
{
+ Throwable rootCause = failure;
+ Set<Throwable> visited = Collections.newSetFromMap(new
IdentityHashMap<Throwable, Boolean>());
+ visited.add(rootCause);
+ while (rootCause.getCause() != null &&
visited.add(rootCause.getCause())) {
+ rootCause = rootCause.getCause();
+ }
+
+ String causeMessage = rootCause.getMessage();
Review Comment:
If the root cause has no message, we still end up with just "TestEngine with
ID 'testng' failed to discover tests", which is the same thing #3463 is about.
That's easy to hit: `new IllegalStateException()`, `Objects.requireNonNull(x)`,
a `StackOverflowError`, or any NPE on JDK 8/11.
The exception type is lost too. A missing dependency shows up as `...failed
to discover tests: com.acme.Missing`, which looks like a test class name, not a
`ClassNotFoundException`.
Using `rootCause.toString()` instead of `getMessage()` would fix both. Since
the `contains` check is what covers the no-cause case today, it would need an
explicit guard:
```java
if (rootCause == failure) {
return failure;
}
String causeMessage = rootCause.toString();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]