utils: rework running system commands

Use g_spawn and pass arguments, so we don't involve a shell that needs
escaping etc.

Improve error handling.
This commit is contained in:
Dirk-Jan C. Binnema
2023-07-18 19:10:08 +03:00
parent 5efd0a61aa
commit cf6c5a36d7
4 changed files with 56 additions and 30 deletions

View File

@ -20,6 +20,7 @@
#ifndef MU_TEST_UTILS_HH__
#define MU_TEST_UTILS_HH__
#include <initializer_list>
#include <string>
#include <utils/mu-utils.hh>
#include <utils/mu-result.hh>
@ -91,6 +92,14 @@ bool set_en_us_utf8_locale();
} \
} while(0)
#define assert_valid_command(RCO) do { \
assert_valid_result(RCO); \
if ((RCO)->exit_code != 0 && !(RCO)->standard_err.empty()) \
mu_printerrln("{}:{}: {}", \
__FILE__, __LINE__, (RCO)->standard_err); \
g_assert_cmpuint((RCO)->exit_code, ==, 0); \
} while (0)
/**
* For unit-tests, allow warnings in the current function.
*
@ -98,18 +107,6 @@ bool set_en_us_utf8_locale();
void allow_warnings();
/**
* Execute the in-tree mu executable with the arguments
* Asserts if fails.
*
* @param args arguments;;
*
* @return either the exit code or an error.
*/
Result<int> run_mu_command(const std::string& args);
/**
* For unit-tests, a RAII tempdir.
*