From f3b8dc29e4bfe41804d29ee9bd517d031d40813a Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Mon, 15 Jan 2024 08:23:31 +0100 Subject: [PATCH] chore: support using real terminal in test_iolayer --- test/test_helpers.h | 2 ++ test/test_iolayer.cpp | 32 ++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/test/test_helpers.h b/test/test_helpers.h index 93da45c1..e9197666 100644 --- a/test/test_helpers.h +++ b/test/test_helpers.h @@ -240,6 +240,7 @@ class test_iolayer { std::string out() const; std::string err() const; + void use_real_terminal(bool use); void set_in(std::string in); void set_terminal_fancy(bool fancy); void set_terminal_width(size_t width); @@ -259,6 +260,7 @@ class test_iolayer { std::ostringstream out_; std::ostringstream err_; std::unique_ptr iol_; + std::shared_ptr real_term_; }; extern std::map statmap; diff --git a/test/test_iolayer.cpp b/test/test_iolayer.cpp index 5a8603ca..98e68c57 100644 --- a/test/test_iolayer.cpp +++ b/test/test_iolayer.cpp @@ -20,6 +20,7 @@ */ #include +#include #include @@ -316,18 +317,33 @@ test_iolayer::~test_iolayer() = default; iolayer const& test_iolayer::get() { if (!iol_) { - iol_ = std::make_unique(iolayer{ - .os = os_, - .term = term_, - .file = fa_, - .in = in_, - .out = out_, - .err = err_, - }); + if (real_term_) { + iol_ = std::make_unique(iolayer{ + .os = os_, + .term = real_term_, + .file = fa_, + .in = std::cin, + .out = std::cout, + .err = std::cerr, + }); + } else { + iol_ = std::make_unique(iolayer{ + .os = os_, + .term = term_, + .file = fa_, + .in = in_, + .out = out_, + .err = err_, + }); + } } return *iol_; } +void test_iolayer::use_real_terminal(bool use) { + real_term_ = terminal::create(); +} + void test_iolayer::set_terminal_fancy(bool fancy) { term_->set_fancy(fancy); } void test_iolayer::set_terminal_width(size_t width) { term_->set_width(width); } void test_iolayer::set_in(std::string in) { in_.str(std::move(in)); }