From 262fc37bad19f21a1d706312f70c71d7b7bc6fe8 Mon Sep 17 00:00:00 2001 From: Llewellyn Falco Date: Thu, 1 Mar 2018 15:47:13 +0200 Subject: [PATCH] Seperated SystemLauncher --- ApprovalTests/CMakeLists.txt | 2 +- ApprovalTests/reporters/CommandLauncher.h | 33 -------------- ApprovalTests/reporters/GenericDiffReporter.h | 1 + ApprovalTests/reporters/SystemLauncher.h | 43 +++++++++++++++++++ 4 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 ApprovalTests/reporters/SystemLauncher.h diff --git a/ApprovalTests/CMakeLists.txt b/ApprovalTests/CMakeLists.txt index 2af8bdc26..53c6017de 100644 --- a/ApprovalTests/CMakeLists.txt +++ b/ApprovalTests/CMakeLists.txt @@ -22,6 +22,6 @@ set(SOURCE_FILES reporters/MacReporters.h reporters/LinuxReporters.h StringUtils.h reporters/GenericDiffReporter.h reporters/CommandReporter.h OkraApprovals.h GoogleTestApprovals.h - ) + reporters/SystemLauncher.h) add_library(ApprovalTests ${SOURCE_FILES} ) set_target_properties(ApprovalTests PROPERTIES LINKER_LANGUAGE CXX) diff --git a/ApprovalTests/reporters/CommandLauncher.h b/ApprovalTests/reporters/CommandLauncher.h index 919e2cbba..67b3d51b6 100644 --- a/ApprovalTests/reporters/CommandLauncher.h +++ b/ApprovalTests/reporters/CommandLauncher.h @@ -1,11 +1,7 @@ #ifndef COMMANDLAUNCHER_H #define COMMANDLAUNCHER_H -#include -#include #include -#include "../SystemUtils.h" -#include "../FileUtils.h" #include #include @@ -40,33 +36,4 @@ class DoNothingLauncher : public CommandLauncher } }; -class SystemLauncher : public CommandLauncher -{ -public: - bool exists(const std::string& command) - { - bool foundByWhich = false; - if (!SystemUtils::isWindowsOs()) { - std::string which = "which " + command + " > /dev/null 2>&1"; - int result = system(which.c_str()); - foundByWhich = (result == 0); - } - return foundByWhich || FileUtils::fileExists(command); - - } - - bool Launch(std::vector argv) - { - if (!exists(argv.front())) - { - return false; - } - - std::string command = std::accumulate(argv.begin(), argv.end(), std::string(""), [](std::string a, std::string b) {return a + " " + "\"" + b + "\""; }); - std::string launch = SystemUtils::isWindowsOs() ? ("start \"\" " + command) : (command + " &"); - system(launch.c_str()); - return true; -} -}; - #endif \ No newline at end of file diff --git a/ApprovalTests/reporters/GenericDiffReporter.h b/ApprovalTests/reporters/GenericDiffReporter.h index 33d4f88c2..0043489bb 100644 --- a/ApprovalTests/reporters/GenericDiffReporter.h +++ b/ApprovalTests/reporters/GenericDiffReporter.h @@ -7,6 +7,7 @@ #include "DiffPrograms.h" #include "CommandReporter.h" +#include "SystemLauncher.h" class GenericDiffReporter : public CommandReporter { private: diff --git a/ApprovalTests/reporters/SystemLauncher.h b/ApprovalTests/reporters/SystemLauncher.h new file mode 100644 index 000000000..b73cbee09 --- /dev/null +++ b/ApprovalTests/reporters/SystemLauncher.h @@ -0,0 +1,43 @@ + +#ifndef APPROVALTESTS_CPP_SYSTEMLAUNCHER_H +#define APPROVALTESTS_CPP_SYSTEMLAUNCHER_H + +#include +#include +#include +#include "../SystemUtils.h" +#include "../FileUtils.h" +#include +#include +#include "CommandLauncher.h" + +class SystemLauncher : public CommandLauncher +{ +public: + bool exists(const std::string& command) + { + bool foundByWhich = false; + if (!SystemUtils::isWindowsOs()) { + std::string which = "which " + command + " > /dev/null 2>&1"; + int result = system(which.c_str()); + foundByWhich = (result == 0); + } + return foundByWhich || FileUtils::fileExists(command); + + } + + bool Launch(std::vector argv) + { + if (!exists(argv.front())) + { + return false; + } + + std::string command = std::accumulate(argv.begin(), argv.end(), std::string(""), [](std::string a, std::string b) {return a + " " + "\"" + b + "\""; }); + std::string launch = SystemUtils::isWindowsOs() ? ("start \"\" " + command) : (command + " &"); + system(launch.c_str()); + return true; + } +}; + +#endif //APPROVALTESTS_CPP_SYSTEMLAUNCHER_H