headless-browser: Store each test's relative path on the Test object

Rather than having to compute it each time we want it.
This commit is contained in:
Timothy Flynn 2024-11-30 08:08:47 -05:00 committed by Tim Flynn
parent 3947c6d4ed
commit 49eeaaf8fe
Notes: github-actions[bot] 2024-11-30 17:11:24 +00:00
2 changed files with 18 additions and 16 deletions

View file

@ -57,7 +57,7 @@ static ErrorOr<void> load_test_config(StringView test_root_path)
return {};
}
static ErrorOr<void> collect_dump_tests(Vector<Test>& tests, StringView path, StringView trail, TestMode mode)
static ErrorOr<void> collect_dump_tests(Application const& app, Vector<Test>& 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<void> collect_dump_tests(Vector<Test>& 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<void> collect_dump_tests(Vector<Test>& 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<void> collect_ref_tests(Vector<Test>& tests, StringView path, StringView trail)
static ErrorOr<void> collect_ref_tests(Application const& app, Vector<Test>& 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<void> collect_ref_tests(Vector<Test>& 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<void> {
auto screenshot_file = TRY(Core::File::open(path, Core::File::OpenMode::Write));
@ -394,11 +396,11 @@ ErrorOr<void> run_tests(Core::AnonymousBuffer const& theme, Web::DevicePixelSize
Vector<Test> 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<void> 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<void> 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<void> 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<void> 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());
}
}

View file

@ -59,6 +59,7 @@ struct Test {
ByteString input_path {};
ByteString expectation_path {};
ByteString relative_path {};
UnixDateTime start_time {};
UnixDateTime end_time {};