Skip to content

Commit b76e529

Browse files
committed
Add tests for resources with spaces in their path
1 parent 592661e commit b76e529

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/NativeImageResourceFileSystemProviderTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package com.oracle.svm.test;
2727

2828
import static com.oracle.svm.test.NativeImageResourceUtils.RESOURCE_DIR;
29+
import static com.oracle.svm.test.NativeImageResourceUtils.RESOURCE_DIR_WITH_SPACE;
2930
import static com.oracle.svm.test.NativeImageResourceUtils.RESOURCE_EMPTY_DIR;
3031
import static com.oracle.svm.test.NativeImageResourceUtils.RESOURCE_FILE_1;
3132
import static com.oracle.svm.test.NativeImageResourceUtils.RESOURCE_FILE_2;
@@ -231,6 +232,20 @@ public void queryEmptyDir() {
231232
}
232233
}
233234

235+
/**
236+
* Query a directory with spaces in its name
237+
*/
238+
@Test
239+
public void queryDirWithSpaces() {
240+
Path dirWithSpaces = fileSystem.getPath(RESOURCE_DIR_WITH_SPACE);
241+
try (Stream<Path> stream = Files.walk(dirWithSpaces)) {
242+
Assert.assertEquals(1, stream.count());
243+
} catch (IOException e) {
244+
e.printStackTrace();
245+
Assert.fail("IOException occurred during file system walk, starting from the root.");
246+
}
247+
}
248+
234249
/**
235250
* Reading from file using {@link java.nio.channels.ByteChannel}.
236251
*/

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/NativeImageResourceTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package com.oracle.svm.test;
2727

2828
import static com.oracle.svm.test.NativeImageResourceUtils.RESOURCE_DIR;
29+
import static com.oracle.svm.test.NativeImageResourceUtils.RESOURCE_DIR_WITH_SPACE;
2930
import static com.oracle.svm.test.NativeImageResourceUtils.RESOURCE_FILE_1;
3031
import static com.oracle.svm.test.NativeImageResourceUtils.RESOURCE_FILE_2;
3132
import static com.oracle.svm.test.NativeImageResourceUtils.RESOURCE_FILE_3;
@@ -131,6 +132,19 @@ public void classGetDirectoryResource() {
131132
resourceNameToURL(nonCanonicalResourceDirectoryName, false);
132133
}
133134

135+
@Test
136+
public void classGetDirectoryWithSpaceResource() {
137+
URL url1 = resourceNameToURL(RESOURCE_DIR_WITH_SPACE + "/", true);
138+
Assert.assertTrue("The URL should end with slash!", url1.toString().endsWith("/"));
139+
140+
URL url2 = resourceNameToURL(RESOURCE_DIR_WITH_SPACE, true);
141+
Assert.assertFalse("The URL should not end with slash!", url2.toString().endsWith("/"));
142+
Assert.assertTrue("Two URLs must be the same!", compareTwoURLs(url1, url2));
143+
144+
String nonCanonicalResourceDirectoryName = RESOURCE_DIR_WITH_SPACE + "/./";
145+
resourceNameToURL(nonCanonicalResourceDirectoryName, false);
146+
}
147+
134148
@Test
135149
public void registeredResourceDirectoryHasContent() throws IOException {
136150
URL directory = NativeImageResourceUtils.class.getResource(SIMPLE_RESOURCE_DIR);

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/NativeImageResourceUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class NativeImageResourceUtils {
4444
public static final String RESOURCE_DIR = "/resources";
4545
public static final String SIMPLE_RESOURCE_DIR = "/simpleDir";
4646
public static final String RESOURCE_EMPTY_DIR = RESOURCE_DIR + "/empty";
47+
public static final String RESOURCE_DIR_WITH_SPACE = RESOURCE_DIR + "/dir with space";
4748
public static final String RESOURCE_FILE_1 = RESOURCE_DIR + "/resource-test1.txt";
4849
public static final String RESOURCE_FILE_2 = RESOURCE_DIR + "/resource-test2.txt";
4950
public static final String RESOURCE_FILE_3 = RESOURCE_DIR + "/resource-test3.html";
@@ -58,6 +59,7 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
5859
RuntimeResourceAccess.addResource(resourceModule, RESOURCE_DIR.substring(1));
5960
RuntimeResourceAccess.addResource(resourceModule, SIMPLE_RESOURCE_DIR.substring(1));
6061
RuntimeResourceAccess.addResource(resourceModule, RESOURCE_EMPTY_DIR.substring(1));
62+
RuntimeResourceAccess.addResource(resourceModule, RESOURCE_DIR_WITH_SPACE.substring(1));
6163
RuntimeResourceAccess.addResource(resourceModule, RESOURCE_FILE_1.substring(1));
6264
RuntimeResourceAccess.addResource(resourceModule, RESOURCE_FILE_2.substring(1));
6365
RuntimeResourceAccess.addResource(resourceModule, RESOURCE_FILE_3.substring(1));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file instructs mx to create a jar entry for the parent directory

0 commit comments

Comments
 (0)