JavaScriptTestRunner.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /*
  2. * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
  3. * Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
  4. * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
  5. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  6. * Copyright (c) 2023, Shannon Booth <shannon@serenityos.org>
  7. *
  8. * SPDX-License-Identifier: BSD-2-Clause
  9. */
  10. #pragma once
  11. #include <AK/ByteBuffer.h>
  12. #include <AK/JsonObject.h>
  13. #include <AK/JsonValue.h>
  14. #include <AK/LexicalPath.h>
  15. #include <AK/QuickSort.h>
  16. #include <AK/Result.h>
  17. #include <AK/Tuple.h>
  18. #include <LibCore/DirIterator.h>
  19. #include <LibCore/File.h>
  20. #include <LibJS/Bytecode/Interpreter.h>
  21. #include <LibJS/Lexer.h>
  22. #include <LibJS/Parser.h>
  23. #include <LibJS/Runtime/Array.h>
  24. #include <LibJS/Runtime/GlobalObject.h>
  25. #include <LibJS/Runtime/JSONObject.h>
  26. #include <LibJS/Runtime/TypedArray.h>
  27. #include <LibJS/Runtime/WeakMap.h>
  28. #include <LibJS/Runtime/WeakSet.h>
  29. #include <LibJS/Script.h>
  30. #include <LibJS/SourceTextModule.h>
  31. #include <LibTest/Results.h>
  32. #include <LibTest/TestRunner.h>
  33. #include <fcntl.h>
  34. #include <sys/time.h>
  35. #include <unistd.h>
  36. #ifdef AK_OS_SERENITY
  37. # include <serenity.h>
  38. #endif
  39. #define STRCAT(x, y) __STRCAT(x, y)
  40. #define STRSTRCAT(x, y) __STRSTRCAT(x, y)
  41. #define __STRCAT(x, y) x #y
  42. #define __STRSTRCAT(x, y) x y
  43. // Note: This is a little weird, so here's an explanation:
  44. // If the vararg isn't given, the tuple initializer will simply expand to `fn, ::Test::JS::__testjs_last<1>()`
  45. // and if it _is_ given (say as `A`), the tuple initializer will expand to `fn, ::Test::JS::__testjs_last<1, A>()`, which will end up being evaluated as `A`
  46. // and if multiple args are given, the static_assert will be sad.
  47. #define __TESTJS_REGISTER_GLOBAL_FUNCTION(name, fn, ...) \
  48. struct __TestJS_register_##fn { \
  49. static_assert( \
  50. ::Test::JS::__testjs_count(__VA_ARGS__) <= 1, \
  51. STRCAT(STRSTRCAT(STRCAT("Expected at most three arguments to TESTJS_GLOBAL_FUNCTION at line", __LINE__), ", in file "), __FILE__)); \
  52. __TestJS_register_##fn() noexcept \
  53. { \
  54. ::Test::JS::s_exposed_global_functions.set( \
  55. name, \
  56. { fn, ::Test::JS::__testjs_last<1, ##__VA_ARGS__>() }); \
  57. } \
  58. } __testjs_register_##fn {};
  59. #define TESTJS_GLOBAL_FUNCTION(function, exposed_name, ...) \
  60. JS_DECLARE_NATIVE_FUNCTION(function); \
  61. __TESTJS_REGISTER_GLOBAL_FUNCTION(#exposed_name, function, ##__VA_ARGS__); \
  62. JS_DEFINE_NATIVE_FUNCTION(function)
  63. #define TESTJS_MAIN_HOOK() \
  64. struct __TestJS_main_hook { \
  65. __TestJS_main_hook() \
  66. { \
  67. ::Test::JS::g_main_hook = hook; \
  68. } \
  69. static void hook(); \
  70. } __testjs_common_register_##name {}; \
  71. void __TestJS_main_hook::hook()
  72. #define TESTJS_PROGRAM_FLAG(flag, help_string, long_name, short_name) \
  73. bool flag { false }; \
  74. struct __TestJS_flag_hook_##flag { \
  75. __TestJS_flag_hook_##flag() \
  76. { \
  77. ::Test::JS::g_extra_args.set(&(flag), { help_string, long_name, short_name }); \
  78. } \
  79. } __testjs_flag_hook_##flag;
  80. #define TEST_ROOT(path) \
  81. DeprecatedString Test::JS::g_test_root_fragment = path
  82. #define TESTJS_RUN_FILE_FUNCTION(...) \
  83. struct __TestJS_run_file { \
  84. __TestJS_run_file() \
  85. { \
  86. ::Test::JS::g_run_file = hook; \
  87. } \
  88. static ::Test::JS::IntermediateRunFileResult hook(DeprecatedString const&, JS::Realm&, JS::ExecutionContext&); \
  89. } __testjs_common_run_file {}; \
  90. ::Test::JS::IntermediateRunFileResult __TestJS_run_file::hook(__VA_ARGS__)
  91. namespace Test::JS {
  92. namespace JS = ::JS;
  93. template<typename... Args>
  94. static consteval size_t __testjs_count(Args...) { return sizeof...(Args); }
  95. template<auto... Values>
  96. static consteval size_t __testjs_last()
  97. {
  98. Array values { Values... };
  99. return values[values.size() - 1U];
  100. }
  101. static constexpr auto TOP_LEVEL_TEST_NAME = "__$$TOP_LEVEL$$__";
  102. extern RefPtr<JS::VM> g_vm;
  103. extern bool g_collect_on_every_allocation;
  104. extern DeprecatedString g_currently_running_test;
  105. struct FunctionWithLength {
  106. JS::ThrowCompletionOr<JS::Value> (*function)(JS::VM&);
  107. size_t length { 0 };
  108. };
  109. extern HashMap<DeprecatedString, FunctionWithLength> s_exposed_global_functions;
  110. extern DeprecatedString g_test_root_fragment;
  111. extern DeprecatedString g_test_root;
  112. extern int g_test_argc;
  113. extern char** g_test_argv;
  114. extern Function<void()> g_main_hook;
  115. extern HashMap<bool*, Tuple<DeprecatedString, DeprecatedString, char>> g_extra_args;
  116. struct ParserError {
  117. JS::ParserError error;
  118. DeprecatedString hint;
  119. };
  120. struct JSFileResult {
  121. DeprecatedString name;
  122. Optional<ParserError> error {};
  123. double time_taken { 0 };
  124. // A failed test takes precedence over a skipped test, which both have
  125. // precedence over a passed test
  126. Test::Result most_severe_test_result { Test::Result::Pass };
  127. Vector<Test::Suite> suites {};
  128. Vector<DeprecatedString> logged_messages {};
  129. };
  130. enum class RunFileHookResult {
  131. RunAsNormal,
  132. SkipFile,
  133. };
  134. using IntermediateRunFileResult = AK::Result<JSFileResult, RunFileHookResult>;
  135. extern IntermediateRunFileResult (*g_run_file)(DeprecatedString const&, JS::Realm&, JS::ExecutionContext&);
  136. class TestRunner : public ::Test::TestRunner {
  137. public:
  138. TestRunner(DeprecatedString test_root, DeprecatedString common_path, bool print_times, bool print_progress, bool print_json, bool detailed_json)
  139. : ::Test::TestRunner(move(test_root), print_times, print_progress, print_json, detailed_json)
  140. , m_common_path(move(common_path))
  141. {
  142. g_test_root = m_test_root;
  143. }
  144. virtual ~TestRunner() = default;
  145. protected:
  146. virtual void do_run_single_test(DeprecatedString const& test_path, size_t, size_t) override;
  147. virtual Vector<DeprecatedString> get_test_paths() const override;
  148. virtual JSFileResult run_file_test(DeprecatedString const& test_path);
  149. void print_file_result(JSFileResult const& file_result) const;
  150. DeprecatedString m_common_path;
  151. };
  152. class TestRunnerGlobalObject final : public JS::GlobalObject {
  153. JS_OBJECT(TestRunnerGlobalObject, JS::GlobalObject);
  154. public:
  155. TestRunnerGlobalObject(JS::Realm& realm)
  156. : JS::GlobalObject(realm)
  157. {
  158. }
  159. virtual void initialize(JS::Realm&) override;
  160. virtual ~TestRunnerGlobalObject() override = default;
  161. };
  162. inline void TestRunnerGlobalObject::initialize(JS::Realm& realm)
  163. {
  164. Base::initialize(realm);
  165. define_direct_property("global", this, JS::Attribute::Enumerable);
  166. for (auto& entry : s_exposed_global_functions) {
  167. define_native_function(
  168. realm,
  169. entry.key, [fn = entry.value.function](auto& vm) {
  170. return fn(vm);
  171. },
  172. entry.value.length, JS::default_attributes);
  173. }
  174. }
  175. inline ByteBuffer load_entire_file(StringView path)
  176. {
  177. auto try_load_entire_file = [](StringView const& path) -> ErrorOr<ByteBuffer> {
  178. auto file = TRY(Core::File::open(path, Core::File::OpenMode::Read));
  179. auto file_size = TRY(file->size());
  180. auto content = TRY(ByteBuffer::create_uninitialized(file_size));
  181. TRY(file->read_until_filled(content.bytes()));
  182. return content;
  183. };
  184. auto buffer_or_error = try_load_entire_file(path);
  185. if (buffer_or_error.is_error()) {
  186. warnln("Failed to open the following file: \"{}\", error: {}", path, buffer_or_error.release_error());
  187. cleanup_and_exit();
  188. }
  189. return buffer_or_error.release_value();
  190. }
  191. inline AK::Result<JS::NonnullGCPtr<JS::Script>, ParserError> parse_script(StringView path, JS::Realm& realm)
  192. {
  193. auto contents = load_entire_file(path);
  194. auto script_or_errors = JS::Script::parse(contents, realm, path);
  195. if (script_or_errors.is_error()) {
  196. auto errors = script_or_errors.release_error();
  197. return ParserError { errors[0], errors[0].source_location_hint(contents) };
  198. }
  199. return script_or_errors.release_value();
  200. }
  201. inline AK::Result<JS::NonnullGCPtr<JS::SourceTextModule>, ParserError> parse_module(StringView path, JS::Realm& realm)
  202. {
  203. auto contents = load_entire_file(path);
  204. auto script_or_errors = JS::SourceTextModule::parse(contents, realm, path);
  205. if (script_or_errors.is_error()) {
  206. auto errors = script_or_errors.release_error();
  207. return ParserError { errors[0], errors[0].source_location_hint(contents) };
  208. }
  209. return script_or_errors.release_value();
  210. }
  211. inline ErrorOr<JsonValue> get_test_results(JS::Realm& realm)
  212. {
  213. auto results = MUST(realm.global_object().get("__TestResults__"));
  214. auto maybe_json_string = MUST(JS::JSONObject::stringify_impl(*g_vm, results, JS::js_undefined(), JS::js_undefined()));
  215. if (maybe_json_string.has_value())
  216. return JsonValue::from_string(*maybe_json_string);
  217. return JsonValue();
  218. }
  219. inline void TestRunner::do_run_single_test(DeprecatedString const& test_path, size_t, size_t)
  220. {
  221. auto file_result = run_file_test(test_path);
  222. if (!m_print_json)
  223. print_file_result(file_result);
  224. if (needs_detailed_suites())
  225. ensure_suites().extend(file_result.suites);
  226. }
  227. inline Vector<DeprecatedString> TestRunner::get_test_paths() const
  228. {
  229. Vector<DeprecatedString> paths;
  230. iterate_directory_recursively(m_test_root, [&](DeprecatedString const& file_path) {
  231. if (!file_path.ends_with(".js"sv))
  232. return;
  233. if (!file_path.ends_with("test-common.js"sv))
  234. paths.append(file_path);
  235. });
  236. quick_sort(paths);
  237. return paths;
  238. }
  239. inline JSFileResult TestRunner::run_file_test(DeprecatedString const& test_path)
  240. {
  241. g_currently_running_test = test_path;
  242. #ifdef AK_OS_SERENITY
  243. auto string_id = perf_register_string(test_path.characters(), test_path.length());
  244. perf_event(PERF_EVENT_SIGNPOST, string_id, 0);
  245. #endif
  246. double start_time = get_time_in_ms();
  247. JS::GCPtr<JS::Realm> realm;
  248. JS::GCPtr<TestRunnerGlobalObject> global_object;
  249. auto root_execution_context = MUST(JS::Realm::initialize_host_defined_realm(
  250. *g_vm,
  251. [&](JS::Realm& realm_) -> JS::GlobalObject* {
  252. realm = &realm_;
  253. global_object = g_vm->heap().allocate<TestRunnerGlobalObject>(*realm, *realm);
  254. return global_object;
  255. },
  256. nullptr));
  257. auto& global_execution_context = *root_execution_context;
  258. g_vm->pop_execution_context();
  259. g_vm->heap().set_should_collect_on_every_allocation(g_collect_on_every_allocation);
  260. if (g_run_file) {
  261. auto result = g_run_file(test_path, *realm, global_execution_context);
  262. if (result.is_error() && result.error() == RunFileHookResult::SkipFile) {
  263. return {
  264. test_path,
  265. {},
  266. 0,
  267. Test::Result::Skip,
  268. {},
  269. {}
  270. };
  271. }
  272. if (!result.is_error()) {
  273. auto value = result.release_value();
  274. for (auto& suite : value.suites) {
  275. if (suite.most_severe_test_result == Result::Pass)
  276. m_counts.suites_passed++;
  277. else if (suite.most_severe_test_result == Result::Fail)
  278. m_counts.suites_failed++;
  279. for (auto& test : suite.tests) {
  280. if (test.result == Result::Pass)
  281. m_counts.tests_passed++;
  282. else if (test.result == Result::Fail)
  283. m_counts.tests_failed++;
  284. else if (test.result == Result::Skip)
  285. m_counts.tests_skipped++;
  286. }
  287. }
  288. ++m_counts.files_total;
  289. m_total_elapsed_time_in_ms += value.time_taken;
  290. return value;
  291. }
  292. }
  293. // FIXME: Since a new realm is created every time, we no longer cache the test-common.js file as scripts are parsed for the current realm only.
  294. // Find a way to cache this.
  295. auto result = parse_script(m_common_path, *realm);
  296. if (result.is_error()) {
  297. warnln("Unable to parse test-common.js");
  298. warnln("{}", result.error().error.to_deprecated_string());
  299. warnln("{}", result.error().hint);
  300. cleanup_and_exit();
  301. }
  302. auto test_script = result.release_value();
  303. g_vm->push_execution_context(global_execution_context);
  304. MUST(g_vm->bytecode_interpreter().run(*test_script));
  305. g_vm->pop_execution_context();
  306. auto file_script = parse_script(test_path, *realm);
  307. JS::ThrowCompletionOr<JS::Value> top_level_result { JS::js_undefined() };
  308. if (file_script.is_error())
  309. return { test_path, file_script.error() };
  310. g_vm->push_execution_context(global_execution_context);
  311. top_level_result = g_vm->bytecode_interpreter().run(file_script.value());
  312. g_vm->pop_execution_context();
  313. g_vm->push_execution_context(global_execution_context);
  314. auto test_json = get_test_results(*realm);
  315. g_vm->pop_execution_context();
  316. if (test_json.is_error()) {
  317. warnln("Received malformed JSON from test \"{}\"", test_path);
  318. cleanup_and_exit();
  319. }
  320. JSFileResult file_result { test_path.substring(m_test_root.length() + 1, test_path.length() - m_test_root.length() - 1) };
  321. // Collect logged messages
  322. auto user_output = MUST(realm->global_object().get("__UserOutput__"));
  323. auto& arr = user_output.as_array();
  324. for (auto& entry : arr.indexed_properties()) {
  325. auto message = MUST(arr.get(entry.index()));
  326. file_result.logged_messages.append(message.to_string_without_side_effects().to_deprecated_string());
  327. }
  328. test_json.value().as_object().for_each_member([&](DeprecatedString const& suite_name, JsonValue const& suite_value) {
  329. Test::Suite suite { test_path, suite_name };
  330. VERIFY(suite_value.is_object());
  331. suite_value.as_object().for_each_member([&](const DeprecatedString& test_name, const JsonValue& test_value) {
  332. Test::Case test { test_name, Test::Result::Fail, "", 0 };
  333. VERIFY(test_value.is_object());
  334. VERIFY(test_value.as_object().has("result"sv));
  335. auto result = test_value.as_object().get_deprecated_string("result"sv);
  336. VERIFY(result.has_value());
  337. auto result_string = result.value();
  338. if (result_string == "pass") {
  339. test.result = Test::Result::Pass;
  340. m_counts.tests_passed++;
  341. } else if (result_string == "fail") {
  342. test.result = Test::Result::Fail;
  343. m_counts.tests_failed++;
  344. suite.most_severe_test_result = Test::Result::Fail;
  345. VERIFY(test_value.as_object().has("details"sv));
  346. auto details = test_value.as_object().get_deprecated_string("details"sv);
  347. VERIFY(result.has_value());
  348. test.details = details.value();
  349. } else if (result_string == "xfail") {
  350. test.result = Test::Result::ExpectedFail;
  351. m_counts.tests_expected_failed++;
  352. if (suite.most_severe_test_result != Test::Result::Fail)
  353. suite.most_severe_test_result = Test::Result::ExpectedFail;
  354. } else {
  355. test.result = Test::Result::Skip;
  356. if (suite.most_severe_test_result == Test::Result::Pass)
  357. suite.most_severe_test_result = Test::Result::Skip;
  358. m_counts.tests_skipped++;
  359. }
  360. test.duration_us = test_value.as_object().get_u64("duration"sv).value_or(0);
  361. suite.tests.append(test);
  362. });
  363. if (suite.most_severe_test_result == Test::Result::Fail) {
  364. m_counts.suites_failed++;
  365. file_result.most_severe_test_result = Test::Result::Fail;
  366. } else {
  367. if (suite.most_severe_test_result == Test::Result::Skip && file_result.most_severe_test_result == Test::Result::Pass)
  368. file_result.most_severe_test_result = Test::Result::Skip;
  369. else if (suite.most_severe_test_result == Test::Result::ExpectedFail && (file_result.most_severe_test_result == Test::Result::Pass || file_result.most_severe_test_result == Test::Result::Skip))
  370. file_result.most_severe_test_result = Test::Result::ExpectedFail;
  371. m_counts.suites_passed++;
  372. }
  373. file_result.suites.append(suite);
  374. });
  375. if (top_level_result.is_error()) {
  376. Test::Suite suite { test_path, "<top-level>" };
  377. suite.most_severe_test_result = Result::Crashed;
  378. Test::Case test_case { "<top-level>", Test::Result::Fail, "", 0 };
  379. auto error = top_level_result.release_error().release_value().release_value();
  380. if (error.is_object()) {
  381. StringBuilder detail_builder;
  382. auto& error_object = error.as_object();
  383. auto name = error_object.get_without_side_effects(g_vm->names.name).value_or(JS::js_undefined());
  384. auto message = error_object.get_without_side_effects(g_vm->names.message).value_or(JS::js_undefined());
  385. if (name.is_accessor() || message.is_accessor()) {
  386. detail_builder.append(error.to_string_without_side_effects());
  387. } else {
  388. detail_builder.append(name.to_string_without_side_effects());
  389. detail_builder.append(": "sv);
  390. detail_builder.append(message.to_string_without_side_effects());
  391. }
  392. if (is<JS::Error>(error_object)) {
  393. auto& error_as_error = static_cast<JS::Error&>(error_object);
  394. detail_builder.append('\n');
  395. detail_builder.append(error_as_error.stack_string());
  396. }
  397. test_case.details = detail_builder.to_deprecated_string();
  398. } else {
  399. test_case.details = error.to_string_without_side_effects().to_deprecated_string();
  400. }
  401. suite.tests.append(move(test_case));
  402. file_result.suites.append(suite);
  403. m_counts.suites_failed++;
  404. file_result.most_severe_test_result = Test::Result::Fail;
  405. }
  406. m_counts.files_total++;
  407. file_result.time_taken = get_time_in_ms() - start_time;
  408. m_total_elapsed_time_in_ms += file_result.time_taken;
  409. return file_result;
  410. }
  411. inline void TestRunner::print_file_result(JSFileResult const& file_result) const
  412. {
  413. if (file_result.most_severe_test_result == Test::Result::Fail || file_result.error.has_value()) {
  414. print_modifiers({ BG_RED, FG_BOLD });
  415. out(" FAIL ");
  416. print_modifiers({ CLEAR });
  417. } else {
  418. if (m_print_times || file_result.most_severe_test_result != Test::Result::Pass) {
  419. print_modifiers({ BG_GREEN, FG_BLACK, FG_BOLD });
  420. out(" PASS ");
  421. print_modifiers({ CLEAR });
  422. } else {
  423. return;
  424. }
  425. }
  426. out(" {}", file_result.name);
  427. if (m_print_times) {
  428. print_modifiers({ CLEAR, ITALIC, FG_GRAY });
  429. if (file_result.time_taken < 1000) {
  430. outln(" ({}ms)", static_cast<int>(file_result.time_taken));
  431. } else {
  432. outln(" ({:3}s)", file_result.time_taken / 1000.0);
  433. }
  434. print_modifiers({ CLEAR });
  435. } else {
  436. outln();
  437. }
  438. if (!file_result.logged_messages.is_empty()) {
  439. print_modifiers({ FG_GRAY, FG_BOLD });
  440. #ifdef AK_OS_SERENITY
  441. outln(" ℹ Console output:");
  442. #else
  443. // This emoji has a second invisible byte after it. The one above does not
  444. outln(" ℹ️ Console output:");
  445. #endif
  446. print_modifiers({ CLEAR, FG_GRAY });
  447. for (auto& message : file_result.logged_messages)
  448. outln(" {}", message);
  449. }
  450. if (file_result.error.has_value()) {
  451. auto test_error = file_result.error.value();
  452. print_modifiers({ FG_RED });
  453. #ifdef AK_OS_SERENITY
  454. outln(" ❌ The file failed to parse");
  455. #else
  456. // No invisible byte here, but the spacing still needs to be altered on the host
  457. outln(" ❌ The file failed to parse");
  458. #endif
  459. outln();
  460. print_modifiers({ FG_GRAY });
  461. for (auto& message : test_error.hint.split('\n', SplitBehavior::KeepEmpty)) {
  462. outln(" {}", message);
  463. }
  464. print_modifiers({ FG_RED });
  465. outln(" {}", test_error.error.to_deprecated_string());
  466. outln();
  467. return;
  468. }
  469. if (file_result.most_severe_test_result != Test::Result::Pass) {
  470. for (auto& suite : file_result.suites) {
  471. if (suite.most_severe_test_result == Test::Result::Pass)
  472. continue;
  473. bool failed = suite.most_severe_test_result == Test::Result::Fail;
  474. print_modifiers({ FG_GRAY, FG_BOLD });
  475. if (failed) {
  476. #ifdef AK_OS_SERENITY
  477. out(" ❌ Suite: ");
  478. #else
  479. // No invisible byte here, but the spacing still needs to be altered on the host
  480. out(" ❌ Suite: ");
  481. #endif
  482. } else {
  483. #ifdef AK_OS_SERENITY
  484. out(" ⚠ Suite: ");
  485. #else
  486. // This emoji has a second invisible byte after it. The one above does not
  487. out(" ⚠️ Suite: ");
  488. #endif
  489. }
  490. print_modifiers({ CLEAR, FG_GRAY });
  491. if (suite.name == TOP_LEVEL_TEST_NAME) {
  492. outln("<top-level>");
  493. } else {
  494. outln("{}", suite.name);
  495. }
  496. print_modifiers({ CLEAR });
  497. for (auto& test : suite.tests) {
  498. if (test.result == Test::Result::Pass)
  499. continue;
  500. print_modifiers({ FG_GRAY, FG_BOLD });
  501. out(" Test: ");
  502. if (test.result == Test::Result::Fail) {
  503. print_modifiers({ CLEAR, FG_RED });
  504. outln("{} (failed):", test.name);
  505. outln(" {}", test.details);
  506. } else if (test.result == Test::Result::ExpectedFail) {
  507. print_modifiers({ CLEAR, FG_ORANGE });
  508. outln("{} (expected fail)", test.name);
  509. } else {
  510. print_modifiers({ CLEAR, FG_ORANGE });
  511. outln("{} (skipped)", test.name);
  512. }
  513. print_modifiers({ CLEAR });
  514. }
  515. }
  516. }
  517. }
  518. }