make parseCommand take an extra error stream argument

Change-Id: Ia56015e7e088f2ce5a28cf0747ca93fdee731f81
diff --git a/src/CParser.cpp b/src/CParser.cpp
index 0762468..c6a42a6 100644
--- a/src/CParser.cpp
+++ b/src/CParser.cpp
@@ -5,7 +5,7 @@
  * Written by Václav Kubernát <kubervac@fit.cvut.cz>
  *
 */
-#include <iostream>
+#include <ostream>
 #include "CParser.hpp"
 
 TooManyArgumentsException::~TooManyArgumentsException() = default;
@@ -18,13 +18,14 @@
 }
 
 
-cd_ CParser::parseCommand(const std::string& line)
+cd_ CParser::parseCommand(const std::string& line, std::ostream& errorStream)
 {
     cd_ parsedCommand;
     ParserContext ctx(m_tree);
     auto it = line.begin();
 
-    boost::spirit::x3::error_handler<std::string::const_iterator> errorHandler(it, line.end(), std::cerr);
+    boost::spirit::x3::error_handler<std::string::const_iterator> errorHandler(it, line.end(), errorStream);
+
     auto grammar =
             x3::with<parser_context_tag>(ctx)[
             x3::with<x3::error_handler_tag>(std::ref(errorHandler))[cd]
diff --git a/src/CParser.hpp b/src/CParser.hpp
index beb91ef..cb92b12 100644
--- a/src/CParser.hpp
+++ b/src/CParser.hpp
@@ -37,7 +37,7 @@
 class CParser {
 public:
     CParser(const CTree& tree);
-    cd_ parseCommand(const std::string& line);
+    cd_ parseCommand(const std::string& line, std::ostream& errorStream);
 
 private:
     const CTree& m_tree;
diff --git a/tests/cd.cpp b/tests/cd.cpp
index 376e74c..9c73c61 100644
--- a/tests/cd.cpp
+++ b/tests/cd.cpp
@@ -25,6 +25,7 @@
     tree.addList("", "twoKeyList", {"number", "name"});
     CParser parser(tree);
     std::string input;
+    std::ostringstream errorStream;
 
     SECTION("valid input")
     {
@@ -90,7 +91,7 @@
             }
 
         }
-        cd_ command = parser.parseCommand(input);
+        cd_ command = parser.parseCommand(input, errorStream);
         REQUIRE(command == expected);
     }
     SECTION("invalid input")
@@ -100,13 +101,11 @@
             SECTION("nonexistent")
             {
                 input = "cd nonexistent";
-                REQUIRE_THROWS(parser.parseCommand(input));
             }
 
             SECTION("nonexistent/lol")
             {
                 input = "cd nonexistent/lol";
-                REQUIRE_THROWS(parser.parseCommand(input));
             }
         }
         SECTION("invalid list key identifiers")
@@ -114,26 +113,23 @@
             SECTION("twoKeyList[invalidKey=4]")
             {
                 input = "cd twoKeyList[invalidKey=4]";
-                REQUIRE_THROWS(parser.parseCommand(input));
             }
 
             SECTION("twoKeyList[number=4 number=5]")
             {
                 input = "cd twoKeyList[number=4 number=5]";
-                REQUIRE_THROWS(parser.parseCommand(input));
             }
 
             SECTION("twoKeyList[number=4 name=lol number=7]")
             {
                 input = "cd twoKeyList[number=4 name=lol number=7]";
-                REQUIRE_THROWS(parser.parseCommand(input));
             }
 
             SECTION("twoKeyList[number=4]")
             {
                 input = "cd twoKeyList[number=4]";
-                REQUIRE_THROWS(parser.parseCommand(input));
             }
         }
+        REQUIRE_THROWS(parser.parseCommand(input, errorStream));
     }
 }