Skip to content

Commit b3d2f87

Browse files
committed
Add verbose logs and change test runner observer for linux
1 parent 4d0c105 commit b3d2f87

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

src/core/utils/test_runner.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ void test_runner::load_framework_config(test_framework fw, const std::string &se
9393
}
9494

9595
fs::path test_runner::get_test_gen_dir(const std::string &target_name) const {
96+
// Fallback if load_config() wasn't called
97+
if (m_build_base_dir.empty()) {
98+
return m_project_dir / "build" / "tests" / target_name;
99+
}
96100
return m_build_base_dir / "tests" / target_name;
97101
}
98102

@@ -185,7 +189,9 @@ std::vector<test_target> test_runner::auto_discover_targets() {
185189
std::vector<test_target> targets;
186190

187191
fs::path test_dir = m_project_dir / m_test_config.directory;
192+
logger::print_verbose("Looking for tests in: " + test_dir.string());
188193
if (!fs::exists(test_dir) || !fs::is_directory(test_dir)) {
194+
logger::print_verbose("Test directory does not exist: " + test_dir.string());
189195
return targets;
190196
}
191197

@@ -201,9 +207,12 @@ std::vector<test_target> test_runner::auto_discover_targets() {
201207
}
202208

203209
if (test_files.empty()) {
210+
logger::print_verbose("No test source files found in " + test_dir.string());
204211
return targets;
205212
}
206213

214+
logger::print_verbose("Found " + std::to_string(test_files.size()) + " test source files");
215+
207216
// Group files by directory to create targets
208217
std::map<fs::path, std::vector<fs::path>> files_by_dir;
209218
for (const auto &file : test_files) {
@@ -212,7 +221,11 @@ std::vector<test_target> test_runner::auto_discover_targets() {
212221
}
213222

214223
// Create one target per directory (or single target for flat structure)
215-
if (files_by_dir.size() == 1 && files_by_dir.begin()->first == ".") {
224+
// Note: fs::relative() returns "." on Windows but empty path on some Linux systems
225+
auto first_rel = files_by_dir.begin()->first;
226+
bool is_flat = files_by_dir.size() == 1 &&
227+
(first_rel == "." || first_rel.empty() || first_rel == test_dir.filename());
228+
if (is_flat) {
216229
// Flat structure - single target
217230
test_target target;
218231
target.name = "tests";
@@ -358,6 +371,7 @@ i_test_framework_adapter *test_runner::get_adapter(test_framework fw) {
358371
bool test_runner::generate_test_cmake(const test_target &target) {
359372
// Use configured build directory for test outputs
360373
fs::path gen_dir = get_test_gen_dir(target.name);
374+
logger::print_verbose("Test CMake dir: " + gen_dir.string());
361375
fs::create_directories(gen_dir);
362376

363377
fs::path cmake_file = gen_dir / "CMakeLists.txt";
@@ -495,6 +509,9 @@ bool test_runner::configure_cmake(const test_target &target,
495509
fs::path gen_dir = get_test_gen_dir(target.name);
496510
fs::path build_dir = get_test_build_dir(target.name);
497511

512+
// Ensure build directory exists
513+
fs::create_directories(build_dir);
514+
498515
std::vector<std::string> args = {
499516
"-S", to_cmake_path(gen_dir),
500517
"-B", to_cmake_path(build_dir),
@@ -515,9 +532,12 @@ bool test_runner::configure_cmake(const test_target &target,
515532
if (!result.success) {
516533
// Store error for later reporting
517534
m_error = "CMake configuration failed";
535+
logger::print_error("FAILED to configure " + target.name);
518536
if (!result.stderr_output.empty()) {
519-
// Just show the key error, not the full output
520-
logger::print_error("FAILED to configure " + target.name);
537+
logger::print_plain(result.stderr_output);
538+
}
539+
if (!result.stdout_output.empty()) {
540+
logger::print_plain(result.stdout_output);
521541
}
522542
}
523543
return result.success;
@@ -536,8 +556,12 @@ bool test_runner::build_target(const test_target &target,
536556
auto result = execute_process("cmake", args, m_project_dir.string(), nullptr, nullptr, 300);
537557
if (!result.success) {
538558
m_error = "Build failed";
559+
logger::print_error("FAILED to build " + target.name);
539560
if (!result.stderr_output.empty()) {
540-
logger::print_error("FAILED to build " + target.name);
561+
logger::print_plain(result.stderr_output);
562+
}
563+
if (!result.stdout_output.empty()) {
564+
logger::print_plain(result.stdout_output);
541565
}
542566
}
543567
return result.success;

0 commit comments

Comments
 (0)