summaryrefslogtreecommitdiff
path: root/test/integration/TestLogger.cpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-04-01 22:05:58 +0200
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2016-04-25 22:19:29 +0200
commit0e3cf1963a4c5fa28f12a70b7d2f25c33580c182 (patch)
tree2ae365ad3a955c29491fb7f8f1c723e0899a2305 /test/integration/TestLogger.cpp
parentac550e242be6e747f9420b705a33407652010b6c (diff)
Implement integration test framework
Diffstat (limited to 'test/integration/TestLogger.cpp')
-rw-r--r--test/integration/TestLogger.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/integration/TestLogger.cpp b/test/integration/TestLogger.cpp
new file mode 100644
index 0000000..d745c0f
--- /dev/null
+++ b/test/integration/TestLogger.cpp
@@ -0,0 +1,70 @@
+/*
+ Ousía
+ Copyright (C) 2015 Benjamin Paaßen, Andreas Stöckel
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <iomanip>
+
+#include "TestLogger.hpp"
+
+namespace ousia {
+namespace test {
+
+Logger::Logger(std::ostream &os, bool useColor) : os(os), terminal(useColor) {}
+
+void Logger::fail(const std::string &msg)
+{
+ os << terminal.color(Terminal::RED, true) << "[Fail]" << terminal.reset()
+ << " " << msg << std::endl;
+}
+
+void Logger::success(const std::string &msg)
+{
+ os << terminal.color(Terminal::GREEN, true) << "[Success]"
+ << terminal.reset() << " " << msg << std::endl;
+}
+
+void Logger::note(const std::string &msg)
+{
+ os << terminal.color(Terminal::BLUE, true) << "[Note]" << terminal.reset()
+ << " " << msg << std::endl;
+}
+
+void Logger::result(std::istream &is, const std::set<int> &errLines)
+{
+ std::string line;
+ is.clear();
+ is.seekg(0);
+ size_t lineNumber = 0;
+ while (std::getline(is, line)) {
+ lineNumber++;
+ const bool hasErr = errLines.count(lineNumber);
+ if (hasErr) {
+ os << terminal.background(Terminal::RED);
+ }
+ os << terminal.color(Terminal::BLACK, !hasErr) << (hasErr ? "!" : " ")
+ << std::setw(3) << lineNumber << ":" << terminal.reset() << " "
+ << line << std::endl;
+ }
+}
+
+void Logger::headline(const std::string &msg)
+{
+ os << std::endl << "== " << terminal.bright() << msg << terminal.reset()
+ << " ==" << std::endl;
+}
+}
+}