mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-23 04:55:15 +00:00
test-js+test-web: Clear taskbar progress on error/assertion failure
Closes #3240
This commit is contained in:
parent
f88b2b064c
commit
5877d6713c
Notes:
sideshowbarker
2024-07-19 03:16:02 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/5877d6713cd Pull-request: https://github.com/SerenityOS/serenity/pull/3266 Issue: https://github.com/SerenityOS/serenity/issues/3240
2 changed files with 63 additions and 11 deletions
|
@ -38,6 +38,7 @@
|
|||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/JSONObject.h>
|
||||
#include <LibJS/Runtime/MarkedValueList.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
@ -145,6 +146,21 @@ JS_DEFINE_NATIVE_FUNCTION(TestRunnerGlobalObject::is_strict_mode)
|
|||
return JS::Value(interpreter.in_strict_mode());
|
||||
}
|
||||
|
||||
static void cleanup_and_exit()
|
||||
{
|
||||
// Clear the taskbar progress.
|
||||
#ifdef __serenity__
|
||||
fprintf(stderr, "\033]9;-1;\033\\");
|
||||
#endif
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void handle_sigabrt(int)
|
||||
{
|
||||
dbg() << "test-js: SIGABRT received, cleaning up.";
|
||||
cleanup_and_exit();
|
||||
}
|
||||
|
||||
static double get_time_in_ms()
|
||||
{
|
||||
struct timeval tv1;
|
||||
|
@ -208,7 +224,7 @@ static Result<NonnullRefPtr<JS::Program>, ParserError> parse_file(const String&
|
|||
auto result = file->open(Core::IODevice::ReadOnly);
|
||||
if (!result) {
|
||||
printf("Failed to open the following file: \"%s\"\n", file_path.characters());
|
||||
exit(1);
|
||||
cleanup_and_exit();
|
||||
}
|
||||
|
||||
auto contents = file->read_all();
|
||||
|
@ -249,7 +265,7 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
|||
printf("Unable to parse test-common.js\n");
|
||||
printf("%s\n", result.error().error.to_string().characters());
|
||||
printf("%s\n", result.error().hint.characters());
|
||||
exit(1);
|
||||
cleanup_and_exit();;
|
||||
}
|
||||
m_test_program = result.value();
|
||||
}
|
||||
|
@ -264,7 +280,7 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
|||
auto test_json = get_test_results(*interpreter);
|
||||
if (!test_json.has_value()) {
|
||||
printf("Received malformed JSON from test \"%s\"\n", test_path.characters());
|
||||
exit(1);
|
||||
cleanup_and_exit();
|
||||
}
|
||||
|
||||
JSFileResult file_result { test_path.substring(m_test_root.length() + 1, test_path.length() - m_test_root.length() - 1) };
|
||||
|
@ -540,6 +556,16 @@ int main(int argc, char** argv)
|
|||
{
|
||||
bool print_times = false;
|
||||
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_flags = SA_NOCLDWAIT;
|
||||
act.sa_handler = handle_sigabrt;
|
||||
int rc = sigaction(SIGABRT, &act, nullptr);
|
||||
if (rc < 0) {
|
||||
perror("sigaction");
|
||||
return 1;
|
||||
}
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(print_times, "Show duration of each test", "show-time", 't');
|
||||
args_parser.parse(argc, argv);
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include <LibWeb/HTML/Parser/HTMLDocumentParser.h>
|
||||
#include <LibWeb/Loader/ResourceLoader.h>
|
||||
#include <LibWeb/InProcessWebView.h>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define TOP_LEVEL_TEST_NAME "__$$TOP_LEVEL$$__"
|
||||
|
@ -164,6 +165,21 @@ private:
|
|||
RefPtr<JS::Program> m_web_test_common;
|
||||
};
|
||||
|
||||
static void cleanup_and_exit()
|
||||
{
|
||||
// Clear the taskbar progress.
|
||||
#ifdef __serenity__
|
||||
fprintf(stderr, "\033]9;-1;\033\\");
|
||||
#endif
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void handle_sigabrt(int)
|
||||
{
|
||||
dbg() << "test-web: SIGABRT received, cleaning up.";
|
||||
cleanup_and_exit();
|
||||
}
|
||||
|
||||
static double get_time_in_ms()
|
||||
{
|
||||
struct timeval tv1;
|
||||
|
@ -210,7 +226,7 @@ void TestRunner::run()
|
|||
g_on_page_change = [this](auto& page_to_load) {
|
||||
if (!page_to_load.is_valid()) {
|
||||
printf("Invalid page URL (%s) on page change", page_to_load.to_string().characters());
|
||||
exit(1);
|
||||
cleanup_and_exit();
|
||||
}
|
||||
|
||||
ASSERT(m_page_view->document());
|
||||
|
@ -228,7 +244,7 @@ void TestRunner::run()
|
|||
},
|
||||
[page_to_load](auto error) {
|
||||
printf("Failed to load test page: %s (%s)", page_to_load.to_string().characters(), error.characters());
|
||||
exit(1);
|
||||
cleanup_and_exit();
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -253,7 +269,7 @@ static Result<NonnullRefPtr<JS::Program>, ParserError> parse_file(const String&
|
|||
auto result = file->open(Core::IODevice::ReadOnly);
|
||||
if (!result) {
|
||||
printf("Failed to open the following file: \"%s\"\n", file_path.characters());
|
||||
exit(1);
|
||||
cleanup_and_exit();
|
||||
}
|
||||
|
||||
auto contents = file->read_all();
|
||||
|
@ -293,7 +309,7 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
|||
auto result = parse_file(String::format("%s/test-common.js", m_js_test_root.characters()));
|
||||
if (result.is_error()) {
|
||||
printf("Unable to parse %s/test-common.js", m_js_test_root.characters());
|
||||
exit(1);
|
||||
cleanup_and_exit();
|
||||
}
|
||||
m_js_test_common = result.value();
|
||||
}
|
||||
|
@ -302,7 +318,7 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
|||
auto result = parse_file(String::format("%s/test-common.js", m_web_test_root.characters()));
|
||||
if (result.is_error()) {
|
||||
printf("Unable to parse %s/test-common.js", m_web_test_root.characters());
|
||||
exit(1);
|
||||
cleanup_and_exit();
|
||||
}
|
||||
m_web_test_common = result.value();
|
||||
}
|
||||
|
@ -317,7 +333,7 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
|||
auto page_to_load = URL(old_interpreter.get_variable("__PageToLoad__", old_interpreter.global_object()).as_string().string());
|
||||
if (!page_to_load.is_valid()) {
|
||||
printf("Invalid page URL for %s", test_path.characters());
|
||||
exit(1);
|
||||
cleanup_and_exit();
|
||||
}
|
||||
|
||||
JSFileResult file_result;
|
||||
|
@ -356,7 +372,7 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
|||
auto test_json = get_test_results(new_interpreter);
|
||||
if (!test_json.has_value()) {
|
||||
printf("Received malformed JSON from test \"%s\"\n", test_path.characters());
|
||||
exit(1);
|
||||
cleanup_and_exit();
|
||||
}
|
||||
|
||||
file_result = { test_path.substring(m_web_test_root.length() + 1, test_path.length() - m_web_test_root.length() - 1) };
|
||||
|
@ -418,7 +434,7 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
|||
},
|
||||
[page_to_load](auto error) {
|
||||
printf("Failed to load test page: %s (%s)", page_to_load.to_string().characters(), error.characters());
|
||||
exit(1);
|
||||
cleanup_and_exit();
|
||||
});
|
||||
|
||||
return file_result;
|
||||
|
@ -633,6 +649,16 @@ int main(int argc, char** argv)
|
|||
bool print_times = false;
|
||||
bool show_window = false;
|
||||
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_flags = SA_NOCLDWAIT;
|
||||
act.sa_handler = handle_sigabrt;
|
||||
int rc = sigaction(SIGABRT, &act, nullptr);
|
||||
if (rc < 0) {
|
||||
perror("sigaction");
|
||||
return 1;
|
||||
}
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(print_times, "Show duration of each test", "show-time", 't');
|
||||
args_parser.add_option(show_window, "Show window while running tests", "window", 'w');
|
||||
|
|
Loading…
Add table
Reference in a new issue