Skip to content

Commit ad690be

Browse files
committed
run some standalone tests with java asserts on
1 parent 8a93973 commit ad690be

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

graalpython/com.oracle.graal.python.test.integration/src/org/graalvm/python/embedding/utils/test/VirtualFileSystemTest.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,35 +83,48 @@ public void toRealPath() throws Exception {
8383
windowsMountPoint(VFS_WIN_MOUNT_POINT).//
8484
extractFilter(p -> p.getFileName().toString().equals("file1")).//
8585
resourceLoadingClass(VirtualFileSystemTest.class).build();
86-
// check regular resource file
86+
// check regular resource dir
8787
assertEquals("dir1", vfs.toRealPath(Path.of("dir1")).toString());
8888
assertEquals(VFS_MOUNT_POINT + File.separator + "dir1", vfs.toRealPath(Path.of(VFS_MOUNT_POINT + File.separator + "dir1")).toString());
89+
// check regular resource file
90+
assertEquals("SomeFile", vfs.toRealPath(Path.of("SomeFile")).toString());
91+
assertEquals(VFS_MOUNT_POINT + File.separator + "SomeFile", vfs.toRealPath(Path.of(VFS_MOUNT_POINT + File.separator + "SomeFile")).toString());
8992
// check to be extracted file
90-
checkExtractedFile(vfs.toRealPath(Path.of("file1")));
91-
checkExtractedFile(vfs.toRealPath(Path.of(VFS_MOUNT_POINT + File.separator + "file1")));
93+
checkExtractedFile(vfs.toRealPath(Path.of("file1")), new String[]{"text1", "text2"});
94+
checkExtractedFile(vfs.toRealPath(Path.of(VFS_MOUNT_POINT + File.separator + "file1")), new String[]{"text1", "text2"});
9295
}
9396

9497
@Test
9598
public void toAbsolutePath() throws Exception {
9699
VirtualFileSystem vfs = VirtualFileSystem.newBuilder().//
97100
unixMountPoint(VFS_MOUNT_POINT).//
98101
windowsMountPoint(VFS_WIN_MOUNT_POINT).//
99-
extractFilter(p -> p.getFileName().toString().equals("file1")).//
102+
extractFilter(p -> p.getFileName().toString().equals("file1") || p.getFileName().toString().equals("file2")).//
100103
resourceLoadingClass(VirtualFileSystemTest.class).build();
101-
// check regular resource file
104+
// check regular resource dir
102105
assertEquals(VFS_MOUNT_POINT + File.separator + "dir1", vfs.toAbsolutePath(Path.of("dir1")).toString());
103106
assertEquals(VFS_MOUNT_POINT + File.separator + "dir1", vfs.toAbsolutePath(Path.of(VFS_MOUNT_POINT + File.separator + "dir1")).toString());
107+
// check regular resource file
108+
assertEquals(VFS_MOUNT_POINT + File.separator + "SomeFile", vfs.toAbsolutePath(Path.of("SomeFile")).toString());
109+
assertEquals(VFS_MOUNT_POINT + File.separator + "SomeFile", vfs.toAbsolutePath(Path.of(VFS_MOUNT_POINT + File.separator + "SomeFile")).toString());
104110
// check to be extracted file
105-
checkExtractedFile(vfs.toAbsolutePath(Path.of("file1")));
106-
checkExtractedFile(vfs.toAbsolutePath(Path.of(VFS_MOUNT_POINT + File.separator + "file1")));
111+
checkExtractedFile(vfs.toAbsolutePath(Path.of("file1")), new String[]{"text1", "text2"});
112+
checkExtractedFile(vfs.toAbsolutePath(Path.of(VFS_MOUNT_POINT + File.separator + "file1")), new String[]{"text1", "text2"});
113+
checkExtractedFile(vfs.toAbsolutePath(Path.of("dir1/file2")), null);
114+
checkExtractedFile(vfs.toAbsolutePath(Path.of(VFS_MOUNT_POINT + File.separator + "dir1/file2")), null);
107115
}
108116

109-
private static void checkExtractedFile(Path extractedFile) throws IOException {
117+
private static void checkExtractedFile(Path extractedFile, String[] expectedContens) throws IOException {
110118
assertTrue(Files.exists(extractedFile));
111119
List<String> lines = Files.readAllLines(extractedFile);
112-
assertEquals(2, lines.size());
113-
assertTrue(lines.contains("text1"));
114-
assertTrue(lines.contains("text2"));
120+
if (expectedContens != null) {
121+
assertEquals("expected " + expectedContens.length + " lines in extracted file '" + extractedFile + "'", expectedContens.length, lines.size());
122+
for (String line : expectedContens) {
123+
assertTrue("expected line '" + line + "' in file '" + extractedFile + "' with contents:\n" + expectedContens, lines.contains(line));
124+
}
125+
} else {
126+
assertEquals("extracted file '" + extractedFile + "' expected to be empty, but had " + lines.size() + " lines", 0, lines.size());
127+
}
115128
}
116129

117130
@Test

graalpython/com.oracle.graal.python.test/src/tests/standalone/test_standalone.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,23 @@ def test_generated_app(self):
281281
out, return_code = run_cmd(cmd, self.env, cwd=target_dir)
282282
assert "hello java" in out, "unexpected output from " + str(cmd)
283283

284-
# execute with java and check
285-
cmd = MVN_CMD + ["exec:java", "-Dexec.mainClass=it.pkg.GraalPy"]
284+
# 2.) check java build and exec
285+
# run with java asserts on
286+
if self.env.get("MAVEN_OPTS"):
287+
self.env["MAVEN_OPTS"] = self.env.get("MAVEN_OPTS") + " -ea -esa"
288+
else:
289+
self.env["MAVEN_OPTS"] = "-ea -esa"
290+
291+
# import struct from python file triggers extract of native extension files in VirtualFileSystem
292+
hello_src = os.path.join(target_dir, "src", "main", "resources", "org.graalvm.python.vfs", "proj", "hello.py")
293+
contents = open(hello_src, 'r').read()
294+
with open(hello_src, 'w') as f:
295+
f.write("import struct\n" + contents)
296+
297+
# rebuild and exec
298+
cmd = MVN_CMD + ["package", "exec:java", "-Dexec.mainClass=it.pkg.GraalPy"]
286299
out, return_code = run_cmd(cmd, self.env, cwd=target_dir)
300+
assert "BUILD SUCCESS" in out, "unexpected output from " + str(cmd)
287301
assert "hello java" in out, "unexpected output from " + str(cmd)
288302

289303
#GR-51132 - NoClassDefFoundError when running polyglot app in java mode
@@ -299,7 +313,7 @@ def test_fail_without_graalpy_dep(self):
299313

300314
cmd = MVN_CMD + ["process-resources"]
301315
out, return_code = run_cmd(cmd, self.env, cwd=target_dir)
302-
assert "Missing GraalPy dependency. Please add to your pom either org.graalvm.polyglot:python-community or org.graalvm.polyglot:python" in out
316+
assert "Missing GraalPy dependency. Please add to your pom either org.graalvm.polyglot:python-community or org.graalvm.polyglot:python" in out
303317

304318
@unittest.skipUnless(is_enabled, "ENABLE_STANDALONE_UNITTESTS is not true")
305319
def test_gen_launcher_and_venv(self):
@@ -308,7 +322,7 @@ def test_gen_launcher_and_venv(self):
308322
target_dir = os.path.join(str(tmpdir), target_name)
309323
pom_template = os.path.join(os.path.dirname(__file__), "prepare_venv_pom.xml")
310324
self.generate_app(tmpdir, target_dir, target_name, pom_template)
311-
325+
312326
cmd = MVN_CMD + ["process-resources"]
313327
out, return_code = run_cmd(cmd, self.env, cwd=target_dir)
314328
assert "-m venv" in out, "unexpected output from " + str(cmd)
@@ -345,7 +359,7 @@ def test_check_home(self):
345359
target_dir = os.path.join(str(tmpdir), target_name)
346360
pom_template = os.path.join(os.path.dirname(__file__), "check_home_pom.xml")
347361
self.generate_app(tmpdir, target_dir, target_name, pom_template)
348-
362+
349363
cmd = MVN_CMD + ["process-resources"]
350364
out, return_code = run_cmd(cmd, self.env, cwd=target_dir)
351365

0 commit comments

Comments
 (0)