mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
Tests: Don't use TestRunners after their scope ends in test-js
The TestRunner objects at the end of test-js are destroyed after the if/else that chooses whether to run the 262 parser tests or the standard tests. Accessing TestRunner::the() after the lifetime of the TestRunners ends is UB, so return the Test::Counts from run() instead. Also, fix the destructor of TestRunner to set s_the to nullptr so that if anyone tries this type of shenanigains again, they'll get a crash :^).
This commit is contained in:
parent
f90a19ba4c
commit
e96451edc9
Notes:
sideshowbarker
2024-07-18 18:11:08 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/e96451edc93 Pull-request: https://github.com/SerenityOS/serenity/pull/7060 Issue: https://github.com/SerenityOS/serenity/issues/4592
1 changed files with 9 additions and 6 deletions
|
@ -79,9 +79,9 @@ public:
|
|||
s_the = this;
|
||||
}
|
||||
|
||||
virtual ~TestRunner() = default;
|
||||
virtual ~TestRunner() { s_the = nullptr; };
|
||||
|
||||
void run();
|
||||
Test::Counts run();
|
||||
|
||||
const Test::Counts& counts() const { return m_counts; }
|
||||
|
||||
|
@ -197,7 +197,7 @@ Vector<String> TestRunner::get_test_paths() const
|
|||
return paths;
|
||||
}
|
||||
|
||||
void TestRunner::run()
|
||||
Test::Counts TestRunner::run()
|
||||
{
|
||||
size_t progress_counter = 0;
|
||||
auto test_paths = get_test_paths();
|
||||
|
@ -212,6 +212,8 @@ void TestRunner::run()
|
|||
warn("\033]9;-1;\033\\");
|
||||
|
||||
print_test_results();
|
||||
|
||||
return m_counts;
|
||||
}
|
||||
|
||||
static Result<NonnullRefPtr<JS::Program>, ParserError> parse_file(const String& file_path)
|
||||
|
@ -739,12 +741,13 @@ int main(int argc, char** argv)
|
|||
|
||||
vm = JS::VM::create();
|
||||
|
||||
Test::Counts result_counts;
|
||||
if (test262_parser_tests)
|
||||
Test262ParserTestRunner(test_root, print_times, print_progress).run();
|
||||
result_counts = Test262ParserTestRunner(test_root, print_times, print_progress).run();
|
||||
else
|
||||
TestRunner(test_root, print_times, print_progress).run();
|
||||
result_counts = TestRunner(test_root, print_times, print_progress).run();
|
||||
|
||||
vm = nullptr;
|
||||
|
||||
return TestRunner::the()->counts().tests_failed > 0 ? 1 : 0;
|
||||
return result_counts.tests_failed > 0 ? 1 : 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue