From 7eaa6976b905725b3fd63284acf925104db2bf45 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 24 Mar 2015 13:14:02 +0000 Subject: [PATCH] Use a dummy UI when running tests, so that we do not need a tty --- src/main.cc | 43 +++++++++++++++++++++++++++++++++++-------- test/run | 2 +- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/main.cc b/src/main.cc index faaff661..c76ca981 100644 --- a/src/main.cc +++ b/src/main.cc @@ -227,15 +227,16 @@ void register_options() UserInterface::Options()); } +template void create_local_client(StringView init_command) { - class LocalNCursesUI : public NCursesUI + struct LocalUI : UI { - ~LocalNCursesUI() + ~LocalUI() { if (not ClientManager::instance().empty() and fork()) { - this->NCursesUI::~NCursesUI(); + this->UI::~UI(); puts("detached from terminal\n"); exit(0); } @@ -255,9 +256,8 @@ void create_local_client(StringView init_command) create_fifo_buffer("*stdin*", fd); } - UserInterface* ui = new LocalNCursesUI{}; static Client* client = ClientManager::instance().create_client( - std::unique_ptr{ui}, get_env_vars(), init_command); + make_unique(), get_env_vars(), init_command); signal(SIGHUP, [](int) { if (client) ClientManager::instance().remove_client(*client); @@ -313,8 +313,28 @@ int run_client(StringView session, StringView init_command) return 0; } +struct DummyUI : UserInterface +{ +public: + void menu_show(ConstArrayView, CharCoord, Face, Face, MenuStyle) override {} + void menu_select(int) override {} + void menu_hide() override {} + + void info_show(StringView, StringView, CharCoord, Face, InfoStyle) override {} + void info_hide() override {} + + void draw(const DisplayBuffer&, const DisplayLine&, const DisplayLine&) override {} + CharCoord dimensions() override { return {24,80}; } + bool is_key_available() override { return false; } + Key get_key() override { return Key::Invalid; } + void refresh() override {} + void set_input_callback(InputCallback) override {} + void set_ui_options(const Options&) override {} +}; + int run_server(StringView session, StringView init_command, - bool ignore_kakrc, bool daemon, ConstArrayView files) + bool ignore_kakrc, bool daemon, bool dummy_ui, + ConstArrayView files) { static bool terminate = false; if (daemon) @@ -396,7 +416,12 @@ int run_server(StringView session, StringView init_command, new Buffer("*scratch*", Buffer::Flags::None); if (not daemon) - create_local_client(init_command); + { + if (dummy_ui) + create_local_client(init_command); + else + create_local_client(init_command); + } while (not terminate and (not client_manager.empty() or daemon)) { @@ -524,7 +549,8 @@ int main(int argc, char* argv[]) { "d", { false, "run as a headless session (requires -s)" } }, { "p", { true, "just send stdin as commands to the given session" } }, { "f", { true, "act as a filter, executing given keys on given files" } }, - { "q", { false, "in filter mode, be quiet about errors applying keys" } } } + { "q", { false, "in filter mode, be quiet about errors applying keys" } }, + { "u", { false, "use a dummy user interface, for testing purposes" } } } }; try { @@ -579,6 +605,7 @@ int main(int argc, char* argv[]) return run_server(session, init_command, (bool)parser.get_switch("n"), (bool)parser.get_switch("d"), + (bool)parser.get_switch("u"), files); } } diff --git a/test/run b/test/run index c96d9790..e3178c2e 100755 --- a/test/run +++ b/test/run @@ -41,7 +41,7 @@ main() { write out quit! " - ${test}/../src/kak out -n -e "$kak_commands" + ${test}/../src/kak out -n -u -e "$kak_commands" for expect in $test_files; do if cmp -s $test/$dir/$expect $expect; then echo "$indent$name" | colorize green normal