diff --git a/UI/Headless/Test.cpp b/UI/Headless/Test.cpp index 2cef6fb07fa..84800ce4ede 100644 --- a/UI/Headless/Test.cpp +++ b/UI/Headless/Test.cpp @@ -57,7 +57,7 @@ static ErrorOr load_test_config(StringView test_root_path) return {}; } -static ErrorOr collect_dump_tests(Vector& tests, StringView path, StringView trail, TestMode mode) +static ErrorOr collect_dump_tests(Application const& app, Vector& tests, StringView path, StringView trail, TestMode mode) { Core::DirIterator it(ByteString::formatted("{}/input/{}", path, trail), Core::DirIterator::Flags::SkipDots); @@ -66,7 +66,7 @@ static ErrorOr collect_dump_tests(Vector& tests, StringView path, St auto input_path = TRY(FileSystem::real_path(ByteString::formatted("{}/input/{}/{}", path, trail, name))); if (FileSystem::is_directory(input_path)) { - TRY(collect_dump_tests(tests, path, ByteString::formatted("{}/{}", trail, name), mode)); + TRY(collect_dump_tests(app, tests, path, ByteString::formatted("{}/{}", trail, name), mode)); continue; } @@ -74,13 +74,14 @@ static ErrorOr collect_dump_tests(Vector& tests, StringView path, St continue; auto expectation_path = ByteString::formatted("{}/expected/{}/{}.txt", path, trail, LexicalPath::title(name)); - tests.append({ mode, input_path, move(expectation_path), {} }); + auto relative_path = LexicalPath::relative_path(input_path, app.test_root_path).release_value(); + tests.append({ mode, input_path, move(expectation_path), move(relative_path) }); } return {}; } -static ErrorOr collect_ref_tests(Vector& tests, StringView path, StringView trail) +static ErrorOr collect_ref_tests(Application const& app, Vector& tests, StringView path, StringView trail) { Core::DirIterator it(ByteString::formatted("{}/input/{}", path, trail), Core::DirIterator::Flags::SkipDots); while (it.has_next()) { @@ -88,11 +89,12 @@ static ErrorOr collect_ref_tests(Vector& tests, StringView path, Str auto input_path = TRY(FileSystem::real_path(ByteString::formatted("{}/input/{}/{}", path, trail, name))); if (FileSystem::is_directory(input_path)) { - TRY(collect_ref_tests(tests, path, ByteString::formatted("{}/{}", trail, name))); + TRY(collect_ref_tests(app, tests, path, ByteString::formatted("{}/{}", trail, name))); continue; } - tests.append({ TestMode::Ref, input_path, {}, {} }); + auto relative_path = LexicalPath::relative_path(input_path, app.test_root_path).release_value(); + tests.append({ TestMode::Ref, input_path, {}, move(relative_path) }); } return {}; @@ -249,7 +251,7 @@ static void run_ref_test(HeadlessWebView& view, Test& test, URL::URL const& url, return TestResult::Pass; if (Application::the().dump_failed_ref_tests) { - warnln("\033[33;1mRef test {} failed; dumping screenshots\033[0m", url); + warnln("\033[33;1mRef test {} failed; dumping screenshots\033[0m", test.relative_path); auto dump_screenshot = [&](Gfx::Bitmap& bitmap, StringView path) -> ErrorOr { auto screenshot_file = TRY(Core::File::open(path, Core::File::OpenMode::Write)); @@ -394,11 +396,11 @@ ErrorOr run_tests(Core::AnonymousBuffer const& theme, Web::DevicePixelSize Vector tests; auto test_glob = ByteString::formatted("*{}*", app.test_glob); - TRY(collect_dump_tests(tests, ByteString::formatted("{}/Layout", app.test_root_path), "."sv, TestMode::Layout)); - TRY(collect_dump_tests(tests, ByteString::formatted("{}/Text", app.test_root_path), "."sv, TestMode::Text)); - TRY(collect_ref_tests(tests, ByteString::formatted("{}/Ref", app.test_root_path), "."sv)); + TRY(collect_dump_tests(app, tests, ByteString::formatted("{}/Layout", app.test_root_path), "."sv, TestMode::Layout)); + TRY(collect_dump_tests(app, tests, ByteString::formatted("{}/Text", app.test_root_path), "."sv, TestMode::Text)); + TRY(collect_ref_tests(app, tests, ByteString::formatted("{}/Ref", app.test_root_path), "."sv)); #if !defined(AK_OS_MACOS) - TRY(collect_ref_tests(tests, ByteString::formatted("{}/Screenshot", app.test_root_path), "."sv)); + TRY(collect_ref_tests(app, tests, ByteString::formatted("{}/Screenshot", app.test_root_path), "."sv)); #endif tests.remove_all_matching([&](auto const& test) { @@ -409,7 +411,7 @@ ErrorOr run_tests(Core::AnonymousBuffer const& theme, Web::DevicePixelSize outln("Found {} tests...", tests.size()); for (auto const& [i, test] : enumerate(tests)) - outln("{}/{}: {}", i + 1, tests.size(), *LexicalPath::relative_path(test.input_path, app.test_root_path)); + outln("{}/{}: {}", i + 1, tests.size(), test.relative_path); return {}; } @@ -466,7 +468,7 @@ ErrorOr run_tests(Core::AnonymousBuffer const& theme, Web::DevicePixelSize out("\33[2K\r"); } - out("{}/{}: {}", index + 1, tests.size(), LexicalPath::relative_path(test.input_path, app.test_root_path)); + out("{}/{}: {}", index + 1, tests.size(), test.relative_path); if (is_tty) fflush(stdout); @@ -532,7 +534,7 @@ ErrorOr run_tests(Core::AnonymousBuffer const& theme, Web::DevicePixelSize if (non_passing_test.result == TestResult::Skipped && !app.verbose) continue; - outln("{}: {}", test_result_to_string(non_passing_test.result), non_passing_test.test.input_path); + outln("{}: {}", test_result_to_string(non_passing_test.result), non_passing_test.test.relative_path); } if (app.verbose) { @@ -546,10 +548,9 @@ ErrorOr run_tests(Core::AnonymousBuffer const& theme, Web::DevicePixelSize }); for (auto const& test : tests.span().trim(tests_to_print)) { - auto name = LexicalPath::relative_path(test.input_path, app.test_root_path); auto duration = test.end_time - test.start_time; - outln("{}: {}ms", name, duration.to_milliseconds()); + outln("{}: {}ms", test.relative_path, duration.to_milliseconds()); } } diff --git a/UI/Headless/Test.h b/UI/Headless/Test.h index 46b25dad707..22f112018a1 100644 --- a/UI/Headless/Test.h +++ b/UI/Headless/Test.h @@ -59,6 +59,7 @@ struct Test { ByteString input_path {}; ByteString expectation_path {}; + ByteString relative_path {}; UnixDateTime start_time {}; UnixDateTime end_time {};