From ff8429a749dce36d27ecfdd4b1aa12e2e4a759b1 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 17 Jul 2021 16:29:51 -0600 Subject: [PATCH] LibTest/Utilities: Add method for TestRunner to print failed test names If a test run has a lot of tests in it, and they fill up the terminal buffer, it can be difficult to find out exactly which tests have failed from your large test run. Make TestRunner print out an optional Vector of failed test names at the end of the run, and have run-tests add each failed or crashed test to a Vector it uses for this purpose. --- Userland/Libraries/LibTest/TestRunner.h | 4 ++++ Userland/Utilities/run-tests.cpp | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Userland/Libraries/LibTest/TestRunner.h b/Userland/Libraries/LibTest/TestRunner.h index 558de18408..f91590bd99 100644 --- a/Userland/Libraries/LibTest/TestRunner.h +++ b/Userland/Libraries/LibTest/TestRunner.h @@ -55,6 +55,7 @@ protected: virtual Vector get_test_paths() const = 0; virtual void do_run_single_test(const String&) = 0; + virtual const Vector* get_failed_test_names() const { return nullptr; } String m_test_root; bool m_print_times; @@ -214,6 +215,9 @@ inline void TestRunner::print_test_results() const } else { outln("{:>.3}s", m_total_elapsed_time_in_ms / 1000.0); } + if (auto* failed_tests = get_failed_test_names(); failed_tests && !failed_tests->is_empty()) { + outln("Failed tests: {}", *failed_tests); + } outln(); } diff --git a/Userland/Utilities/run-tests.cpp b/Userland/Utilities/run-tests.cpp index efc5b29111..a4d721fc2f 100644 --- a/Userland/Utilities/run-tests.cpp +++ b/Userland/Utilities/run-tests.cpp @@ -48,6 +48,7 @@ public: protected: virtual void do_run_single_test(const String& test_path) override; virtual Vector get_test_paths() const override; + virtual const Vector* get_failed_test_names() const override { return &m_failed_test_names; } virtual FileResult run_test_file(const String& test_path); @@ -57,6 +58,7 @@ protected: NonnullRefPtr m_config; Vector m_skip_directories; Vector m_skip_files; + Vector m_failed_test_names; Regex m_skip_regex; bool m_print_all_output { false }; }; @@ -120,6 +122,7 @@ void TestRunner::do_run_single_test(const String& test_path) bool crashed_or_failed = test_result.result == Test::Result::Fail || test_result.result == Test::Result::Crashed; bool print_stdout_stderr = crashed_or_failed || m_print_all_output; if (crashed_or_failed) { + m_failed_test_names.append(test_path); print_modifiers({ Test::BG_RED, Test::FG_BLACK, Test::FG_BOLD }); out("{}", test_result.result == Test::Result::Fail ? " FAIL " : "CRASHED"); print_modifiers({ Test::CLEAR });