From efac08926296860d0729ef41bcc5b8689827a28f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Mon, 2 Nov 2020 23:16:54 +0100
Subject: [PATCH] Add ConsoleManager tests

---
 tests/CMakeLists.txt          |  1 +
 tests/test_ConsoleManager.cpp | 37 +++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
 create mode 100644 tests/test_ConsoleManager.cpp

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index f776b803d..13833beb3 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -50,6 +50,7 @@ add_executable (unit_tests
   test_BuiltinFunctionEmbedderTable.cpp
   test_BuiltinFunctionProcessor.cpp
   test_CastArray.cpp
+  test_ConsoleManager.cpp
   test_CG.cpp
   test_ContinueProcessor.cpp
   test_ConcatExpressionProcessor.cpp
diff --git a/tests/test_ConsoleManager.cpp b/tests/test_ConsoleManager.cpp
new file mode 100644
index 000000000..266185218
--- /dev/null
+++ b/tests/test_ConsoleManager.cpp
@@ -0,0 +1,37 @@
+#ifndef TEST_CONSOLE_MANAGER_HPP
+#define TEST_CONSOLE_MANAGER_HPP
+
+#include <catch2/catch.hpp>
+
+#include <utils/ConsoleManager.hpp>
+
+#include <rang.hpp>
+
+// clazy:excludeall=non-pod-global-static
+
+TEST_CASE("ConsoleManager", "[utils]")
+{
+  SECTION("is terminal")
+  {
+    const bool is_terminal = rang::rang_implementation::isTerminal(std::cout.rdbuf());
+
+    REQUIRE(is_terminal == ConsoleManager::isTerminal(std::cout));
+  }
+
+  SECTION("control settings")
+  {
+    const rang::control saved_control = rang::rang_implementation::controlMode();
+
+    ConsoleManager::init(true);
+
+    REQUIRE(rang::rang_implementation::controlMode() == rang::control::Force);
+
+    ConsoleManager::init(false);
+
+    REQUIRE(rang::rang_implementation::controlMode() == rang::control::Off);
+
+    rang::setControlMode(saved_control);
+  }
+}
+
+#endif   // TEST_CONSOLE_MANAGER_HPP
-- 
GitLab