From fba4dac9f581269d87de52b03dceb6776ec7ed8e Mon Sep 17 00:00:00 2001 From: Gabriel Ionita Date: Mon, 27 Oct 2025 17:20:00 +0100 Subject: [PATCH] add integration tests part 2 --- tests/test_integration.cpp | 81 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/tests/test_integration.cpp b/tests/test_integration.cpp index e70db45..a90e982 100644 --- a/tests/test_integration.cpp +++ b/tests/test_integration.cpp @@ -89,3 +89,84 @@ TEST_CASE("gwatch detects non-existent variable", "[integration]") { bool found_error = (output.find("not found") != std::string::npos); REQUIRE(found_error); } + +TEST_CASE("gwatch handles missing executable", "[integration]") { + std::filesystem::path gwatch_path = "./build/gwatch"; + + if (!std::filesystem::exists(gwatch_path)) { + WARN("gwatch binary not found, skipping test"); + return; + } + + std::string output = exec_command( + "./build/gwatch --var some_var --exec /nonexistent/path 2>&1"); + + REQUIRE((output.find("Cannot open") != std::string::npos || + output.find("Error") != std::string::npos)); +} + +TEST_CASE("Test binaries compile correctly", "[integration]") { + // Verify test programs exist + SECTION("test_access") { + if (std::filesystem::exists("./test_access")) { + REQUIRE(true); + + // Try to check if it has debug symbols + std::string output = exec_command("file ./test_access"); + // Should mention it's an ELF executable + REQUIRE(output.find("ELF") != std::string::npos); + } else { + WARN("test_access not found"); + } + } + + SECTION("test_with_args") { + if (std::filesystem::exists("./test_with_args")) { + REQUIRE(true); + + std::string output = exec_command("file ./test_with_args"); + REQUIRE(output.find("ELF") != std::string::npos); + } else { + WARN("test_with_args not found"); + } + } +} + +TEST_CASE("DWARF debug information is present in test binaries", "[integration]") { + SECTION("test_access has DWARF info") { + if (!std::filesystem::exists("./test_access")) { + WARN("test_access not found, skipping test"); + return; + } + + // Check for debug sections using readelf + std::string output = exec_command("readelf -S ./test_access 2>&1"); + + // Should have debug sections if compiled with -g + bool has_debug = (output.find(".debug_") != std::string::npos); + + if (!has_debug) { + WARN("test_access may not have debug symbols. Compile with: gcc -g -O0 -o test_access test_access.c"); + } + + REQUIRE(has_debug); + } +} + +TEST_CASE("Command-line argument parsing", "[integration]") { + // Test that arguments after -- are properly handled + std::filesystem::path gwatch_path = "./build/gwatch"; + + if (!std::filesystem::exists(gwatch_path)) { + WARN("gwatch binary not found, skipping test"); + return; + } + + // This should at least parse correctly (even if the var doesn't exist) + // We're mainly checking that the -- separator doesn't cause a crash + std::string output = exec_command( + "./build/gwatch --var test_var --exec ./test_with_args -- arg1 arg2 2>&1"); + + // Should either find the var or report it's not found, but not crash + REQUIRE(!output.empty()); +}