Skip to content

[test] Split realpath tests into separate files. NFC #22350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/other/test_realpath.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

int main(int argc, char **argv) {
char *t_realpath_buf = realpath("/boot/README.txt", NULL);
if (!t_realpath_buf) {
perror("Resolve failed");
return 1;
}

printf("Resolved: %s\n", t_realpath_buf);
free(t_realpath_buf);
return 0;
}
1 change: 1 addition & 0 deletions test/other/test_realpath.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Resolved: /boot/README.txt
30 changes: 30 additions & 0 deletions test/other/test_realpath_2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

int testrealpath(const char* path) {
errno = 0;
char *t_realpath_buf = realpath(path, NULL);
if (NULL == t_realpath_buf) {
printf("Resolve failed: \"%s\"\n",path);fflush(stdout);
return 1;
} else {
printf("Resolved: \"%s\" => \"%s\"\n", path, t_realpath_buf);fflush(stdout);
free(t_realpath_buf);
return 0;
}
}

int main(int argc, char **argv) {
// files:
testrealpath("testfile.txt");
testrealpath("Folder/testfile.txt");
testrealpath("testnonexistentfile.txt");
// folders
testrealpath("Folder");
testrealpath("/Folder");
testrealpath("./");
testrealpath("");
testrealpath("/");
return 0;
}
8 changes: 8 additions & 0 deletions test/other/test_realpath_2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Resolved: "testfile.txt" => "/testfile.txt"
Resolved: "Folder/testfile.txt" => "/Folder/testfile.txt"
Resolve failed: "testnonexistentfile.txt"
Resolved: "Folder" => "/Folder"
Resolved: "/Folder" => "/Folder"
Resolved: "./" => "/"
Resolve failed: ""
Resolved: "/" => "/"
23 changes: 23 additions & 0 deletions test/other/test_realpath_nodefs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <emscripten.h>

#define TEST_PATH "/working/TEST_NODEFS.txt"

int main(int argc, char **argv) {
errno = 0;
EM_ASM({
FS.mkdir('/working');
FS.mount(NODEFS, { root: '.' }, '/working');
});
char *t_realpath_buf = realpath(TEST_PATH, NULL);
if (NULL == t_realpath_buf) {
perror("Resolve failed");
return 1;
} else {
printf("Resolved: %s\n", t_realpath_buf);
free(t_realpath_buf);
return 0;
}
}
1 change: 1 addition & 0 deletions test/other/test_realpath_nodefs.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Resolved: /working/TEST_NODEFS.txt
95 changes: 5 additions & 90 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -7677,28 +7677,11 @@ def test_js_lib_native_deps_extra(self):
self.do_runf('hello_world.c', emcc_args=['--js-library', 'lib.js'])

@crossplatform
@also_with_wasmfs
def test_realpath(self):
create_file('src.c', r'''
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

int main(int argc, char **argv) {
char *t_realpath_buf = realpath("/boot/README.txt", NULL);
if (!t_realpath_buf) {
perror("Resolve failed");
return 1;
}

printf("Resolved: %s\n", t_realpath_buf);
free(t_realpath_buf);
return 0;
}
''')
ensure_dir('boot')
create_file('boot/README.txt', ' ')
self.run_process([EMCC, 'src.c', '-sSAFE_HEAP', '--embed-file', 'boot'])
self.assertContained('Resolved: /boot/README.txt', self.run_js('a.out.js'))
self.do_other_test('test_realpath.c', emcc_args=['-sSAFE_HEAP', '--embed-file', 'boot'])

@crossplatform
@parameterized({
Expand All @@ -7707,83 +7690,15 @@ def test_realpath(self):
'wasmfs': (['-sWASMFS', '-sFORCE_FILESYSTEM'],),
})
def test_realpath_nodefs(self, args):
create_file('src.c', r'''
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <emscripten.h>

#define TEST_PATH "/working/TEST_NODEFS.txt"

int main(int argc, char **argv) {
errno = 0;
EM_ASM({
FS.mkdir('/working');
FS.mount(NODEFS, { root: '.' }, '/working');
});
char *t_realpath_buf = realpath(TEST_PATH, NULL);
if (NULL == t_realpath_buf) {
perror("Resolve failed");
return 1;
} else {
printf("Resolved: %s\n", t_realpath_buf);
free(t_realpath_buf);
return 0;
}
}
''')
create_file('TEST_NODEFS.txt', ' ')
self.do_runf('src.c',
expected_output='Resolved: /working/TEST_NODEFS.txt',
emcc_args=args + ['-lnodefs.js'])
self.do_other_test('test_realpath_nodefs.c', emcc_args=args + ['-lnodefs.js'])

@also_with_wasmfs
def test_realpath_2(self):
ensure_dir('Folder')
create_file('src.c', r'''
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

int testrealpath(const char* path) {
errno = 0;
char *t_realpath_buf = realpath(path, NULL);
if (NULL == t_realpath_buf) {
printf("Resolve failed: \"%s\"\n",path);fflush(stdout);
return 1;
} else {
printf("Resolved: \"%s\" => \"%s\"\n", path, t_realpath_buf);fflush(stdout);
free(t_realpath_buf);
return 0;
}
}

int main(int argc, char **argv)
{
// files:
testrealpath("testfile.txt");
testrealpath("Folder/testfile.txt");
testrealpath("testnonexistentfile.txt");
// folders
testrealpath("Folder");
testrealpath("/Folder");
testrealpath("./");
testrealpath("");
testrealpath("/");
return 0;
}
''')
create_file('testfile.txt', '')
create_file('Folder/testfile.txt', '')
self.run_process([EMCC, 'src.c', '--embed-file', 'testfile.txt', '--embed-file', 'Folder'])
self.assertContained('''Resolved: "testfile.txt" => "/testfile.txt"
Resolved: "Folder/testfile.txt" => "/Folder/testfile.txt"
Resolve failed: "testnonexistentfile.txt"
Resolved: "Folder" => "/Folder"
Resolved: "/Folder" => "/Folder"
Resolved: "./" => "/"
Resolve failed: ""
Resolved: "/" => "/"
''', self.run_js('a.out.js'))
self.do_other_test('test_realpath_2.c', emcc_args=['--embed-file', 'testfile.txt', '--embed-file', 'Folder'])

@with_env_modify({'EMCC_LOGGING': '0'}) # this test assumes no emcc output
def test_no_warnings(self):
Expand Down
Loading