10
10
11
11
package org .junit .platform .launcher .core ;
12
12
13
+ import static org .junit .platform .commons .util .UnrecoverableExceptions .rethrowIfUnrecoverable ;
13
14
import static org .junit .platform .engine .SelectorResolutionResult .Status .FAILED ;
14
15
import static org .junit .platform .engine .SelectorResolutionResult .Status .UNRESOLVED ;
15
16
@@ -67,7 +68,7 @@ public void selectorProcessed(UniqueId engineId, DiscoverySelector selector, Sel
67
68
if (result .getStatus () == FAILED ) {
68
69
this .issues .add (DiscoveryIssue .builder (Severity .ERROR , selector + " resolution failed" ) //
69
70
.cause (result .getThrowable ()) //
70
- .source (toSourceSafely (selector )) //
71
+ .source (toSource (selector )) //
71
72
.build ());
72
73
}
73
74
else if (result .getStatus () == UNRESOLVED && selector instanceof UniqueIdSelector uniqueIdSelector ) {
@@ -78,16 +79,6 @@ else if (result.getStatus() == UNRESOLVED && selector instanceof UniqueIdSelecto
78
79
}
79
80
}
80
81
81
- private static @ Nullable TestSource toSourceSafely (DiscoverySelector selector ) {
82
- try {
83
- return toSource (selector );
84
- }
85
- catch (Exception e ) {
86
- logger .error (e , () -> "Failed to convert DiscoverySelector [%s] into TestSource" .formatted (selector ));
87
- return null ;
88
- }
89
- }
90
-
91
82
private static @ Nullable TestSource toSource (DiscoverySelector selector ) {
92
83
if (selector instanceof ClassSelector classSelector ) {
93
84
return ClassSource .from (classSelector .getClassName ());
@@ -106,17 +97,26 @@ else if (result.getStatus() == UNRESOLVED && selector instanceof UniqueIdSelecto
106
97
if (selector instanceof PackageSelector packageSelector ) {
107
98
return PackageSource .from (packageSelector .getPackageName ());
108
99
}
109
- if (selector instanceof FileSelector fileSelector ) {
110
- return fileSelector .getPosition () //
111
- .map (DiscoveryIssueCollector ::convert ) //
112
- .map (position -> FileSource .from (fileSelector .getFile (), position )) //
113
- .orElseGet (() -> FileSource .from (fileSelector .getFile ()));
114
- }
115
- if (selector instanceof DirectorySelector directorySelector ) {
116
- return DirectorySource .from (directorySelector .getDirectory ());
100
+ try {
101
+ // Both FileSource and DirectorySource call File.getCanonicalFile() to normalize the reported file which
102
+ // can throw an exception for certain file names on certain file systems. UriSource.from(...) is affected
103
+ // as well because it may return a FileSource or DirectorySource
104
+ if (selector instanceof FileSelector fileSelector ) {
105
+ return fileSelector .getPosition () //
106
+ .map (DiscoveryIssueCollector ::convert ) //
107
+ .map (position -> FileSource .from (fileSelector .getFile (), position )) //
108
+ .orElseGet (() -> FileSource .from (fileSelector .getFile ()));
109
+ }
110
+ if (selector instanceof DirectorySelector directorySelector ) {
111
+ return DirectorySource .from (directorySelector .getDirectory ());
112
+ }
113
+ if (selector instanceof UriSelector uriSelector ) {
114
+ return UriSource .from (uriSelector .getUri ());
115
+ }
117
116
}
118
- if (selector instanceof UriSelector uriSelector ) {
119
- return UriSource .from (uriSelector .getUri ());
117
+ catch (Exception ex ) {
118
+ rethrowIfUnrecoverable (ex );
119
+ logger .warn (ex , () -> "Failed to convert DiscoverySelector [%s] into TestSource" .formatted (selector ));
120
120
}
121
121
return null ;
122
122
}
0 commit comments