2018-05-20 09:14:17 +02:00
|
|
|
#include <cpp-utils/process/subprocess.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
using cpputils::Subprocess;
|
|
|
|
using cpputils::SubprocessError;
|
|
|
|
|
2018-07-09 04:34:08 +02:00
|
|
|
namespace {
|
|
|
|
std::string exit_with_message_and_status(const char* message, int status) {
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
constexpr const char* executable = "cpp-utils-test_exit_status.exe";
|
|
|
|
#else
|
|
|
|
constexpr const char* executable = "./test/cpp-utils/cpp-utils-test_exit_status";
|
|
|
|
#endif
|
|
|
|
return std::string(executable) + " \"" + message + "\" " + std::to_string(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-20 09:14:17 +02:00
|
|
|
TEST(SubprocessTest, CheckCall_success_output) {
|
2018-07-09 04:34:08 +02:00
|
|
|
EXPECT_EQ("hello", Subprocess::check_call(exit_with_message_and_status("hello", 0)).output);
|
2018-05-20 09:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, CheckCall_successwithemptyoutput_output) {
|
2018-07-09 04:34:08 +02:00
|
|
|
EXPECT_EQ("", Subprocess::check_call(exit_with_message_and_status("", 0)).output);
|
2018-05-20 09:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, CheckCall_success_exitcode) {
|
2018-07-09 04:34:08 +02:00
|
|
|
EXPECT_EQ(0, Subprocess::check_call(exit_with_message_and_status("hello", 0)).exitcode);
|
2018-05-20 09:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, CheckCall_successwithemptyoutput_exitcode) {
|
2018-07-09 04:34:08 +02:00
|
|
|
EXPECT_EQ(0, Subprocess::check_call(exit_with_message_and_status("", 0)).exitcode);
|
2018-05-20 09:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, CheckCall_error) {
|
|
|
|
EXPECT_THROW(
|
2018-07-09 04:34:08 +02:00
|
|
|
Subprocess::check_call(exit_with_message_and_status("", 1)),
|
2018-05-20 09:14:17 +02:00
|
|
|
SubprocessError
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, CheckCall_error5) {
|
|
|
|
EXPECT_THROW(
|
2018-07-09 04:34:08 +02:00
|
|
|
Subprocess::check_call(exit_with_message_and_status("", 5)),
|
2018-05-20 09:14:17 +02:00
|
|
|
SubprocessError
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, CheckCall_errorwithoutput) {
|
|
|
|
EXPECT_THROW(
|
2018-07-09 04:34:08 +02:00
|
|
|
Subprocess::check_call(exit_with_message_and_status("hello", 1)),
|
2018-05-20 09:14:17 +02:00
|
|
|
SubprocessError
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, CheckCall_error5withoutput) {
|
|
|
|
EXPECT_THROW(
|
2018-07-09 04:34:08 +02:00
|
|
|
Subprocess::check_call(exit_with_message_and_status("hello", 5)),
|
2018-05-20 09:14:17 +02:00
|
|
|
SubprocessError
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, Call_success_exitcode) {
|
2018-07-09 04:34:08 +02:00
|
|
|
EXPECT_EQ(0, Subprocess::call(exit_with_message_and_status("hello", 0)).exitcode);
|
2018-05-20 09:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, Call_success_output) {
|
2018-07-09 04:34:08 +02:00
|
|
|
EXPECT_EQ("hello", Subprocess::call(exit_with_message_and_status("hello", 0)).output);
|
2018-05-20 09:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, Call_error_exitcode) {
|
2018-07-09 04:34:08 +02:00
|
|
|
EXPECT_EQ(1, Subprocess::call(exit_with_message_and_status("", 1)).exitcode);
|
2018-05-20 09:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, Call_error_output) {
|
2018-07-09 04:34:08 +02:00
|
|
|
EXPECT_EQ("", Subprocess::call(exit_with_message_and_status("", 1)).output);
|
2018-05-20 09:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, Call_error5_exitcode) {
|
2018-07-09 04:34:08 +02:00
|
|
|
EXPECT_EQ(5, Subprocess::call(exit_with_message_and_status("", 5)).exitcode);
|
2018-05-20 09:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, Call_error5_output) {
|
2018-07-09 04:34:08 +02:00
|
|
|
EXPECT_EQ("", Subprocess::call(exit_with_message_and_status("", 1)).output);
|
2018-05-20 09:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, Call_errorwithoutput_output) {
|
2018-07-09 04:34:08 +02:00
|
|
|
EXPECT_EQ("hello", Subprocess::call(exit_with_message_and_status("hello", 1)).output);
|
2018-05-20 09:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, Call_errorwithoutput_exitcode) {
|
2018-07-09 04:34:08 +02:00
|
|
|
EXPECT_EQ(1, Subprocess::call(exit_with_message_and_status("hello", 1)).exitcode);
|
2018-05-20 09:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, Call_error5withoutput_output) {
|
2018-07-09 04:34:08 +02:00
|
|
|
EXPECT_EQ("hello", Subprocess::call(exit_with_message_and_status("hello", 5)).output);
|
2018-05-20 09:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SubprocessTest, Call_error5withoutput_exitcode) {
|
2018-07-09 04:34:08 +02:00
|
|
|
EXPECT_EQ(5, Subprocess::call(exit_with_message_and_status("hello", 5)).exitcode);
|
2018-05-20 09:14:17 +02:00
|
|
|
}
|