summaryrefslogtreecommitdiffstats
path: root/lib/tests/test_cmd.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-09-15 13:18:17 +0200
committerGitHub <noreply@github.com>2025-09-15 13:18:17 +0200
commit8ef825d85fb4d09c32ca44c545d6eb8d995ddea4 (patch)
tree5ab7b18797dfd5849dec7827c87ca3bb5fcb0993 /lib/tests/test_cmd.c
parenta3cf9041af810770daf5d9b83f1906fa9bb0dd11 (diff)
parent204cf956f0b3db90d079321ee957b3860da7e33f (diff)
downloadmonitoring-plugins-8ef825d85fb4d09c32ca44c545d6eb8d995ddea4.tar.gz
Merge pull request #2149 from RincewindsHat/clang-format
Clang format
Diffstat (limited to 'lib/tests/test_cmd.c')
-rw-r--r--lib/tests/test_cmd.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/tests/test_cmd.c b/lib/tests/test_cmd.c
index c8867dfb..ade0da90 100644
--- a/lib/tests/test_cmd.c
+++ b/lib/tests/test_cmd.c
@@ -67,7 +67,8 @@ int main(int argc, char **argv) {
67 result = cmd_run_array(command_line, &chld_out, &chld_err, 0); 67 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"); 68 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"); 69 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"); 70 ok(strcmp(chld_out.line[0], "this is test one") == 0,
71 "(array) Check for expected stdout output");
71 ok(result == 0, "(array) Checking exit code"); 72 ok(result == 0, "(array) Checking exit code");
72 73
73 /* ensure everything is empty again */ 74 /* ensure everything is empty again */
@@ -82,7 +83,8 @@ int main(int argc, char **argv) {
82 83
83 ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines"); 84 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"); 85 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"); 86 ok(strcmp(chld_out.line[0], "this is test one") == 0,
87 "(string) Check for expected stdout output");
86 ok(result == 0, "(string) Checking exit code"); 88 ok(result == 0, "(string) Checking exit code");
87 89
88 diag("Running plain echo command, set two"); 90 diag("Running plain echo command, set two");
@@ -104,7 +106,8 @@ int main(int argc, char **argv) {
104 result = cmd_run_array(command_line, &chld_out, &chld_err, 0); 106 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"); 107 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"); 108 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"); 109 ok(strcmp(chld_out.line[0], "this is test two") == 0,
110 "(array) Check for expected stdout output");
108 ok(result == 0, "(array) Checking exit code"); 111 ok(result == 0, "(array) Checking exit code");
109 112
110 /* ensure everything is empty again */ 113 /* ensure everything is empty again */
@@ -119,7 +122,8 @@ int main(int argc, char **argv) {
119 122
120 ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines"); 123 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"); 124 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"); 125 ok(strcmp(chld_out.line[0], "this is test one") == 0,
126 "(string) Check for expected stdout output");
123 ok(result == 0, "(string) Checking exit code"); 127 ok(result == 0, "(string) Checking exit code");
124 128
125 /* ensure everything is empty again */ 129 /* ensure everything is empty again */
@@ -130,7 +134,8 @@ int main(int argc, char **argv) {
130 ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); 134 ok(chld_err.lines == 0, "(initialised) Checking stderr is reset");
131 ok(result == UNSET, "(initialised) Checking exit code is reset"); 135 ok(result == UNSET, "(initialised) Checking exit code is reset");
132 136
133 /* Pass linefeeds via parameters through - those should be evaluated by echo to give multi line output */ 137 /* Pass linefeeds via parameters through - those should be evaluated by echo to give multi line
138 * output */
134 command_line[0] = strdup("/bin/echo"); 139 command_line[0] = strdup("/bin/echo");
135 command_line[1] = strdup("this is a test via echo\nline two\nit's line 3"); 140 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"); 141 command_line[2] = strdup("and (note space between '3' and 'and') $$ will not get evaluated");
@@ -138,9 +143,12 @@ int main(int argc, char **argv) {
138 result = cmd_run_array(command_line, &chld_out, &chld_err, 0); 143 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"); 144 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"); 145 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"); 146 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"); 147 "(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, 148 ok(strcmp(chld_out.line[1], "line two") == 0,
149 "(array) Check line 2 for expected stdout output");
150 ok(strcmp(chld_out.line[2],
151 "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"); 152 "(array) Check line 3 for expected stdout output");
145 ok(result == 0, "(array) Checking exit code"); 153 ok(result == 0, "(array) Checking exit code");
146 154
@@ -171,7 +179,8 @@ int main(int argc, char **argv) {
171 179
172 ok(chld_out.lines == 0, "/bin/sh returns no stdout when file is missing..."); 180 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"); 181 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"); 182 ok(strstr(chld_err.line[0], "non-existent-file") != NULL,
183 "And missing filename is in error message");
175 ok(result != 0, "Get non-zero return code from /bin/sh"); 184 ok(result != 0, "Get non-zero return code from /bin/sh");
176 185
177 /* ensure everything is empty again */ 186 /* ensure everything is empty again */