mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-18 07:22:22 +00:00
headless-browser: Add a --dry-run flag
--dry-run causes headless-browser to collect and then list tests, without running them.
This commit is contained in:
parent
c497e5f850
commit
c4b62ab04d
Notes:
github-actions[bot]
2024-10-02 15:37:26 +00:00
Author: https://github.com/AtkinsSJ
Commit: c4b62ab04d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1585
Reviewed-by: https://github.com/tcl3
1 changed files with 28 additions and 9 deletions
|
@ -501,9 +501,10 @@ static ErrorOr<void> collect_ref_tests(Vector<Test>& tests, StringView path)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<int> run_tests(HeadlessWebContentView& view, StringView test_root_path, StringView test_glob, bool dump_failed_ref_tests, bool dump_gc_graph)
|
static ErrorOr<int> run_tests(HeadlessWebContentView* view, StringView test_root_path, StringView test_glob, bool dump_failed_ref_tests, bool dump_gc_graph, bool dry_run)
|
||||||
{
|
{
|
||||||
view.clear_content_filters();
|
if (view)
|
||||||
|
view->clear_content_filters();
|
||||||
|
|
||||||
TRY(load_test_config(test_root_path));
|
TRY(load_test_config(test_root_path));
|
||||||
|
|
||||||
|
@ -526,17 +527,26 @@ static ErrorOr<int> run_tests(HeadlessWebContentView& view, StringView test_root
|
||||||
|
|
||||||
bool is_tty = isatty(STDOUT_FILENO);
|
bool is_tty = isatty(STDOUT_FILENO);
|
||||||
|
|
||||||
|
if (dry_run)
|
||||||
|
outln("Found {} tests...", tests.size());
|
||||||
|
else
|
||||||
outln("Running {} tests...", tests.size());
|
outln("Running {} tests...", tests.size());
|
||||||
|
|
||||||
for (size_t i = 0; i < tests.size(); ++i) {
|
for (size_t i = 0; i < tests.size(); ++i) {
|
||||||
auto& test = tests[i];
|
auto& test = tests[i];
|
||||||
|
|
||||||
if (is_tty) {
|
if (is_tty && !dry_run) {
|
||||||
// Keep clearing and reusing the same line if stdout is a TTY.
|
// Keep clearing and reusing the same line if stdout is a TTY.
|
||||||
out("\33[2K\r");
|
out("\33[2K\r");
|
||||||
}
|
}
|
||||||
|
|
||||||
out("{}/{}: {}", i + 1, tests.size(), LexicalPath::relative_path(test.input_path, test_root_path));
|
out("{}/{}: {}", i + 1, tests.size(), LexicalPath::relative_path(test.input_path, test_root_path));
|
||||||
|
|
||||||
|
if (dry_run) {
|
||||||
|
outln("");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_tty)
|
if (is_tty)
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
else
|
else
|
||||||
|
@ -548,7 +558,7 @@ static ErrorOr<int> run_tests(HeadlessWebContentView& view, StringView test_root
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
test.result = TRY(run_test(view, test.input_path, test.expectation_path, test.mode, dump_failed_ref_tests));
|
test.result = TRY(run_test(*view, test.input_path, test.expectation_path, test.mode, dump_failed_ref_tests));
|
||||||
switch (*test.result) {
|
switch (*test.result) {
|
||||||
case TestResult::Pass:
|
case TestResult::Pass:
|
||||||
++pass_count;
|
++pass_count;
|
||||||
|
@ -565,6 +575,9 @@ static ErrorOr<int> run_tests(HeadlessWebContentView& view, StringView test_root
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dry_run)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (is_tty)
|
if (is_tty)
|
||||||
outln("\33[2K\rDone!");
|
outln("\33[2K\rDone!");
|
||||||
|
|
||||||
|
@ -578,7 +591,7 @@ static ErrorOr<int> run_tests(HeadlessWebContentView& view, StringView test_root
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dump_gc_graph) {
|
if (dump_gc_graph) {
|
||||||
auto path = view.dump_gc_graph();
|
auto path = view->dump_gc_graph();
|
||||||
if (path.is_error()) {
|
if (path.is_error()) {
|
||||||
warnln("Failed to dump GC graph: {}", path.error());
|
warnln("Failed to dump GC graph: {}", path.error());
|
||||||
} else {
|
} else {
|
||||||
|
@ -601,6 +614,7 @@ struct Application : public WebView::Application {
|
||||||
args_parser.add_option(dump_text, "Dump text and exit", "dump-text", 'T');
|
args_parser.add_option(dump_text, "Dump text and exit", "dump-text", 'T');
|
||||||
args_parser.add_option(test_root_path, "Run tests in path", "run-tests", 'R', "test-root-path");
|
args_parser.add_option(test_root_path, "Run tests in path", "run-tests", 'R', "test-root-path");
|
||||||
args_parser.add_option(test_glob, "Only run tests matching the given glob", "filter", 'f', "glob");
|
args_parser.add_option(test_glob, "Only run tests matching the given glob", "filter", 'f', "glob");
|
||||||
|
args_parser.add_option(test_dry_run, "List the tests that would be run, without running them", "dry-run");
|
||||||
args_parser.add_option(dump_failed_ref_tests, "Dump screenshots of failing ref tests", "dump-failed-ref-tests", 'D');
|
args_parser.add_option(dump_failed_ref_tests, "Dump screenshots of failing ref tests", "dump-failed-ref-tests", 'D');
|
||||||
args_parser.add_option(dump_gc_graph, "Dump GC graph", "dump-gc-graph", 'G');
|
args_parser.add_option(dump_gc_graph, "Dump GC graph", "dump-gc-graph", 'G');
|
||||||
args_parser.add_option(resources_folder, "Path of the base resources folder (defaults to /res)", "resources", 'r', "resources-root-path");
|
args_parser.add_option(resources_folder, "Path of the base resources folder (defaults to /res)", "resources", 'r', "resources-root-path");
|
||||||
|
@ -626,6 +640,7 @@ struct Application : public WebView::Application {
|
||||||
bool is_layout_test_mode { false };
|
bool is_layout_test_mode { false };
|
||||||
StringView test_root_path;
|
StringView test_root_path;
|
||||||
ByteString test_glob;
|
ByteString test_glob;
|
||||||
|
bool test_dry_run { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
Application::Application(Badge<WebView::Application>, Main::Arguments&)
|
Application::Application(Badge<WebView::Application>, Main::Arguments&)
|
||||||
|
@ -646,13 +661,17 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
// FIXME: Allow passing the window size as an argument.
|
// FIXME: Allow passing the window size as an argument.
|
||||||
static constexpr Gfx::IntSize window_size { 800, 600 };
|
static constexpr Gfx::IntSize window_size { 800, 600 };
|
||||||
|
|
||||||
auto view = TRY(HeadlessWebContentView::create(move(theme), window_size, app->resources_folder));
|
|
||||||
|
|
||||||
if (!app->test_root_path.is_empty()) {
|
if (!app->test_root_path.is_empty()) {
|
||||||
|
OwnPtr<HeadlessWebContentView> view;
|
||||||
|
if (!app->test_dry_run)
|
||||||
|
view = TRY(HeadlessWebContentView::create(move(theme), window_size, app->resources_folder));
|
||||||
|
|
||||||
auto test_glob = ByteString::formatted("*{}*", app->test_glob);
|
auto test_glob = ByteString::formatted("*{}*", app->test_glob);
|
||||||
return run_tests(*view, app->test_root_path, test_glob, app->dump_failed_ref_tests, app->dump_gc_graph);
|
return run_tests(view, app->test_root_path, test_glob, app->dump_failed_ref_tests, app->dump_gc_graph, app->test_dry_run);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto view = TRY(HeadlessWebContentView::create(move(theme), window_size, app->resources_folder));
|
||||||
|
|
||||||
VERIFY(!WebView::Application::chrome_options().urls.is_empty());
|
VERIFY(!WebView::Application::chrome_options().urls.is_empty());
|
||||||
auto const& url = WebView::Application::chrome_options().urls.first();
|
auto const& url = WebView::Application::chrome_options().urls.first();
|
||||||
if (!url.is_valid()) {
|
if (!url.is_valid()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue