mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
test-web: Utilize new LibTest types from test-web
test-web has alot of similar code to test-js, so re-use some of the types we already pulled out into LibTest.
This commit is contained in:
parent
0a49877fdc
commit
e60d394b32
1 changed files with 22 additions and 41 deletions
|
@ -41,6 +41,7 @@
|
||||||
#include <LibJS/Parser.h>
|
#include <LibJS/Parser.h>
|
||||||
#include <LibJS/Runtime/Array.h>
|
#include <LibJS/Runtime/Array.h>
|
||||||
#include <LibJS/Runtime/JSONObject.h>
|
#include <LibJS/Runtime/JSONObject.h>
|
||||||
|
#include <LibTest/Results.h>
|
||||||
#include <LibWeb/HTML/Parser/HTMLDocumentParser.h>
|
#include <LibWeb/HTML/Parser/HTMLDocumentParser.h>
|
||||||
#include <LibWeb/InProcessWebView.h>
|
#include <LibWeb/InProcessWebView.h>
|
||||||
#include <LibWeb/Loader/ResourceLoader.h>
|
#include <LibWeb/Loader/ResourceLoader.h>
|
||||||
|
@ -49,26 +50,6 @@
|
||||||
|
|
||||||
#define TOP_LEVEL_TEST_NAME "__$$TOP_LEVEL$$__"
|
#define TOP_LEVEL_TEST_NAME "__$$TOP_LEVEL$$__"
|
||||||
|
|
||||||
enum class TestResult {
|
|
||||||
Pass,
|
|
||||||
Fail,
|
|
||||||
Skip,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct JSTest {
|
|
||||||
String name;
|
|
||||||
TestResult result;
|
|
||||||
String details;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct JSSuite {
|
|
||||||
String name;
|
|
||||||
// A failed test takes precedence over a skipped test, which both have
|
|
||||||
// precedence over a passed test
|
|
||||||
TestResult most_severe_test_result { TestResult::Pass };
|
|
||||||
Vector<JSTest> tests {};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ParserError {
|
struct ParserError {
|
||||||
JS::Parser::Error error;
|
JS::Parser::Error error;
|
||||||
String hint;
|
String hint;
|
||||||
|
@ -80,8 +61,8 @@ struct JSFileResult {
|
||||||
double time_taken { 0 };
|
double time_taken { 0 };
|
||||||
// A failed test takes precedence over a skipped test, which both have
|
// A failed test takes precedence over a skipped test, which both have
|
||||||
// precedence over a passed test
|
// precedence over a passed test
|
||||||
TestResult most_severe_test_result { TestResult::Pass };
|
Test::Result most_severe_test_result { Test::Result::Pass };
|
||||||
Vector<JSSuite> suites {};
|
Vector<Test::Suite> suites {};
|
||||||
Vector<String> logged_messages {};
|
Vector<String> logged_messages {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -394,12 +375,12 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
test_json.value().as_object().for_each_member([&](const String& suite_name, const JsonValue& suite_value) {
|
test_json.value().as_object().for_each_member([&](const String& suite_name, const JsonValue& suite_value) {
|
||||||
JSSuite suite { suite_name };
|
Test::Suite suite { suite_name };
|
||||||
|
|
||||||
VERIFY(suite_value.is_object());
|
VERIFY(suite_value.is_object());
|
||||||
|
|
||||||
suite_value.as_object().for_each_member([&](const String& test_name, const JsonValue& test_value) {
|
suite_value.as_object().for_each_member([&](const String& test_name, const JsonValue& test_value) {
|
||||||
JSTest test { test_name, TestResult::Fail, "" };
|
Test::Case test { test_name, Test::Result::Fail, "" };
|
||||||
|
|
||||||
VERIFY(test_value.is_object());
|
VERIFY(test_value.is_object());
|
||||||
VERIFY(test_value.as_object().has("result"));
|
VERIFY(test_value.as_object().has("result"));
|
||||||
|
@ -408,32 +389,32 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
||||||
VERIFY(result.is_string());
|
VERIFY(result.is_string());
|
||||||
auto result_string = result.as_string();
|
auto result_string = result.as_string();
|
||||||
if (result_string == "pass") {
|
if (result_string == "pass") {
|
||||||
test.result = TestResult::Pass;
|
test.result = Test::Result::Pass;
|
||||||
m_counts.tests_passed++;
|
m_counts.tests_passed++;
|
||||||
} else if (result_string == "fail") {
|
} else if (result_string == "fail") {
|
||||||
test.result = TestResult::Fail;
|
test.result = Test::Result::Fail;
|
||||||
m_counts.tests_failed++;
|
m_counts.tests_failed++;
|
||||||
suite.most_severe_test_result = TestResult::Fail;
|
suite.most_severe_test_result = Test::Result::Fail;
|
||||||
VERIFY(test_value.as_object().has("details"));
|
VERIFY(test_value.as_object().has("details"));
|
||||||
auto details = test_value.as_object().get("details");
|
auto details = test_value.as_object().get("details");
|
||||||
VERIFY(result.is_string());
|
VERIFY(result.is_string());
|
||||||
test.details = details.as_string();
|
test.details = details.as_string();
|
||||||
} else {
|
} else {
|
||||||
test.result = TestResult::Skip;
|
test.result = Test::Result::Skip;
|
||||||
if (suite.most_severe_test_result == TestResult::Pass)
|
if (suite.most_severe_test_result == Test::Result::Pass)
|
||||||
suite.most_severe_test_result = TestResult::Skip;
|
suite.most_severe_test_result = Test::Result::Skip;
|
||||||
m_counts.tests_skipped++;
|
m_counts.tests_skipped++;
|
||||||
}
|
}
|
||||||
|
|
||||||
suite.tests.append(test);
|
suite.tests.append(test);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (suite.most_severe_test_result == TestResult::Fail) {
|
if (suite.most_severe_test_result == Test::Result::Fail) {
|
||||||
m_counts.suites_failed++;
|
m_counts.suites_failed++;
|
||||||
file_result.most_severe_test_result = TestResult::Fail;
|
file_result.most_severe_test_result = Test::Result::Fail;
|
||||||
} else {
|
} else {
|
||||||
if (suite.most_severe_test_result == TestResult::Skip && file_result.most_severe_test_result == TestResult::Pass)
|
if (suite.most_severe_test_result == Test::Result::Skip && file_result.most_severe_test_result == Test::Result::Pass)
|
||||||
file_result.most_severe_test_result = TestResult::Skip;
|
file_result.most_severe_test_result = Test::Result::Skip;
|
||||||
m_counts.suites_passed++;
|
m_counts.suites_passed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,12 +481,12 @@ static void print_modifiers(Vector<Modifier> modifiers)
|
||||||
|
|
||||||
void TestRunner::print_file_result(const JSFileResult& file_result) const
|
void TestRunner::print_file_result(const JSFileResult& file_result) const
|
||||||
{
|
{
|
||||||
if (file_result.most_severe_test_result == TestResult::Fail || file_result.error.has_value()) {
|
if (file_result.most_severe_test_result == Test::Result::Fail || file_result.error.has_value()) {
|
||||||
print_modifiers({ BG_RED, FG_BLACK, FG_BOLD });
|
print_modifiers({ BG_RED, FG_BLACK, FG_BOLD });
|
||||||
printf(" FAIL ");
|
printf(" FAIL ");
|
||||||
print_modifiers({ CLEAR });
|
print_modifiers({ CLEAR });
|
||||||
} else {
|
} else {
|
||||||
if (m_print_times || file_result.most_severe_test_result != TestResult::Pass) {
|
if (m_print_times || file_result.most_severe_test_result != Test::Result::Pass) {
|
||||||
print_modifiers({ BG_GREEN, FG_BLACK, FG_BOLD });
|
print_modifiers({ BG_GREEN, FG_BLACK, FG_BOLD });
|
||||||
printf(" PASS ");
|
printf(" PASS ");
|
||||||
print_modifiers({ CLEAR });
|
print_modifiers({ CLEAR });
|
||||||
|
@ -561,12 +542,12 @@ void TestRunner::print_file_result(const JSFileResult& file_result) const
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_result.most_severe_test_result != TestResult::Pass) {
|
if (file_result.most_severe_test_result != Test::Result::Pass) {
|
||||||
for (auto& suite : file_result.suites) {
|
for (auto& suite : file_result.suites) {
|
||||||
if (suite.most_severe_test_result == TestResult::Pass)
|
if (suite.most_severe_test_result == Test::Result::Pass)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool failed = suite.most_severe_test_result == TestResult::Fail;
|
bool failed = suite.most_severe_test_result == Test::Result::Fail;
|
||||||
|
|
||||||
print_modifiers({ FG_GRAY, FG_BOLD });
|
print_modifiers({ FG_GRAY, FG_BOLD });
|
||||||
|
|
||||||
|
@ -596,12 +577,12 @@ void TestRunner::print_file_result(const JSFileResult& file_result) const
|
||||||
print_modifiers({ CLEAR });
|
print_modifiers({ CLEAR });
|
||||||
|
|
||||||
for (auto& test : suite.tests) {
|
for (auto& test : suite.tests) {
|
||||||
if (test.result == TestResult::Pass)
|
if (test.result == Test::Result::Pass)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
print_modifiers({ FG_GRAY, FG_BOLD });
|
print_modifiers({ FG_GRAY, FG_BOLD });
|
||||||
printf(" Test: ");
|
printf(" Test: ");
|
||||||
if (test.result == TestResult::Fail) {
|
if (test.result == Test::Result::Fail) {
|
||||||
print_modifiers({ CLEAR, FG_RED });
|
print_modifiers({ CLEAR, FG_RED });
|
||||||
printf("%s (failed):\n", test.name.characters());
|
printf("%s (failed):\n", test.name.characters());
|
||||||
printf(" %s\n", test.details.characters());
|
printf(" %s\n", test.details.characters());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue