mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
test-js: Catch SIGINFO and dump the current test name + pass/fail/skip
This is pretty handy if the JS tests take a long time to run and you wonder what they're doing. :^)
This commit is contained in:
parent
f8e59addf7
commit
606f83436d
1 changed files with 25 additions and 0 deletions
|
@ -44,6 +44,7 @@
|
||||||
#define TOP_LEVEL_TEST_NAME "__$$TOP_LEVEL$$__"
|
#define TOP_LEVEL_TEST_NAME "__$$TOP_LEVEL$$__"
|
||||||
|
|
||||||
static bool collect_on_every_allocation = false;
|
static bool collect_on_every_allocation = false;
|
||||||
|
static String currently_running_test;
|
||||||
|
|
||||||
enum class TestResult {
|
enum class TestResult {
|
||||||
Pass,
|
Pass,
|
||||||
|
@ -105,15 +106,26 @@ private:
|
||||||
|
|
||||||
class TestRunner {
|
class TestRunner {
|
||||||
public:
|
public:
|
||||||
|
static TestRunner* the()
|
||||||
|
{
|
||||||
|
return s_the;
|
||||||
|
}
|
||||||
|
|
||||||
TestRunner(String test_root, bool print_times)
|
TestRunner(String test_root, bool print_times)
|
||||||
: m_test_root(move(test_root))
|
: m_test_root(move(test_root))
|
||||||
, m_print_times(print_times)
|
, m_print_times(print_times)
|
||||||
{
|
{
|
||||||
|
ASSERT(!s_the);
|
||||||
|
s_the = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
const JSTestRunnerCounts& counts() const { return m_counts; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static TestRunner* s_the;
|
||||||
|
|
||||||
JSFileResult run_file_test(const String& test_path);
|
JSFileResult run_file_test(const String& test_path);
|
||||||
void print_file_result(const JSFileResult& file_result) const;
|
void print_file_result(const JSFileResult& file_result) const;
|
||||||
void print_test_results() const;
|
void print_test_results() const;
|
||||||
|
@ -127,6 +139,8 @@ private:
|
||||||
RefPtr<JS::Program> m_test_program;
|
RefPtr<JS::Program> m_test_program;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TestRunner* TestRunner::s_the = nullptr;
|
||||||
|
|
||||||
TestRunnerGlobalObject::TestRunnerGlobalObject()
|
TestRunnerGlobalObject::TestRunnerGlobalObject()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -256,6 +270,8 @@ static Optional<JsonValue> get_test_results(JS::Interpreter& interpreter)
|
||||||
|
|
||||||
JSFileResult TestRunner::run_file_test(const String& test_path)
|
JSFileResult TestRunner::run_file_test(const String& test_path)
|
||||||
{
|
{
|
||||||
|
currently_running_test = test_path;
|
||||||
|
|
||||||
double start_time = get_time_in_ms();
|
double start_time = get_time_in_ms();
|
||||||
auto interpreter = JS::Interpreter::create<TestRunnerGlobalObject>();
|
auto interpreter = JS::Interpreter::create<TestRunnerGlobalObject>();
|
||||||
|
|
||||||
|
@ -569,6 +585,15 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SIGINFO
|
||||||
|
signal(SIGINFO, [](int) {
|
||||||
|
static char buffer[4096];
|
||||||
|
auto& counts = TestRunner::the()->counts();
|
||||||
|
int len = snprintf(buffer, sizeof(buffer), "Pass: %d, Fail: %d, Skip: %d\nCurrent test: %s\n", counts.tests_passed, counts.tests_failed, counts.tests_skipped, currently_running_test.characters());
|
||||||
|
write(STDOUT_FILENO, buffer, len);
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_option(print_times, "Show duration of each test", "show-time", 't');
|
args_parser.add_option(print_times, "Show duration of each test", "show-time", 't');
|
||||||
args_parser.add_option(collect_on_every_allocation, "Collect garbage after every allocation", "collect-often", 'g');
|
args_parser.add_option(collect_on_every_allocation, "Collect garbage after every allocation", "collect-often", 'g');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue