Skip to content

Commit

Permalink
Seperated SystemLauncher
Browse files Browse the repository at this point in the history
  • Loading branch information
isidore committed Mar 1, 2018
1 parent aff3867 commit 262fc37
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
2 changes: 1 addition & 1 deletion ApprovalTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
33 changes: 0 additions & 33 deletions ApprovalTests/reporters/CommandLauncher.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#ifndef COMMANDLAUNCHER_H
#define COMMANDLAUNCHER_H

#include <iostream>
#include <stdlib.h>
#include <string>
#include "../SystemUtils.h"
#include "../FileUtils.h"
#include <vector>
#include <numeric>

Expand Down Expand Up @@ -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<std::string> 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
1 change: 1 addition & 0 deletions ApprovalTests/reporters/GenericDiffReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "DiffPrograms.h"
#include "CommandReporter.h"
#include "SystemLauncher.h"

class GenericDiffReporter : public CommandReporter {
private:
Expand Down
43 changes: 43 additions & 0 deletions ApprovalTests/reporters/SystemLauncher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

#ifndef APPROVALTESTS_CPP_SYSTEMLAUNCHER_H
#define APPROVALTESTS_CPP_SYSTEMLAUNCHER_H

#include <iostream>
#include <stdlib.h>
#include <string>
#include "../SystemUtils.h"
#include "../FileUtils.h"
#include <vector>
#include <numeric>
#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<std::string> 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

0 comments on commit 262fc37

Please sign in to comment.