diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /toolkit/modules/subprocess/test/xpcshell/test_subprocess_pathSearch.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/modules/subprocess/test/xpcshell/test_subprocess_pathSearch.js')
-rw-r--r-- | toolkit/modules/subprocess/test/xpcshell/test_subprocess_pathSearch.js | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/toolkit/modules/subprocess/test/xpcshell/test_subprocess_pathSearch.js b/toolkit/modules/subprocess/test/xpcshell/test_subprocess_pathSearch.js new file mode 100644 index 0000000000..9d9374f536 --- /dev/null +++ b/toolkit/modules/subprocess/test/xpcshell/test_subprocess_pathSearch.js @@ -0,0 +1,87 @@ +"use strict"; + +const PYTHON = Services.env.get("PYTHON"); + +const PYTHON_BIN = PathUtils.filename(PYTHON); +const PYTHON_DIR = PathUtils.parent(PYTHON); + +const DOES_NOT_EXIST = PathUtils.join( + PathUtils.tempDir, + "ThisPathDoesNotExist" +); + +const PATH_SEP = AppConstants.platform == "win" ? ";" : ":"; + +add_task(async function test_pathSearchAbsolute() { + let env = {}; + + let path = await Subprocess.pathSearch(PYTHON, env); + equal(path, PYTHON, "Full path resolves even with no PATH."); + + env.PATH = ""; + path = await Subprocess.pathSearch(PYTHON, env); + equal(path, PYTHON, "Full path resolves even with empty PATH."); + + await Assert.rejects( + Subprocess.pathSearch(DOES_NOT_EXIST, env), + function (e) { + equal( + e.errorCode, + Subprocess.ERROR_BAD_EXECUTABLE, + "Got the expected error code" + ); + return /File at path .* does not exist, or is not (executable|a normal file)/.test( + e.message + ); + }, + "Absolute path should throw for a nonexistent execuable" + ); +}); + +add_task(async function test_pathSearchRelative() { + let env = {}; + + await Assert.rejects( + Subprocess.pathSearch(PYTHON_BIN, env), + function (e) { + equal( + e.errorCode, + Subprocess.ERROR_BAD_EXECUTABLE, + "Got the expected error code" + ); + return /Executable not found:/.test(e.message); + }, + "Relative path should not be found when PATH is missing" + ); + + env.PATH = [DOES_NOT_EXIST, PYTHON_DIR].join(PATH_SEP); + + let path = await Subprocess.pathSearch(PYTHON_BIN, env); + equal(path, PYTHON, "Correct executable should be found in the path"); +}); + +add_task( + { + skip_if: () => AppConstants.platform != "win", + }, + async function test_pathSearch_PATHEXT() { + ok(PYTHON_BIN.endsWith(".exe"), "Python executable must end with .exe"); + + const python_bin = PYTHON_BIN.slice(0, -4); + + let env = { + PATH: PYTHON_DIR, + PATHEXT: [".com", ".exe", ".foobar"].join(";"), + }; + + let path = await Subprocess.pathSearch(python_bin, env); + equal( + path, + PYTHON, + "Correct executable should be found in the path, with guessed extension" + ); + } +); +// IMPORTANT: Do not add any tests beyond this point without removing +// the `skip_if` condition from the previous task, or it will prevent +// all succeeding tasks from running when it does not match. |