#include #include #include #include #include #include #include // Helper function to execute a command and capture output std::string exec_command(const std::string& cmd) { std::array buffer; std::string result; std::unique_ptr pipe(popen(cmd.c_str(), "r"), pclose); if (!pipe) { return ""; } while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { result += buffer.data(); } return result; } TEST_CASE("gwatch binary exists and is executable", "[integration]") { std::filesystem::path gwatch_path = "./build/gwatch"; if (!std::filesystem::exists(gwatch_path)) { WARN("gwatch binary not found at ./build/gwatch"); return; } REQUIRE(std::filesystem::exists(gwatch_path)); // Check if it's executable auto perms = std::filesystem::status(gwatch_path).permissions(); bool is_executable = (perms & std::filesystem::perms::owner_exec) != std::filesystem::perms::none; REQUIRE(is_executable); } TEST_CASE("gwatch shows help message", "[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 --help"); // Help should mention the main options REQUIRE(output.find("--exec") != std::string::npos); REQUIRE(output.find("--var") != std::string::npos); } TEST_CASE("gwatch requires both --exec and --var arguments", "[integration]") { std::filesystem::path gwatch_path = "./build/gwatch"; if (!std::filesystem::exists(gwatch_path)) { WARN("gwatch binary not found, skipping test"); return; } // Test missing both arguments std::string output = exec_command("./build/gwatch 2>&1"); bool has_error = (output.find("required") != std::string::npos || output.find("Error") != std::string::npos); REQUIRE(has_error); } TEST_CASE("gwatch detects non-existent variable", "[integration]") { std::filesystem::path gwatch_path = "./build/gwatch"; std::filesystem::path test_binary = "./test_access"; if (!std::filesystem::exists(gwatch_path)) { WARN("gwatch binary not found, skipping test"); return; } if (!std::filesystem::exists(test_binary)) { WARN("test_access binary not found, skipping test"); return; } std::string output = exec_command( "./build/gwatch --var nonexistent_var_xyz --exec ./test_access 2>&1"); bool found_error = (output.find("not found") != std::string::npos); REQUIRE(found_error); }