2 * test-run-command.c: test run command API.
4 * (C) 2009 Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
6 * This code is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include "test-tool.h"
12 #include "git-compat-util.h"
13 #include "run-command.h"
14 #include "argv-array.h"
19 static int number_callbacks
;
20 static int parallel_next(struct child_process
*cp
,
25 struct child_process
*d
= cb
;
26 if (number_callbacks
>= 4)
29 argv_array_pushv(&cp
->args
, d
->argv
);
30 strbuf_addstr(err
, "preloaded output of a child\n");
35 static int no_job(struct child_process
*cp
,
40 strbuf_addstr(err
, "no further jobs available\n");
44 static int task_finished(int result
,
49 strbuf_addstr(err
, "asking for a quick stop\n");
53 int cmd__run_command(int argc
, const char **argv
)
55 struct child_process proc
= CHILD_PROCESS_INIT
;
60 while (!strcmp(argv
[1], "env")) {
62 die("env specifier without a value");
63 argv_array_push(&proc
.env_array
, argv
[2]);
69 proc
.argv
= (const char **)argv
+ 2;
71 if (!strcmp(argv
[1], "start-command-ENOENT")) {
72 if (start_command(&proc
) < 0 && errno
== ENOENT
)
74 fprintf(stderr
, "FAIL %s\n", argv
[1]);
77 if (!strcmp(argv
[1], "run-command"))
78 exit(run_command(&proc
));
81 proc
.argv
= (const char **)argv
+ 3;
83 if (!strcmp(argv
[1], "run-command-parallel"))
84 exit(run_processes_parallel(jobs
, parallel_next
,
87 if (!strcmp(argv
[1], "run-command-abort"))
88 exit(run_processes_parallel(jobs
, parallel_next
,
89 NULL
, task_finished
, &proc
));
91 if (!strcmp(argv
[1], "run-command-no-jobs"))
92 exit(run_processes_parallel(jobs
, no_job
,
93 NULL
, task_finished
, &proc
));
95 fprintf(stderr
, "check usage\n");