aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Sasha Smundak <asmundak@google.com>2016-08-02 16:36:58 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-08-03 07:56:37 +0000
commite76562ccdfb757cabbd9774c0fa679163bce8928 (patch)
tree8c368858d2501f30851834be1c146d67099eae33 /src
parent23d0a3a3f2c712cdc7d7c0f47503758a64c54843 (diff)
Add TestUtil::RunCommand.
-- MOS_MIGRATED_REVID=129106911
Diffstat (limited to 'src')
-rw-r--r--src/tools/singlejar/test_util.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/tools/singlejar/test_util.h b/src/tools/singlejar/test_util.h
index 4f92376ee4..853455e66d 100644
--- a/src/tools/singlejar/test_util.h
+++ b/src/tools/singlejar/test_util.h
@@ -16,6 +16,7 @@
#include <sys/types.h>
#include <fcntl.h>
+#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
@@ -44,6 +45,24 @@ class TestUtil {
}
}
+ // Combine the passed arguments to a shell command and run it.
+ // E.g. calling RunCommand("cmd", "arg1", "arg2", nullptr) results in
+ // running 'cmd arg1 arg2'.
+ // Returns command's return code.
+ static int RunCommand(const char *cmd, ...) {
+ std::string args_string(cmd);
+ va_list ap;
+ va_start(ap, cmd);
+ for (const char *arg = va_arg(ap, const char *); arg;
+ arg = va_arg(ap, const char *)) {
+ args_string += ' ';
+ args_string += arg;
+ }
+ va_end(ap);
+ fprintf(stderr, "Arguments: %s\n", args_string.c_str());
+ return system(args_string.c_str());
+ }
+
// List zip file contents.
static void LsZip(const char *zip_name) {
#if !defined(__APPLE__)