add integration tests part 2

This commit is contained in:
Gabriel Ionita 2025-10-27 17:20:00 +01:00
parent 4104bea698
commit fba4dac9f5
Signed by: gabi
SSH Key Fingerprint: SHA256:mrbYmB/SGtDvT3etRoS6pDrMYWxR0/B5GSF6rR3qhhc

View File

@ -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());
}