Skip to content

Commit 80d2150

Browse files
authored
[test] Split realpath tests into separate files. NFC (#22350)
1 parent 65e311b commit 80d2150

File tree

7 files changed

+83
-90
lines changed

7 files changed

+83
-90
lines changed

test/other/test_realpath.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <errno.h>
4+
5+
int main(int argc, char **argv) {
6+
char *t_realpath_buf = realpath("/boot/README.txt", NULL);
7+
if (!t_realpath_buf) {
8+
perror("Resolve failed");
9+
return 1;
10+
}
11+
12+
printf("Resolved: %s\n", t_realpath_buf);
13+
free(t_realpath_buf);
14+
return 0;
15+
}

test/other/test_realpath.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Resolved: /boot/README.txt

test/other/test_realpath_2.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <errno.h>
4+
5+
int testrealpath(const char* path) {
6+
errno = 0;
7+
char *t_realpath_buf = realpath(path, NULL);
8+
if (NULL == t_realpath_buf) {
9+
printf("Resolve failed: \"%s\"\n",path);fflush(stdout);
10+
return 1;
11+
} else {
12+
printf("Resolved: \"%s\" => \"%s\"\n", path, t_realpath_buf);fflush(stdout);
13+
free(t_realpath_buf);
14+
return 0;
15+
}
16+
}
17+
18+
int main(int argc, char **argv) {
19+
// files:
20+
testrealpath("testfile.txt");
21+
testrealpath("Folder/testfile.txt");
22+
testrealpath("testnonexistentfile.txt");
23+
// folders
24+
testrealpath("Folder");
25+
testrealpath("/Folder");
26+
testrealpath("./");
27+
testrealpath("");
28+
testrealpath("/");
29+
return 0;
30+
}

test/other/test_realpath_2.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Resolved: "testfile.txt" => "/testfile.txt"
2+
Resolved: "Folder/testfile.txt" => "/Folder/testfile.txt"
3+
Resolve failed: "testnonexistentfile.txt"
4+
Resolved: "Folder" => "/Folder"
5+
Resolved: "/Folder" => "/Folder"
6+
Resolved: "./" => "/"
7+
Resolve failed: ""
8+
Resolved: "/" => "/"

test/other/test_realpath_nodefs.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <errno.h>
4+
#include <emscripten.h>
5+
6+
#define TEST_PATH "/working/TEST_NODEFS.txt"
7+
8+
int main(int argc, char **argv) {
9+
errno = 0;
10+
EM_ASM({
11+
FS.mkdir('/working');
12+
FS.mount(NODEFS, { root: '.' }, '/working');
13+
});
14+
char *t_realpath_buf = realpath(TEST_PATH, NULL);
15+
if (NULL == t_realpath_buf) {
16+
perror("Resolve failed");
17+
return 1;
18+
} else {
19+
printf("Resolved: %s\n", t_realpath_buf);
20+
free(t_realpath_buf);
21+
return 0;
22+
}
23+
}

test/other/test_realpath_nodefs.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Resolved: /working/TEST_NODEFS.txt

test/test_other.py

Lines changed: 5 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -7677,28 +7677,11 @@ def test_js_lib_native_deps_extra(self):
76777677
self.do_runf('hello_world.c', emcc_args=['--js-library', 'lib.js'])
76787678

76797679
@crossplatform
7680+
@also_with_wasmfs
76807681
def test_realpath(self):
7681-
create_file('src.c', r'''
7682-
#include <stdlib.h>
7683-
#include <stdio.h>
7684-
#include <errno.h>
7685-
7686-
int main(int argc, char **argv) {
7687-
char *t_realpath_buf = realpath("/boot/README.txt", NULL);
7688-
if (!t_realpath_buf) {
7689-
perror("Resolve failed");
7690-
return 1;
7691-
}
7692-
7693-
printf("Resolved: %s\n", t_realpath_buf);
7694-
free(t_realpath_buf);
7695-
return 0;
7696-
}
7697-
''')
76987682
ensure_dir('boot')
76997683
create_file('boot/README.txt', ' ')
7700-
self.run_process([EMCC, 'src.c', '-sSAFE_HEAP', '--embed-file', 'boot'])
7701-
self.assertContained('Resolved: /boot/README.txt', self.run_js('a.out.js'))
7684+
self.do_other_test('test_realpath.c', emcc_args=['-sSAFE_HEAP', '--embed-file', 'boot'])
77027685

77037686
@crossplatform
77047687
@parameterized({
@@ -7707,83 +7690,15 @@ def test_realpath(self):
77077690
'wasmfs': (['-sWASMFS', '-sFORCE_FILESYSTEM'],),
77087691
})
77097692
def test_realpath_nodefs(self, args):
7710-
create_file('src.c', r'''
7711-
#include <stdlib.h>
7712-
#include <stdio.h>
7713-
#include <errno.h>
7714-
#include <emscripten.h>
7715-
7716-
#define TEST_PATH "/working/TEST_NODEFS.txt"
7717-
7718-
int main(int argc, char **argv) {
7719-
errno = 0;
7720-
EM_ASM({
7721-
FS.mkdir('/working');
7722-
FS.mount(NODEFS, { root: '.' }, '/working');
7723-
});
7724-
char *t_realpath_buf = realpath(TEST_PATH, NULL);
7725-
if (NULL == t_realpath_buf) {
7726-
perror("Resolve failed");
7727-
return 1;
7728-
} else {
7729-
printf("Resolved: %s\n", t_realpath_buf);
7730-
free(t_realpath_buf);
7731-
return 0;
7732-
}
7733-
}
7734-
''')
77357693
create_file('TEST_NODEFS.txt', ' ')
7736-
self.do_runf('src.c',
7737-
expected_output='Resolved: /working/TEST_NODEFS.txt',
7738-
emcc_args=args + ['-lnodefs.js'])
7694+
self.do_other_test('test_realpath_nodefs.c', emcc_args=args + ['-lnodefs.js'])
77397695

7696+
@also_with_wasmfs
77407697
def test_realpath_2(self):
77417698
ensure_dir('Folder')
7742-
create_file('src.c', r'''
7743-
#include <stdlib.h>
7744-
#include <stdio.h>
7745-
#include <errno.h>
7746-
7747-
int testrealpath(const char* path) {
7748-
errno = 0;
7749-
char *t_realpath_buf = realpath(path, NULL);
7750-
if (NULL == t_realpath_buf) {
7751-
printf("Resolve failed: \"%s\"\n",path);fflush(stdout);
7752-
return 1;
7753-
} else {
7754-
printf("Resolved: \"%s\" => \"%s\"\n", path, t_realpath_buf);fflush(stdout);
7755-
free(t_realpath_buf);
7756-
return 0;
7757-
}
7758-
}
7759-
7760-
int main(int argc, char **argv)
7761-
{
7762-
// files:
7763-
testrealpath("testfile.txt");
7764-
testrealpath("Folder/testfile.txt");
7765-
testrealpath("testnonexistentfile.txt");
7766-
// folders
7767-
testrealpath("Folder");
7768-
testrealpath("/Folder");
7769-
testrealpath("./");
7770-
testrealpath("");
7771-
testrealpath("/");
7772-
return 0;
7773-
}
7774-
''')
77757699
create_file('testfile.txt', '')
77767700
create_file('Folder/testfile.txt', '')
7777-
self.run_process([EMCC, 'src.c', '--embed-file', 'testfile.txt', '--embed-file', 'Folder'])
7778-
self.assertContained('''Resolved: "testfile.txt" => "/testfile.txt"
7779-
Resolved: "Folder/testfile.txt" => "/Folder/testfile.txt"
7780-
Resolve failed: "testnonexistentfile.txt"
7781-
Resolved: "Folder" => "/Folder"
7782-
Resolved: "/Folder" => "/Folder"
7783-
Resolved: "./" => "/"
7784-
Resolve failed: ""
7785-
Resolved: "/" => "/"
7786-
''', self.run_js('a.out.js'))
7701+
self.do_other_test('test_realpath_2.c', emcc_args=['--embed-file', 'testfile.txt', '--embed-file', 'Folder'])
77877702

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

0 commit comments

Comments
 (0)