1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-25 13:55:47 -05:00

add command unit tests

This commit is contained in:
Jérôme BOULMIER 2019-03-07 01:42:10 -05:00 committed by Patrick Ziegler
parent 5e5d8faf04
commit e9d2f022cd
5 changed files with 61 additions and 3 deletions

View file

@ -5,6 +5,7 @@
#include <thread> #include <thread>
#include "common.hpp" #include "common.hpp"
#include "components/types.hpp"
#include "events/signal_fwd.hpp" #include "events/signal_fwd.hpp"
#include "events/signal_receiver.hpp" #include "events/signal_receiver.hpp"
#include "events/types.hpp" #include "events/types.hpp"

View file

@ -77,7 +77,7 @@ class command<output_policy::IGNORED> {
string m_cmd; string m_cmd;
pid_t m_forkpid{}; pid_t m_forkpid{};
int m_forkstatus{}; int m_forkstatus = - 1;
}; };
template <> template <>

View file

@ -48,6 +48,7 @@ function(add_unit_test source_file)
endfunction() endfunction()
add_unit_test(utils/color) add_unit_test(utils/color)
add_unit_test(utils/command)
add_unit_test(utils/math unit_tests) add_unit_test(utils/math unit_tests)
add_unit_test(utils/memory unit_tests) add_unit_test(utils/memory unit_tests)
add_unit_test(utils/scope unit_tests) add_unit_test(utils/scope unit_tests)

View file

@ -0,0 +1,57 @@
#include "utils/command.hpp"
#include "common/test.hpp"
#include <unistd.h>
using namespace polybar;
TEST(Command, status) {
// Test for command<output_policy::IGNORED>::exec(bool);
{
auto cmd = command_util::make_command<output_policy::IGNORED>("echo polybar > /dev/null");
int status = cmd->exec();
EXPECT_EQ(status, EXIT_SUCCESS);
}
// Test for command<output_policy::REDIRECTED>::exec(bool);
{
auto cmd = command_util::make_command<output_policy::REDIRECTED>("echo polybar");
int status = cmd->exec();
EXPECT_EQ(status, EXIT_SUCCESS);
}
}
TEST(Command, status_async) {
{
auto cmd = command_util::make_command<output_policy::IGNORED>("echo polybar > /dev/null");
EXPECT_EQ(cmd->exec(false), EXIT_SUCCESS);
cmd->wait();
EXPECT_FALSE(cmd->is_running());
EXPECT_EQ(cmd->get_exit_status(), EXIT_SUCCESS);
}
}
TEST(Command, output) {
auto cmd = command_util::make_command<output_policy::REDIRECTED>("echo polybar");
string str;
cmd->exec(false);
cmd->tail([&str](string&& string) { str = string; });
cmd->wait();
EXPECT_EQ(str, "polybar");
}
TEST(Command, readline) {
auto cmd = command_util::make_command<output_policy::REDIRECTED>("read text;echo $text");
string str;
cmd->exec(false);
cmd->writeline("polybar");
cmd->tail([&str](string&& string) { str = string; });
EXPECT_EQ(str, "polybar");
}

View file

@ -8,10 +8,9 @@
using namespace polybar; using namespace polybar;
TEST(File, expand) { TEST(File, expand) {
auto cmd = command_util::make_command("echo $HOME"); auto cmd = command_util::make_command<output_policy::REDIRECTED>("echo $HOME");
cmd->exec(); cmd->exec();
cmd->tail([](string home) { cmd->tail([](string home) {
EXPECT_EQ(home + "/test", file_util::expand("~/test")); EXPECT_EQ(home + "/test", file_util::expand("~/test"));
}); });
} }