1010
1111package org .junit .platform .launcher .core ;
1212
13+ import static org .junit .platform .commons .util .UnrecoverableExceptions .rethrowIfUnrecoverable ;
1314import static org .junit .platform .engine .SelectorResolutionResult .Status .FAILED ;
1415import static org .junit .platform .engine .SelectorResolutionResult .Status .UNRESOLVED ;
1516
@@ -78,7 +79,7 @@ else if (result.getStatus() == UNRESOLVED && selector instanceof UniqueIdSelecto
7879 }
7980 }
8081
81- static @ Nullable TestSource toSource (DiscoverySelector selector ) {
82+ private static @ Nullable TestSource toSource (DiscoverySelector selector ) {
8283 if (selector instanceof ClassSelector classSelector ) {
8384 return ClassSource .from (classSelector .getClassName ());
8485 }
@@ -96,17 +97,26 @@ else if (result.getStatus() == UNRESOLVED && selector instanceof UniqueIdSelecto
9697 if (selector instanceof PackageSelector packageSelector ) {
9798 return PackageSource .from (packageSelector .getPackageName ());
9899 }
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+ }
107116 }
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 ));
110120 }
111121 return null ;
112122 }
0 commit comments