Truly independent web browser
LibJS: Make the per-file results of test-js work on Windows
Aliaksandr Kalenik483dbbc05b14
diff --git a/Libraries/LibJS/Rust/src/utilities/test_js/test_runner.rs b/Libraries/LibJS/Rust/src/utilities/test_js/test_runner.rsindex e946d17e75c..9a54d96d6fd 100644--- a/Libraries/LibJS/Rust/src/utilities/test_js/test_runner.rs+++ b/Libraries/LibJS/Rust/src/utilities/test_js/test_runner.rs@@ -229,8 +229,34 @@ fn canonicalized_absolute_path(path: &str) -> String {format!("/{}", parts.join("/"))}+/// An absolute Windows path, with a drive or a server and share, and maybe the `\\?\` prefix of verbatim paths, as one+/// that starts with a slash, with the drive or server as its first part, and with forward slashes like the paths that+/// `iterate_directory_recursively()` appends to it.+#[cfg(windows)]+fn with_forward_slashes(path: &str) -> Option<String> {+ let path = path.replace('\\', "/");+ let path = match path.strip_prefix("//?/") {+ Some(verbatim) => match verbatim.strip_prefix("UNC/") {+ Some(share) => format!("//{share}"),+ None => verbatim.to_string(),+ },+ None => path,+ };+ let bytes = path.as_bytes();+ if bytes.len() >= 2 && bytes[0].is_ascii_alphabetic() && bytes[1] == b':' {+ Some(format!("/{path}"))+ } else {+ path.starts_with("//").then_some(path)+ }+}+/// LexicalPath::relative_path(), which has no answer unless both paths are absolute.pub fn relative_path(path: &str, prefix: &str) -> Option<String> {+ #[cfg(windows)]+ let (path, prefix) = (with_forward_slashes(path)?, with_forward_slashes(prefix)?);+ #[cfg(windows)]+ let (path, prefix) = (path.as_str(), prefix.as_str());+if !path.starts_with('/') || !prefix.starts_with('/') {return None;}diff --git a/Tests/LibJS/JIT/matrix.py b/Tests/LibJS/JIT/matrix.pyindex 7b141f3dbac..c3397b883bb 100755--- a/Tests/LibJS/JIT/matrix.py+++ b/Tests/LibJS/JIT/matrix.py@@ -98,13 +98,18 @@ class TestJsSuite(Suite):"LIBJS_TEST_REPEAT": str(self.arguments.repeat),}+ def test_filter(self, relative: str) -> str:+ """The runner's filter for the test file at `relative`, which it matches against paths with forward slashes. A+ backslash in it would escape the next character."""+ return f"{self.root.name}/{relative}"+def run_file(self, mode: Mode, path: Path) -> Dict[str, str]:wait_until_machine_is_free()relative = path.relative_to(self.root).as_posix()environment = environment_for(mode, self.arguments.seed, {"LIBJS_TEST_REPEAT": str(self.arguments.repeat)})try:process = subprocess.run(- [self.runner, "--per-file", "-f", path],+ [self.runner, "--per-file", "-f", self.test_filter(relative)],env=environment,capture_output=True,timeout=self.arguments.timeout,@@ -137,7 +142,7 @@ class TestJsSuite(Suite):relative = key.split(".js/", 1)[0] + ".js"return command_line(self.environment_changes(mode) | {"LADYBIRD_SOURCE_DIR": str(SOURCE_DIR)},- [self.runner, "-f", self.root / relative],+ [self.runner, "-f", self.test_filter(relative)],)@@ -315,7 +320,7 @@ def main() -> int:expected = suite.run(INTERPRETER)print(f"{suite.name} [interpreter]: {len(expected)} results in {time.monotonic() - start:.1f} s", flush=True)summary[suite.name] = {"interpreter": {"results": len(expected)}}- if "(test262)" in expected:+ if not expected or "(test262)" in expected:print(f"{suite.name} [interpreter]: no results, so nothing to compare with")return 1for mode in modes: