1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/basic/testPaths.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +// load() and snarf() (aka read()) should resolve paths relative to the current 1.5 +// working directory. This is a little hard to test because the shell doesn't 1.6 +// really have any (portable) notion of the current directory (and it can't 1.7 +// create files to enforce an expected layout.) loadRelativeToScript() and 1.8 +// readRelativeToScript() do what their names say, which is much easier to 1.9 +// test. 1.10 + 1.11 +loaded = {} 1.12 +snarfed = {} 1.13 +loadRel = {} 1.14 +snarfRel = {} 1.15 +for (let f of ['local.js', '../basic/local.js', 'Y.js']) { 1.16 + try { 1.17 + load(f); 1.18 + loaded[f] = true; 1.19 + } catch(e) { 1.20 + loaded[f] = !/can't open/.test(e); 1.21 + } 1.22 + 1.23 + try { 1.24 + snarf(f); 1.25 + snarfed[f] = true; 1.26 + } catch(e) { 1.27 + snarfed[f] = !/can't open/.test(e); 1.28 + } 1.29 + 1.30 + try { 1.31 + readRelativeToScript(f); 1.32 + snarfRel[f] = true; 1.33 + } catch(e) { 1.34 + snarfRel[f] = !/can't open/.test(e); 1.35 + } 1.36 + 1.37 + try { 1.38 + loadRelativeToScript(f); 1.39 + loadRel[f] = true; 1.40 + } catch(e) { 1.41 + loadRel[f] = !/can't open/.test(e); 1.42 + } 1.43 +} 1.44 + 1.45 +// local.js in the same dir as this script, so should be found by the 1.46 +// script-relative calls but not the cwd-relative ones -- unless you happen to 1.47 +// be in that directory 1.48 +assertEq(loadRel['local.js'], true); 1.49 +assertEq(loadRel['../basic/local.js'], true); 1.50 +assertEq(snarfRel['local.js'], true); 1.51 +assertEq(snarfRel['../basic/local.js'], true); 1.52 +if (('PWD' in environment) && !(/test.*[\/\\]basic[\/\\]/.test(environment['PWD']))) { 1.53 + assertEq(loaded['local.js'], false); 1.54 + assertEq(loaded['../basic/local.js'], false); 1.55 + assertEq(snarfed['local.js'], false); 1.56 + assertEq(snarfed['../basic/local.js'], false); 1.57 +} 1.58 + 1.59 +// Y.js is in the root of the objdir, where |make check| is normally 1.60 +// run from. 1.61 +assertEq(loadRel['Y.js'], false); 1.62 +assertEq(snarfRel['Y.js'], false); 1.63 +if (!snarfed['Y.js']) { 1.64 + print("WARNING: expected to be able to find Y.js in current directory\n"); 1.65 + print("(not failing because it depends on where this test was run from)\n"); 1.66 +} 1.67 +if (!loaded['Y.js']) { 1.68 + print("WARNING: expected to be able to find Y.js in current directory\n"); 1.69 + print("(not failing because it depends on where this test was run from)\n"); 1.70 +}