| 26 | #include "openhd_util.h" |
| 27 | |
| 28 | static 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 | |
| 51 | int main(int argc, char *argv[]) { test_execute_commands(); } |