michael@0: // load() and snarf() (aka read()) should resolve paths relative to the current michael@0: // working directory. This is a little hard to test because the shell doesn't michael@0: // really have any (portable) notion of the current directory (and it can't michael@0: // create files to enforce an expected layout.) loadRelativeToScript() and michael@0: // readRelativeToScript() do what their names say, which is much easier to michael@0: // test. michael@0: michael@0: loaded = {} michael@0: snarfed = {} michael@0: loadRel = {} michael@0: snarfRel = {} michael@0: for (let f of ['local.js', '../basic/local.js', 'Y.js']) { michael@0: try { michael@0: load(f); michael@0: loaded[f] = true; michael@0: } catch(e) { michael@0: loaded[f] = !/can't open/.test(e); michael@0: } michael@0: michael@0: try { michael@0: snarf(f); michael@0: snarfed[f] = true; michael@0: } catch(e) { michael@0: snarfed[f] = !/can't open/.test(e); michael@0: } michael@0: michael@0: try { michael@0: readRelativeToScript(f); michael@0: snarfRel[f] = true; michael@0: } catch(e) { michael@0: snarfRel[f] = !/can't open/.test(e); michael@0: } michael@0: michael@0: try { michael@0: loadRelativeToScript(f); michael@0: loadRel[f] = true; michael@0: } catch(e) { michael@0: loadRel[f] = !/can't open/.test(e); michael@0: } michael@0: } michael@0: michael@0: // local.js in the same dir as this script, so should be found by the michael@0: // script-relative calls but not the cwd-relative ones -- unless you happen to michael@0: // be in that directory michael@0: assertEq(loadRel['local.js'], true); michael@0: assertEq(loadRel['../basic/local.js'], true); michael@0: assertEq(snarfRel['local.js'], true); michael@0: assertEq(snarfRel['../basic/local.js'], true); michael@0: if (('PWD' in environment) && !(/test.*[\/\\]basic[\/\\]/.test(environment['PWD']))) { michael@0: assertEq(loaded['local.js'], false); michael@0: assertEq(loaded['../basic/local.js'], false); michael@0: assertEq(snarfed['local.js'], false); michael@0: assertEq(snarfed['../basic/local.js'], false); michael@0: } michael@0: michael@0: // Y.js is in the root of the objdir, where |make check| is normally michael@0: // run from. michael@0: assertEq(loadRel['Y.js'], false); michael@0: assertEq(snarfRel['Y.js'], false); michael@0: if (!snarfed['Y.js']) { michael@0: print("WARNING: expected to be able to find Y.js in current directory\n"); michael@0: print("(not failing because it depends on where this test was run from)\n"); michael@0: } michael@0: if (!loaded['Y.js']) { michael@0: print("WARNING: expected to be able to find Y.js in current directory\n"); michael@0: print("(not failing because it depends on where this test was run from)\n"); michael@0: }