#include #include "frontends/tui/tui.hpp" #include #include #include #include // Tui::Source nesting — regression for the bug where a nested `source` // overwrote the single loading state, so the CALLING script's remaining // lines never ran. Headless path (no screen): BootDispatch drains // synchronously, exactly like `essim --batch --source`. namespace { std::string run_boot(const std::string &cmd) { Tui t; t.BootDispatch(cmd); std::ostringstream oss; t.DumpOutput(oss); return oss.str(); } } // namespace TEST_CASE("source: lines after a nested source still run") { const char *inner = "test_src_inner.essim"; const char *outer = "test_src_outer.essim"; { std::ofstream f(inner); f << "new\n"; } { std::ofstream f(outer); f << "source " << inner << "\n" "verify\n"; } std::string out = run_boot(std::string("source ") + outer); // The inner script ran and was summarised… CHECK(out.find("system created.") != std::string::npos); CHECK(out.find(std::string("source: ") + inner) != std::string::npos); // …and the OUTER script kept going after it: verify executed… CHECK(out.find("verify: 0 local mismatch(es)") != std::string::npos); // …and the outer summary counts its 2 effective lines. CHECK(out.find(std::string("source: ") + outer + " (2 line(s))") != std::string::npos); std::remove(inner); std::remove(outer); } TEST_CASE("source: self-recursion stops at the depth guard") { const char *loop = "test_src_loop.essim"; { std::ofstream f(loop); f << "source " << loop << "\n"; } std::string out = run_boot(std::string("source ") + loop); CHECK(out.find("source: nesting too deep, skipping") != std::string::npos); // Every frame still closes with its own summary. CHECK(out.find(std::string("source: ") + loop + " (1 line(s))") != std::string::npos); std::remove(loop); }