refspec-api: avoid uninitialized field in refspec item
[git/git-svn.git] / t / helper / test-run-command.c
blob2cc93bb69c522d99491cd8a9e02e211b2c3df807
1 /*
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.
9 */
11 #include "test-tool.h"
12 #include "git-compat-util.h"
13 #include "run-command.h"
14 #include "argv-array.h"
15 #include "strbuf.h"
16 #include <string.h>
17 #include <errno.h>
19 static int number_callbacks;
20 static int parallel_next(struct child_process *cp,
21 struct strbuf *err,
22 void *cb,
23 void **task_cb)
25 struct child_process *d = cb;
26 if (number_callbacks >= 4)
27 return 0;
29 argv_array_pushv(&cp->args, d->argv);
30 strbuf_addstr(err, "preloaded output of a child\n");
31 number_callbacks++;
32 return 1;
35 static int no_job(struct child_process *cp,
36 struct strbuf *err,
37 void *cb,
38 void **task_cb)
40 strbuf_addstr(err, "no further jobs available\n");
41 return 0;
44 static int task_finished(int result,
45 struct strbuf *err,
46 void *pp_cb,
47 void *pp_task_cb)
49 strbuf_addstr(err, "asking for a quick stop\n");
50 return 1;
53 int cmd__run_command(int argc, const char **argv)
55 struct child_process proc = CHILD_PROCESS_INIT;
56 int jobs;
58 if (argc < 3)
59 return 1;
60 while (!strcmp(argv[1], "env")) {
61 if (!argv[2])
62 die("env specifier without a value");
63 argv_array_push(&proc.env_array, argv[2]);
64 argv += 2;
65 argc -= 2;
67 if (argc < 3)
68 return 1;
69 proc.argv = (const char **)argv + 2;
71 if (!strcmp(argv[1], "start-command-ENOENT")) {
72 if (start_command(&proc) < 0 && errno == ENOENT)
73 return 0;
74 fprintf(stderr, "FAIL %s\n", argv[1]);
75 return 1;
77 if (!strcmp(argv[1], "run-command"))
78 exit(run_command(&proc));
80 jobs = atoi(argv[2]);
81 proc.argv = (const char **)argv + 3;
83 if (!strcmp(argv[1], "run-command-parallel"))
84 exit(run_processes_parallel(jobs, parallel_next,
85 NULL, NULL, &proc));
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");
96 return 1;