@@ -5321,6 +5321,54 @@ def test_realpath(self):
5321
5321
Popen ([PYTHON , EMCC , 'src.c' , '--embed-file' , 'boot' ]).communicate ()
5322
5322
self .assertContained ('Resolved: /boot/README.txt' , run_js ('a.out.js' ))
5323
5323
5324
+ def test_realpath_2 (self ):
5325
+ open ('src.c' , 'w' ).write (r'''
5326
+ #include <stdlib.h>
5327
+ #include <stdio.h>
5328
+ #include <errno.h>
5329
+
5330
+ int testrealpath(const char* path) {
5331
+ errno = 0;
5332
+ char *t_realpath_buf = realpath(path, NULL);
5333
+ if (NULL == t_realpath_buf) {
5334
+ printf("Resolve failed: \"%s\"\n",path);fflush(stdout);
5335
+ return 1;
5336
+ } else {
5337
+ printf("Resolved: \"%s\" => \"%s\"\n", path, t_realpath_buf);fflush(stdout);
5338
+ free(t_realpath_buf);
5339
+ return 0;
5340
+ }
5341
+ }
5342
+
5343
+ int main(int argc, char **argv)
5344
+ {
5345
+ // files:
5346
+ testrealpath("testfile.txt");
5347
+ testrealpath("Folder/testfile.txt");
5348
+ testrealpath("testnonexistentfile.txt");
5349
+ // folders
5350
+ testrealpath("Folder");
5351
+ testrealpath("/Folder");
5352
+ testrealpath("./");
5353
+ testrealpath("");
5354
+ testrealpath("/");
5355
+ return 0;
5356
+ }
5357
+ ''' )
5358
+ open ('testfile.txt' , 'w' ).write ('' )
5359
+ if not os .path .exists ('Folder' ): os .mkdir ('Folder' )
5360
+ open (os .path .join ('Folder' , 'testfile.txt' ), 'w' ).write ('' )
5361
+ check_execute ([PYTHON , EMCC , 'src.c' , '--embed-file' , 'testfile.txt' , '--embed-file' , 'Folder' ])
5362
+ self .assertContained ('''Resolved: "testfile.txt" => "/testfile.txt"
5363
+ Resolved: "Folder/testfile.txt" => "/Folder/testfile.txt"
5364
+ Resolve failed: "testnonexistentfile.txt"
5365
+ Resolved: "Folder" => "/Folder"
5366
+ Resolved: "/Folder" => "/Folder"
5367
+ Resolved: "./" => "/"
5368
+ Resolve failed: ""
5369
+ Resolved: "/" => "/"
5370
+ ''' , run_js ('a.out.js' ))
5371
+
5324
5372
def test_no_warnings (self ):
5325
5373
out , err = Popen ([PYTHON , EMCC , path_from_root ('tests' , 'hello_libcxx.cpp' )], stderr = PIPE ).communicate ()
5326
5374
assert err == '' , err
0 commit comments