MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / test_execute_commands

Function test_execute_commands

OpenHD/ohd_common/test/test_openhd_util.cpp:28–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26#include "openhd_util.h"
27
28static void test_execute_commands() {
29 // We do echo 1, but the method should return "0" which stands for
30 // command succesfully executed
31 auto res = OHDUtil::run_command("echo", {"1"});
32 std::cout << "Res is:" << res << "\n";
33 if (res != 0) {
34 throw std::runtime_error("run_command return does not match expected\n");
35 }
36 // Here we get the actual output in the shell, which should be 1
37 auto res2 = OHDUtil::run_command_out("echo 1");
38 std::cout << "Res2 is:[" << res2.value() << "]\n";
39 if (res2 != "1\n") {
40 throw std::runtime_error(
41 "run_command_out return does not match expected\n");
42 }
43 auto res3 = OHDUtil::run_command_out("rambazambathiscommanddoesnotexist");
44 if (res3 != std::nullopt) {
45 std::cerr << "res3 is:[" << res3.value() << "]\n";
46 // throw std::runtime_error("run_command_out an unknown command should
47 // return command not found\n");
48 }
49}
50
51int main(int argc, char *argv[]) { test_execute_commands(); }

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected