js/src/jit-test/tests/basic/testPaths.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:7489cb1989f8
1 // load() and snarf() (aka read()) should resolve paths relative to the current
2 // working directory. This is a little hard to test because the shell doesn't
3 // really have any (portable) notion of the current directory (and it can't
4 // create files to enforce an expected layout.) loadRelativeToScript() and
5 // readRelativeToScript() do what their names say, which is much easier to
6 // test.
7
8 loaded = {}
9 snarfed = {}
10 loadRel = {}
11 snarfRel = {}
12 for (let f of ['local.js', '../basic/local.js', 'Y.js']) {
13 try {
14 load(f);
15 loaded[f] = true;
16 } catch(e) {
17 loaded[f] = !/can't open/.test(e);
18 }
19
20 try {
21 snarf(f);
22 snarfed[f] = true;
23 } catch(e) {
24 snarfed[f] = !/can't open/.test(e);
25 }
26
27 try {
28 readRelativeToScript(f);
29 snarfRel[f] = true;
30 } catch(e) {
31 snarfRel[f] = !/can't open/.test(e);
32 }
33
34 try {
35 loadRelativeToScript(f);
36 loadRel[f] = true;
37 } catch(e) {
38 loadRel[f] = !/can't open/.test(e);
39 }
40 }
41
42 // local.js in the same dir as this script, so should be found by the
43 // script-relative calls but not the cwd-relative ones -- unless you happen to
44 // be in that directory
45 assertEq(loadRel['local.js'], true);
46 assertEq(loadRel['../basic/local.js'], true);
47 assertEq(snarfRel['local.js'], true);
48 assertEq(snarfRel['../basic/local.js'], true);
49 if (('PWD' in environment) && !(/test.*[\/\\]basic[\/\\]/.test(environment['PWD']))) {
50 assertEq(loaded['local.js'], false);
51 assertEq(loaded['../basic/local.js'], false);
52 assertEq(snarfed['local.js'], false);
53 assertEq(snarfed['../basic/local.js'], false);
54 }
55
56 // Y.js is in the root of the objdir, where |make check| is normally
57 // run from.
58 assertEq(loadRel['Y.js'], false);
59 assertEq(snarfRel['Y.js'], false);
60 if (!snarfed['Y.js']) {
61 print("WARNING: expected to be able to find Y.js in current directory\n");
62 print("(not failing because it depends on where this test was run from)\n");
63 }
64 if (!loaded['Y.js']) {
65 print("WARNING: expected to be able to find Y.js in current directory\n");
66 print("(not failing because it depends on where this test was run from)\n");
67 }

mercurial