polybar-dwm/tests/unit_tests/utils/command.cpp

50 lines
1.1 KiB
C++
Raw Normal View History

2019-03-07 06:42:10 +00:00
#include "utils/command.hpp"
#include <unistd.h>
#include "common/test.hpp"
2019-03-07 06:42:10 +00:00
using namespace polybar;
2022-03-06 16:44:48 +00:00
static logger null_logger(loglevel::NONE);
2019-03-07 06:42:10 +00:00
TEST(Command, status) {
// Test for command<output_policy::IGNORED>::exec(bool);
{
2022-03-06 16:44:48 +00:00
command<output_policy::IGNORED> cmd(null_logger, "echo polybar > /dev/null");
int status = cmd.exec();
2019-03-07 06:42:10 +00:00
EXPECT_EQ(status, EXIT_SUCCESS);
}
// Test for command<output_policy::REDIRECTED>::exec(bool);
{
2022-03-06 16:44:48 +00:00
command<output_policy::REDIRECTED> cmd(null_logger, "echo polybar");
int status = cmd.exec();
2019-03-07 06:42:10 +00:00
EXPECT_EQ(status, EXIT_SUCCESS);
}
}
TEST(Command, status_async) {
{
2022-03-06 16:44:48 +00:00
command<output_policy::IGNORED> cmd(null_logger, "echo polybar > /dev/null");
EXPECT_EQ(cmd.exec(false), EXIT_SUCCESS);
2019-03-07 06:42:10 +00:00
2022-03-06 16:44:48 +00:00
cmd.wait();
2019-03-07 06:42:10 +00:00
2022-03-06 16:44:48 +00:00
EXPECT_FALSE(cmd.is_running());
EXPECT_EQ(cmd.get_exit_status(), EXIT_SUCCESS);
2019-03-07 06:42:10 +00:00
}
}
TEST(Command, output) {
2022-03-06 16:44:48 +00:00
command<output_policy::REDIRECTED> cmd(null_logger, "echo polybar");
2019-03-07 06:42:10 +00:00
string str;
2022-03-06 16:44:48 +00:00
cmd.exec(false);
cmd.tail([&str](string&& string) { str = string; });
cmd.wait();
2019-03-07 06:42:10 +00:00
EXPECT_EQ(str, "polybar");
}