| 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 or a sibling 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 |
var cwd = os.getenv('PWD'); |
| 50 |
if (cwd !== undefined && !(/test.*[\/\\][^\//]+[\/\\]/.test(cwd))) { |
| 51 |
assertEq(loaded['local.js'], false); |
| 52 |
assertEq(loaded['../basic/local.js'], false); |
| 53 |
assertEq(snarfed['local.js'], false); |
| 54 |
assertEq(snarfed['../basic/local.js'], false); |
| 55 |
} |
| 56 |
|
| 57 |
// Y.js is in the root of the objdir, where |make check| is normally |
| 58 |
// run from. |
| 59 |
assertEq(loadRel['Y.js'], false); |
| 60 |
assertEq(snarfRel['Y.js'], false); |
| 61 |
if (!snarfed['Y.js']) { |
| 62 |
print("WARNING: expected to be able to find Y.js in current directory\n"); |
| 63 |
print("(not failing because it depends on where this test was run from)\n"); |
| 64 |
} |
| 65 |
if (!loaded['Y.js']) { |
| 66 |
print("WARNING: expected to be able to find Y.js in current directory\n"); |
| 67 |
print("(not failing because it depends on where this test was run from)\n"); |
| 68 |
} |