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 "git-compat-util.h"
12 #include "run-command.h"
13 #include "argv-array.h"
18 static int number_callbacks
;
19 static int parallel_next(struct child_process
*cp
,
24 struct child_process
*d
= cb
;
25 if (number_callbacks
>= 4)
28 argv_array_pushv(&cp
->args
, d
->argv
);
29 strbuf_addstr(err
, "preloaded output of a child\n");
34 static int no_job(struct child_process
*cp
,
39 strbuf_addstr(err
, "no further jobs available\n");
43 static int task_finished(int result
,
48 strbuf_addstr(err
, "asking for a quick stop\n");
52 int cmd_main(int argc
, const char **argv
)
54 struct child_process proc
= CHILD_PROCESS_INIT
;
59 while (!strcmp(argv
[1], "env")) {
61 die("env specifier without a value");
62 argv_array_push(&proc
.env_array
, argv
[2]);
68 proc
.argv
= (const char **)argv
+ 2;
70 if (!strcmp(argv
[1], "start-command-ENOENT")) {
71 if (start_command(&proc
) < 0 && errno
== ENOENT
)
73 fprintf(stderr
, "FAIL %s\n", argv
[1]);
76 if (!strcmp(argv
[1], "run-command"))
77 exit(run_command(&proc
));
80 proc
.argv
= (const char **)argv
+ 3;
82 if (!strcmp(argv
[1], "run-command-parallel"))
83 exit(run_processes_parallel(jobs
, parallel_next
,
86 if (!strcmp(argv
[1], "run-command-abort"))
87 exit(run_processes_parallel(jobs
, parallel_next
,
88 NULL
, task_finished
, &proc
));
90 if (!strcmp(argv
[1], "run-command-no-jobs"))
91 exit(run_processes_parallel(jobs
, no_job
,
92 NULL
, task_finished
, &proc
));
94 fprintf(stderr
, "check usage\n");