summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/testPaths.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/basic/testPaths.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/basic/testPaths.js')
-rw-r--r--js/src/jit-test/tests/basic/testPaths.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/testPaths.js b/js/src/jit-test/tests/basic/testPaths.js
new file mode 100644
index 0000000000..a2b78323ea
--- /dev/null
+++ b/js/src/jit-test/tests/basic/testPaths.js
@@ -0,0 +1,68 @@
+// load() and snarf() (aka read()) should resolve paths relative to the current
+// working directory. This is a little hard to test because the shell doesn't
+// really have any (portable) notion of the current directory (and it can't
+// create files to enforce an expected layout.) loadRelativeToScript() and
+// readRelativeToScript() do what their names say, which is much easier to
+// test.
+
+loaded = {}
+snarfed = {}
+loadRel = {}
+snarfRel = {}
+for (let f of ['local.js', '../basic/local.js', 'Y.js']) {
+ try {
+ load(f);
+ loaded[f] = true;
+ } catch(e) {
+ loaded[f] = !/can't open/.test(e);
+ }
+
+ try {
+ snarf(f);
+ snarfed[f] = true;
+ } catch(e) {
+ snarfed[f] = !/can't open/.test(e);
+ }
+
+ try {
+ readRelativeToScript(f);
+ snarfRel[f] = true;
+ } catch(e) {
+ snarfRel[f] = !/can't open/.test(e);
+ }
+
+ try {
+ loadRelativeToScript(f);
+ loadRel[f] = true;
+ } catch(e) {
+ loadRel[f] = !/can't open/.test(e);
+ }
+}
+
+// local.js in the same dir as this script, so should be found by the
+// script-relative calls but not the cwd-relative ones -- unless you happen to
+// be in that directory or a sibling directory.
+assertEq(loadRel['local.js'], true);
+assertEq(loadRel['../basic/local.js'], true);
+assertEq(snarfRel['local.js'], true);
+assertEq(snarfRel['../basic/local.js'], true);
+var cwd = os.getenv('PWD');
+if (cwd !== undefined && !(/test.*[\/\\][^\//]+[\/\\]/.test(cwd))) {
+ assertEq(loaded['local.js'], false);
+ assertEq(loaded['../basic/local.js'], false);
+ assertEq(snarfed['local.js'], false);
+ assertEq(snarfed['../basic/local.js'], false);
+}
+
+// Y.js is in the root of the objdir, where |make check| is normally
+// run from.
+assertEq(loadRel['Y.js'], false);
+assertEq(snarfRel['Y.js'], false);
+if (!snarfed['Y.js']) {
+ print("WARNING: expected to be able to find Y.js in current directory\n");
+ print("(not failing because it depends on where this test was run from)\n");
+}
+if (!loaded['Y.js']) {
+ print("WARNING: expected to be able to find Y.js in current directory\n");
+ print("(not failing because it depends on where this test was run from)\n");
+}