diff options
Diffstat (limited to 'lib/tests/test_cmd.c')
| -rw-r--r-- | lib/tests/test_cmd.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/lib/tests/test_cmd.c b/lib/tests/test_cmd.c index c8867dfb..d51016cc 100644 --- a/lib/tests/test_cmd.c +++ b/lib/tests/test_cmd.c | |||
| @@ -38,36 +38,35 @@ char *get_command(char *const *line) { | |||
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | int main(int argc, char **argv) { | 40 | int main(int argc, char **argv) { |
| 41 | char **command_line = malloc(sizeof(char *) * COMMAND_LINE); | ||
| 42 | char *command = NULL; | ||
| 43 | char *perl; | ||
| 44 | output chld_out, chld_err; | ||
| 45 | int c; | ||
| 46 | int result = UNSET; | ||
| 47 | |||
| 48 | plan_tests(51); | 41 | plan_tests(51); |
| 49 | 42 | ||
| 50 | diag("Running plain echo command, set one"); | 43 | diag("Running plain echo command, set one"); |
| 51 | 44 | ||
| 52 | /* ensure everything is empty before we begin */ | 45 | /* ensure everything is empty before we begin */ |
| 46 | |||
| 47 | output chld_out; | ||
| 53 | memset(&chld_out, 0, sizeof(output)); | 48 | memset(&chld_out, 0, sizeof(output)); |
| 49 | output chld_err; | ||
| 54 | memset(&chld_err, 0, sizeof(output)); | 50 | memset(&chld_err, 0, sizeof(output)); |
| 55 | ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); | 51 | ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); |
| 56 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); | 52 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); |
| 53 | int result = UNSET; | ||
| 57 | ok(result == UNSET, "(initialised) Checking exit code is reset"); | 54 | ok(result == UNSET, "(initialised) Checking exit code is reset"); |
| 58 | 55 | ||
| 56 | char **command_line = malloc(sizeof(char *) * COMMAND_LINE); | ||
| 59 | command_line[0] = strdup("/bin/echo"); | 57 | command_line[0] = strdup("/bin/echo"); |
| 60 | command_line[1] = strdup("this"); | 58 | command_line[1] = strdup("this"); |
| 61 | command_line[2] = strdup("is"); | 59 | command_line[2] = strdup("is"); |
| 62 | command_line[3] = strdup("test"); | 60 | command_line[3] = strdup("test"); |
| 63 | command_line[4] = strdup("one"); | 61 | command_line[4] = strdup("one"); |
| 64 | 62 | ||
| 65 | command = get_command(command_line); | 63 | char *command = get_command(command_line); |
| 66 | 64 | ||
| 67 | result = cmd_run_array(command_line, &chld_out, &chld_err, 0); | 65 | result = cmd_run_array(command_line, &chld_out, &chld_err, 0); |
| 68 | ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines"); | 66 | ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines"); |
| 69 | ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); | 67 | ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); |
| 70 | ok(strcmp(chld_out.line[0], "this is test one") == 0, "(array) Check for expected stdout output"); | 68 | ok(strcmp(chld_out.line[0], "this is test one") == 0, |
| 69 | "(array) Check for expected stdout output"); | ||
| 71 | ok(result == 0, "(array) Checking exit code"); | 70 | ok(result == 0, "(array) Checking exit code"); |
| 72 | 71 | ||
| 73 | /* ensure everything is empty again */ | 72 | /* ensure everything is empty again */ |
| @@ -82,7 +81,8 @@ int main(int argc, char **argv) { | |||
| 82 | 81 | ||
| 83 | ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines"); | 82 | ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines"); |
| 84 | ok(chld_err.lines == 0, "(string) Check for expected number of stderr lines"); | 83 | ok(chld_err.lines == 0, "(string) Check for expected number of stderr lines"); |
| 85 | ok(strcmp(chld_out.line[0], "this is test one") == 0, "(string) Check for expected stdout output"); | 84 | ok(strcmp(chld_out.line[0], "this is test one") == 0, |
| 85 | "(string) Check for expected stdout output"); | ||
| 86 | ok(result == 0, "(string) Checking exit code"); | 86 | ok(result == 0, "(string) Checking exit code"); |
| 87 | 87 | ||
| 88 | diag("Running plain echo command, set two"); | 88 | diag("Running plain echo command, set two"); |
| @@ -104,7 +104,8 @@ int main(int argc, char **argv) { | |||
| 104 | result = cmd_run_array(command_line, &chld_out, &chld_err, 0); | 104 | result = cmd_run_array(command_line, &chld_out, &chld_err, 0); |
| 105 | ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines"); | 105 | ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines"); |
| 106 | ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); | 106 | ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); |
| 107 | ok(strcmp(chld_out.line[0], "this is test two") == 0, "(array) Check for expected stdout output"); | 107 | ok(strcmp(chld_out.line[0], "this is test two") == 0, |
| 108 | "(array) Check for expected stdout output"); | ||
| 108 | ok(result == 0, "(array) Checking exit code"); | 109 | ok(result == 0, "(array) Checking exit code"); |
| 109 | 110 | ||
| 110 | /* ensure everything is empty again */ | 111 | /* ensure everything is empty again */ |
| @@ -119,7 +120,8 @@ int main(int argc, char **argv) { | |||
| 119 | 120 | ||
| 120 | ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines"); | 121 | ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines"); |
| 121 | ok(chld_err.lines == 0, "(string) Check for expected number of stderr lines"); | 122 | ok(chld_err.lines == 0, "(string) Check for expected number of stderr lines"); |
| 122 | ok(strcmp(chld_out.line[0], "this is test one") == 0, "(string) Check for expected stdout output"); | 123 | ok(strcmp(chld_out.line[0], "this is test one") == 0, |
| 124 | "(string) Check for expected stdout output"); | ||
| 123 | ok(result == 0, "(string) Checking exit code"); | 125 | ok(result == 0, "(string) Checking exit code"); |
| 124 | 126 | ||
| 125 | /* ensure everything is empty again */ | 127 | /* ensure everything is empty again */ |
| @@ -130,7 +132,8 @@ int main(int argc, char **argv) { | |||
| 130 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); | 132 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); |
| 131 | ok(result == UNSET, "(initialised) Checking exit code is reset"); | 133 | ok(result == UNSET, "(initialised) Checking exit code is reset"); |
| 132 | 134 | ||
| 133 | /* Pass linefeeds via parameters through - those should be evaluated by echo to give multi line output */ | 135 | /* Pass linefeeds via parameters through - those should be evaluated by echo to give multi line |
| 136 | * output */ | ||
| 134 | command_line[0] = strdup("/bin/echo"); | 137 | command_line[0] = strdup("/bin/echo"); |
| 135 | command_line[1] = strdup("this is a test via echo\nline two\nit's line 3"); | 138 | command_line[1] = strdup("this is a test via echo\nline two\nit's line 3"); |
| 136 | command_line[2] = strdup("and (note space between '3' and 'and') $$ will not get evaluated"); | 139 | command_line[2] = strdup("and (note space between '3' and 'and') $$ will not get evaluated"); |
| @@ -138,9 +141,12 @@ int main(int argc, char **argv) { | |||
| 138 | result = cmd_run_array(command_line, &chld_out, &chld_err, 0); | 141 | result = cmd_run_array(command_line, &chld_out, &chld_err, 0); |
| 139 | ok(chld_out.lines == 3, "(array) Check for expected number of stdout lines"); | 142 | ok(chld_out.lines == 3, "(array) Check for expected number of stdout lines"); |
| 140 | ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); | 143 | ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); |
| 141 | ok(strcmp(chld_out.line[0], "this is a test via echo") == 0, "(array) Check line 1 for expected stdout output"); | 144 | ok(strcmp(chld_out.line[0], "this is a test via echo") == 0, |
| 142 | ok(strcmp(chld_out.line[1], "line two") == 0, "(array) Check line 2 for expected stdout output"); | 145 | "(array) Check line 1 for expected stdout output"); |
| 143 | ok(strcmp(chld_out.line[2], "it's line 3 and (note space between '3' and 'and') $$ will not get evaluated") == 0, | 146 | ok(strcmp(chld_out.line[1], "line two") == 0, |
| 147 | "(array) Check line 2 for expected stdout output"); | ||
| 148 | ok(strcmp(chld_out.line[2], | ||
| 149 | "it's line 3 and (note space between '3' and 'and') $$ will not get evaluated") == 0, | ||
| 144 | "(array) Check line 3 for expected stdout output"); | 150 | "(array) Check line 3 for expected stdout output"); |
| 145 | ok(result == 0, "(array) Checking exit code"); | 151 | ok(result == 0, "(array) Checking exit code"); |
| 146 | 152 | ||
| @@ -171,7 +177,8 @@ int main(int argc, char **argv) { | |||
| 171 | 177 | ||
| 172 | ok(chld_out.lines == 0, "/bin/sh returns no stdout when file is missing..."); | 178 | ok(chld_out.lines == 0, "/bin/sh returns no stdout when file is missing..."); |
| 173 | ok(chld_err.lines == 1, "...but does give an error line"); | 179 | ok(chld_err.lines == 1, "...but does give an error line"); |
| 174 | ok(strstr(chld_err.line[0], "non-existent-file") != NULL, "And missing filename is in error message"); | 180 | ok(strstr(chld_err.line[0], "non-existent-file") != NULL, |
| 181 | "And missing filename is in error message"); | ||
| 175 | ok(result != 0, "Get non-zero return code from /bin/sh"); | 182 | ok(result != 0, "Get non-zero return code from /bin/sh"); |
| 176 | 183 | ||
| 177 | /* ensure everything is empty again */ | 184 | /* ensure everything is empty again */ |
