🏗️ interpreter doesn't depends on std::cout anymore.

main
bog 2023-10-14 18:03:21 +02:00
parent acabfb8889
commit af7f6768fd
4 changed files with 16 additions and 12 deletions

View File

@ -7,10 +7,12 @@ namespace sn
{
/*explicit*/ Interpreter::Interpreter(std::shared_ptr<State> state,
std::shared_ptr<Loader> loader,
std::shared_ptr<Executor> executor)
std::shared_ptr<Executor> executor,
std::ostream& ostream)
: m_state { state }
, m_loader { loader }
, m_executor { executor }
, m_ostream { ostream }
{
}
@ -106,19 +108,19 @@ namespace sn
int const SPACE = 2;
int const WIDTH = max_w + SQUARES_W + SPACE;
std::cout << std::setw(WIDTH);
std::cout << std::left;
m_ostream << std::setw(WIDTH);
m_ostream << std::left;
std::cout << "[" + file.filename().string() + "]";
m_ostream << "[" + file.filename().string() + "]";
std::cout << std::setw(WIDTH);
std::cout << script << std::endl;
m_ostream << std::setw(WIDTH);
m_ostream << script << std::endl;
auto ret = execute(script);
if (ret.empty() == false)
{
std::cout << ret << std::endl;
m_ostream << ret << std::endl;
}
}
}
@ -128,7 +130,7 @@ namespace sn
if (sorted.empty())
{
std::cout << "everything is up to date" << std::endl;
m_ostream << "everything is up to date" << std::endl;
}
}

View File

@ -23,7 +23,8 @@ namespace sn
public:
explicit Interpreter(std::shared_ptr<State> state,
std::shared_ptr<Loader> loader,
std::shared_ptr<Executor> executor);
std::shared_ptr<Executor> executor,
std::ostream& ostream);
virtual ~Interpreter();
void run();
@ -32,7 +33,7 @@ namespace sn
std::shared_ptr<State> m_state;
std::shared_ptr<Loader> m_loader;
std::shared_ptr<Executor> m_executor;
std::ostream& m_ostream;
std::unordered_map<std::filesystem::path,
std::vector<std::filesystem::path>> m_dependencies;

View File

@ -11,7 +11,7 @@ int main(int, char**)
auto loader = std::make_shared<sn::Loader>();
auto executor = std::make_shared<sn::Executor>();
sn::Interpreter interpreter {state, loader, executor};
sn::Interpreter interpreter {state, loader, executor, std::cout};
interpreter.run();
return 0;

View File

@ -70,7 +70,8 @@ public:
auto loader = std::make_shared<LoaderMock>(snakefile);
auto executor = std::make_shared<ExecutorMock>();
Interpreter interpreter {state, loader, executor};
std::stringstream ss;
Interpreter interpreter {state, loader, executor, ss};
interpreter.run();
return executor->history;