#include #include #include #include #include #include #include #include #include #include namespace { namespace fs = std::filesystem; // A worker may exit while the session still owns its stdin pipe. struct IgnoreSigpipe { IgnoreSigpipe() { std::signal(SIGPIPE, SIG_IGN); } } ignore_sigpipe; using namespace vls::debug::live; using namespace std::chrono_literals; using Void::Testing::expect; using Void::Testing::require; struct Fixture { Void::FileSystem::TempDir temp{"vls_live_session_"}; fs::path source; fs::path trace; Options options; explicit Fixture(std::string name = "normal.cpp", std::chrono::milliseconds deadline = 5s) { source = temp.path() / name; std::ofstream{source} << "int value = 17;\n"; trace = temp.path() / "session.vls"; const auto worker = fs::canonical("/proc/self/exe").parent_path() / "vls_live_worker_fixture"; options = Options{worker, "/private/cc1plus", std::string(64, 'a'), source, trace, true, deadline, 64 * 1024}; } }; } // namespace VOID_TEST(LiveSession, steps_through_stops_and_inspects_each_generation) { Fixture fixture; LiveSession session{fixture.options}; const auto first = session.start(); if (!first.has_value()) std::cerr << "start error: " << first.error() << '\n'; require(first.has_value()); expect(first->generation == 1 && first->sequence == 1); expect(session.state() == State::stopped); const auto first_snapshot = session.inspect(); require(first_snapshot.has_value()); const auto first_json = Void::LanguageServer::Protocol::serialize_json(*first_snapshot); require(first_json.has_value()); expect(first_json->find("\"17\"") != std::string::npos); const auto second = session.step(); require(second.has_value() && second->has_value()); expect((*second)->generation == 2 && (*second)->sequence == 2); const auto second_snapshot = session.inspect(); require(second_snapshot.has_value()); const auto second_json = Void::LanguageServer::Protocol::serialize_json(*second_snapshot); require(second_json.has_value()); expect(second_json->find("\"34\"") != std::string::npos); require(session.step().has_value()); const auto done = session.step(); require(done.has_value()); expect(!done->has_value()); expect(session.state() == State::completed && session.outcome() == "completed"); } VOID_TEST(LiveSession, continue_finishes_the_session) { Fixture fixture; LiveSession session{fixture.options}; require(session.start().has_value()); const auto done = session.continue_run(); require(done.has_value()); expect(!done->has_value() && session.state() == State::completed); expect(session.stop() == std::nullopt); } VOID_TEST(LiveSession, cancel_terminates_at_a_stop) { Fixture fixture; LiveSession session{fixture.options}; require(session.start().has_value()); require(session.cancel().has_value()); expect(session.state() == State::cancelled); } VOID_TEST(LiveSession, refuses_movement_without_a_stop) { Fixture fixture; LiveSession session{fixture.options}; expect(!session.step().has_value()); expect(!session.inspect().has_value()); expect(!session.cancel().has_value()); } VOID_TEST(LiveSession, rejects_malformed_worker_output) { Fixture fixture{"malformed.cpp"}; LiveSession session{fixture.options}; const auto started = session.start(); require(!started.has_value()); expect(started.error().contains("bound") || started.error().contains("JSON")); } VOID_TEST(LiveSession, enforces_the_notice_deadline) { Fixture fixture{"silent.cpp", 200ms}; LiveSession session{fixture.options}; const auto started = session.start(); require(!started.has_value()); expect(started.error().contains("deadline")); }