summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2007-12-11 12:05:16 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2007-12-11 12:05:16 (GMT)
commitba6b4cab4125b5f07f6e37c8504824850425267f (patch)
treeaa6dd866c3227576b4d489c81ad4caa992b8a4c9
parent1fcc40c49b349a1bd0e3e73e40fbd7ae88fc1c37 (diff)
downloadmonitoring-plugins-ba6b4cab4125b5f07f6e37c8504824850425267f.tar.gz
Fixed test so works on MacOSX (use /bin/sh instead of /bin/grep).
Added extra test for missing command - should drop into STATE_UNKNOWN git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1863 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--lib/tests/test_cmd.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/tests/test_cmd.c b/lib/tests/test_cmd.c
index 4da76a9..7d0915b 100644
--- a/lib/tests/test_cmd.c
+++ b/lib/tests/test_cmd.c
@@ -51,7 +51,7 @@ main (int argc, char **argv)
51 int c; 51 int c;
52 int result = UNSET; 52 int result = UNSET;
53 53
54 plan_tests(47); 54 plan_tests(50);
55 55
56 diag ("Running plain echo command, set one"); 56 diag ("Running plain echo command, set one");
57 57
@@ -194,17 +194,32 @@ main (int argc, char **argv)
194 result = UNSET; 194 result = UNSET;
195 195
196 command = (char *)malloc(COMMAND_LINE); 196 command = (char *)malloc(COMMAND_LINE);
197 strcpy(command, "/bin/grep pattern non-existant-file"); 197 strcpy(command, "/bin/sh non-existant-file");
198 result = cmd_run (command, &chld_out, &chld_err, 0); 198 result = cmd_run (command, &chld_out, &chld_err, 0);
199 199
200 ok (chld_out.lines == 0, 200 ok (chld_out.lines == 0,
201 "Grep returns no stdout when file is missing..."); 201 "/bin/sh returns no stdout when file is missing...");
202 ok (chld_err.lines == 1, 202 ok (chld_err.lines == 1,
203 "...but does give an error line"); 203 "...but does give an error line");
204 ok (strstr(chld_err.line[0],"non-existant-file") != NULL, "And missing filename is in error message"); 204 ok (strstr(chld_err.line[0],"non-existant-file") != NULL, "And missing filename is in error message");
205 ok (result == 2, "Get return code 2 from grep"); 205 ok (result == 127, "Get return code 127 from /bin/sh");
206 206
207 207
208 /* ensure everything is empty again */
209 memset (&chld_out, 0, sizeof (output));
210 memset (&chld_err, 0, sizeof (output));
211 result = UNSET;
212
213 command = (char *)malloc(COMMAND_LINE);
214 strcpy(command, "/bin/non-existant-command");
215 result = cmd_run (command, &chld_out, &chld_err, 0);
216
217 ok (chld_out.lines == 0,
218 "/bin/non-existant-command returns no stdout...");
219 ok (chld_err.lines == 0,
220 "...and no stderr output either");
221 ok (result == 3, "Get return code 3 = UNKNOWN when command does not exist");
222
208 223
209 return exit_status (); 224 return exit_status ();
210} 225}