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
@@ -78,7 +79,7 @@ else if (result.getStatus() == UNRESOLVED && selector instanceof UniqueIdSelecto
78
79
}
79
80
}
80
81
81
- static @ Nullable TestSource toSource (DiscoverySelector selector ) {
82
+ private static @ Nullable TestSource toSource (DiscoverySelector selector ) {
82
83
if (selector instanceof ClassSelector classSelector ) {
83
84
return ClassSource .from (classSelector .getClassName ());
84
85
}
@@ -96,17 +97,26 @@ else if (result.getStatus() == UNRESOLVED && selector instanceof UniqueIdSelecto
96
97
if (selector instanceof PackageSelector packageSelector ) {
97
98
return PackageSource .from (packageSelector .getPackageName ());
98
99
}
99
- if (selector instanceof FileSelector fileSelector ) {
100
- return fileSelector .getPosition () //
101
- .map (DiscoveryIssueCollector ::convert ) //
102
- .map (position -> FileSource .from (fileSelector .getFile (), position )) //
103
- .orElseGet (() -> FileSource .from (fileSelector .getFile ()));
104
- }
105
- if (selector instanceof DirectorySelector directorySelector ) {
106
- 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
+ }
107
116
}
108
- if (selector instanceof UriSelector uriSelector ) {
109
- 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 ));
110
120
}
111
121
return null ;
112
122
}
0 commit comments