From 3b8bf85fbc35dc2403c3848abed02c85acddf3ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20M=C4=99drek?= Date: Mon, 19 Jan 2026 17:32:57 +0100 Subject: [PATCH] test/lib/boost_test_tree_lister.cc: Record empty test suites Before this commit, if a test file or a test suite didn't include any actual test cases, it was ignored by `boost_test_tree_lister`. However, this information is useful; for example, it allows us to tell if the test file the user wants to run doesn't exist or simply doesn't contain any tests. The kind of error we would return to them should be different depending on which situation we're dealing with. We start including those empty suites and files in the output of `--list_json_content`. --- Examples (with additional formatting): * Consider the following test file, `test/boost/dummy_test.cc` [1]: ``` BOOST_AUTO_TEST_SUITE(dummy_suite1) BOOST_AUTO_TEST_SUITE(dummy_suite2) BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE(dummy_suite3) BOOST_AUTO_TEST_SUITE_END() ``` Before this commit: ``` $ ./build/debug/test/boost/dummy_test -- --list_json_content [{"file": "test/boost/dummy_test.cc", "content": {"suites": [], "tests": []}}] ``` After this commit: ``` $ ./build/debug/test/boost/dummy_test -- --list_json_content [{"file":"test/boost/dummy_test.cc", "content": {"suites": [ {"name": "dummy_suite1", "suites": [ {"name": "dummy_suite2", "suites": [], "tests": []} ], "tests": []}, {"name": "dummy_suite3", "suites": [], "tests": []} ], "tests": []}}] ``` * Consider the same test file as in Example 1, but also assume it's compiled into `test/boost/combined_tests`. Before this commit: ``` $ ./build/debug/test/boost/combined_tests -- --list_json_content | grep dummy $ ``` After this commit: ``` $ ./build/debug/test/boost/combined_tests -- --list_json_content [..., {"file": "test/boost/dummy_test.cc", "content": {"suites": [ {"name": "dummy_suite1", "suites": [{"name": "dummy_suite2", "suites": [], "tests": []}], "tests": []}, {"name": "dummy_suite3", "suites": [], "tests": []}], "tests":[]}}, ...] ``` [1] Note that the example is simplified. As of now, it's not possible to use `--list_json_content` with a file without any Boost tests. That will result in the following error: `Test setup error: test tree is empty`. Refs scylladb/scylladb#25415 --- test/lib/boost_test_tree_lister.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/lib/boost_test_tree_lister.cc b/test/lib/boost_test_tree_lister.cc index f63037f4ca..8b321616ac 100644 --- a/test/lib/boost_test_tree_lister.cc +++ b/test/lib/boost_test_tree_lister.cc @@ -273,6 +273,23 @@ public: return; } + // If the suite doesn't have any children, that indicates one of + // the following: + // + // * This suite represents an actual test suite that doesn't contain + // any tests. + // * This suite corresponds to a test file that was compiled into + // the `test/boost/combined_tests` binary. In that case, the test + // file was empty, i.e. it didn't contain any suites or tests. + // + // In either situation, we still want to record the information that + // the file/suite exists (e.g. to be able to tell if the file the user + // wants to run even exists). + if (ts.size() == 0) { + const std::string_view filename = {ts.p_file_name.begin(), ts.p_file_name.end()}; + (void) get_active_suite(filename); + } + drop_active_suite(); }