mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:37:46 +00:00
test-js: Sometimes include more details for failures
LibJS doesn't store stacks for exception objects, so this only amends test-common.js's __expect() with an optional `details` function that can produce a more detailed error message, and it lets test-js.cpp read and print that error message. I added the optional details parameter to a few matchers, most notably toBe() where it now prints expected and actual value. It'd be nice to have line numbers of failures, but that seems hard to do with the current design, and this is already much better than the current state.
This commit is contained in:
parent
3fbb02c3cc
commit
96891669c3
2 changed files with 26 additions and 14 deletions
|
@ -52,6 +52,7 @@ enum class TestResult {
|
|||
struct JSTest {
|
||||
String name;
|
||||
TestResult result;
|
||||
String details;
|
||||
};
|
||||
|
||||
struct JSSuite {
|
||||
|
@ -281,7 +282,7 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
|||
ASSERT(suite_value.is_object());
|
||||
|
||||
suite_value.as_object().for_each_member([&](const String& test_name, const JsonValue& test_value) {
|
||||
JSTest test { test_name, TestResult::Fail };
|
||||
JSTest test { test_name, TestResult::Fail, "" };
|
||||
|
||||
ASSERT(test_value.is_object());
|
||||
ASSERT(test_value.as_object().has("result"));
|
||||
|
@ -296,6 +297,10 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
|||
test.result = TestResult::Fail;
|
||||
m_counts.tests_failed++;
|
||||
suite.most_severe_test_result = TestResult::Fail;
|
||||
ASSERT(test_value.as_object().has("details"));
|
||||
auto details = test_value.as_object().get("details");
|
||||
ASSERT(result.is_string());
|
||||
test.details = details.as_string();
|
||||
} else {
|
||||
test.result = TestResult::Skip;
|
||||
if (suite.most_severe_test_result == TestResult::Pass)
|
||||
|
@ -476,7 +481,8 @@ void TestRunner::print_file_result(const JSFileResult& file_result) const
|
|||
printf(" Test: ");
|
||||
if (test.result == TestResult::Fail) {
|
||||
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());
|
||||
} else {
|
||||
print_modifiers({ CLEAR, FG_ORANGE });
|
||||
printf("%s (skipped)\n", test.name.characters());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue