Revision: 2141
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2141&view=rev
Author: dermoth
Date: 2009-01-23 07:47:35 +0000 (Fri, 23 Jan 2009)
Log Message:
-----------
Add die tests for parse_ini
From: Thomas Guyot-Sionnest <[email protected]>
Modified Paths:
--------------
nagiosplug/trunk/.gitignore
nagiosplug/trunk/configure.in
nagiosplug/trunk/lib/tests/Makefile.am
nagiosplug/trunk/lib/tests/test_opts3.t
Added Paths:
-----------
nagiosplug/trunk/lib/tests/test_ini1.c
nagiosplug/trunk/lib/tests/test_ini1.t
nagiosplug/trunk/lib/tests/test_ini3.c
nagiosplug/trunk/lib/tests/test_ini3.t
Removed Paths:
-------------
nagiosplug/trunk/lib/tests/test_ini.c
nagiosplug/trunk/lib/tests/test_ini.t
Modified: nagiosplug/trunk/.gitignore
===================================================================
--- nagiosplug/trunk/.gitignore 2009-01-22 07:28:16 UTC (rev 2140)
+++ nagiosplug/trunk/.gitignore 2009-01-23 07:47:35 UTC (rev 2141)
@@ -93,7 +93,8 @@
/lib/tests/utils_disk.Po
/lib/tests/utils_tcp.Po
/lib/tests/parse_ini.Po
-/lib/tests/test_ini
+/lib/tests/test_ini1
+/lib/tests/test_ini3
/lib/tests/test_opts1
/lib/tests/test_opts2
/lib/tests/test_opts3
Modified: nagiosplug/trunk/configure.in
===================================================================
--- nagiosplug/trunk/configure.in 2009-01-22 07:28:16 UTC (rev 2140)
+++ nagiosplug/trunk/configure.in 2009-01-23 07:47:35 UTC (rev 2141)
@@ -188,7 +188,7 @@
if test "$enable_extra_opts" = "yes" ; then
AC_DEFINE(NP_EXTRA_OPTS,[1],[Enable INI file parsing.])
if test "$enable_libtap" = "yes"; then
- EXTRA_TEST="$EXTRA_TEST test_ini test_opts1 test_opts2 test_opts3"
+ EXTRA_TEST="$EXTRA_TEST test_ini1 test_ini3 test_opts1 test_opts2 test_opts3"
AC_SUBST(EXTRA_TEST)
fi
fi
Modified: nagiosplug/trunk/lib/tests/Makefile.am
===================================================================
--- nagiosplug/trunk/lib/tests/Makefile.am 2009-01-22 07:28:16 UTC (rev 2140)
+++ nagiosplug/trunk/lib/tests/Makefile.am 2009-01-23 07:47:35 UTC (rev 2141)
@@ -7,9 +7,9 @@
INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
-EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd test_base64 test_ini test_opts1 test_opts2 test_opts3
+EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd test_base64 test_ini1 test_ini3 test_opts1 test_opts2 test_opts3
-np_test_scripts = test_base64.t test_cmd.t test_disk.t test_ini.t test_opts1.t test_opts2.t test_opts3.t test_tcp.t test_utils.t
+np_test_scripts = test_base64.t test_cmd.t test_disk.t test_ini1.t test_ini3.t test_opts1.t test_opts2.t test_opts3.t test_tcp.t test_utils.t
np_test_files = config-dos.ini config-opts.ini config-tiny.ini plugin.ini plugins.ini
EXTRA_DIST = $(np_test_scripts) $(np_test_files)
@@ -28,7 +28,7 @@
AM_LDFLAGS = $(tap_ldflags) -ltap
LDADD = $(top_srcdir)/lib/libnagiosplug.a $(top_srcdir)/gl/libgnu.a
-SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini.c test_opts1.c test_opts2.c test_opts3.c
+SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c
test: ${noinst_PROGRAMS}
perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS)
Deleted: nagiosplug/trunk/lib/tests/test_ini.c
===================================================================
--- nagiosplug/trunk/lib/tests/test_ini.c 2009-01-22 07:28:16 UTC (rev 2140)
+++ nagiosplug/trunk/lib/tests/test_ini.c 2009-01-23 07:47:35 UTC (rev 2141)
@@ -1,117 +0,0 @@
-/*****************************************************************************
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-*
-*****************************************************************************/
-
-#include "common.h"
-#include "utils_base.h"
-#include "parse_ini.h"
-
-#include "tap.h"
-
-void my_free(char *string) {
- if (string != NULL) {
- printf("string:\n\t|%s|\n", string);
- free(string);
- }
-}
-
-char*
-list2str(np_arg_list *optlst)
-{
- char *optstr=NULL;
- np_arg_list *optltmp;
-
- /* Put everything as a space-separated string */
- asprintf(&optstr, "");
- while (optlst) {
- asprintf(&optstr, "%s%s ", optstr, optlst->arg);
- optltmp=optlst;
- optlst=optlst->next;
- free(optltmp);
- }
- /* Strip last whitespace */
- if (strlen(optstr)>1) optstr[strlen(optstr)-1]='\0';
-
- return optstr;
-}
-
-int
-main (int argc, char **argv)
-{
- char *optstr=NULL;
-
- plan_tests(12);
-
- optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk"));
- ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected");
- my_free(optstr);
-
- optstr=list2str(np_get_defaults("@./config-tiny.ini", "section"));
- ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name, without specific");
- my_free(optstr);
-
- /*
- * This check is expected to die - It's commented so we can eventually put
- * it in a separate file for testing the return value
- */
- /* optstr=list2str(np_get_defaults("section_unknown@./config-tiny.ini", "section"));
- ok( 0, "die if section isn't found");
- my_free(optstr); */
-
- optstr=list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk"));
- ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected");
- my_free(optstr);
-
- optstr=list2str(np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk"));
- ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's filename as section name");
- my_free(optstr);
-
- optstr=list2str(np_get_defaults("section2@./config-tiny.ini", "check_disk"));
- ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section2 with whitespace before section name");
- my_free(optstr);
-
- optstr=list2str(np_get_defaults("section3@./config-tiny.ini", "check_disk"));
- ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section3 with whitespace after section name");
- my_free(optstr);
-
- optstr=list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk"));
- ok( !strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected");
- my_free(optstr);
-
- optstr=list2str(np_get_defaults("check_mysql2@./plugin.ini", "check_disk"));
- ok( !strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected");
- my_free(optstr);
-
- optstr=list2str(np_get_defaults("check space_and_flags@./plugin.ini", "check_disk"));
- ok( !strcmp(optstr, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments");
- my_free(optstr);
-
- optstr=list2str(np_get_defaults("Section Two@./config-dos.ini", "check_disk"));
- ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-dos.ini's Section Two as expected");
- my_free(optstr);
-
- optstr=list2str(np_get_defaults("section_twice@./plugin.ini", "check_disk"));
- ok( !strcmp(optstr, "--foo=bar --bar=foo"), "plugin.ini's section_twice defined twice in the file");
- my_free(optstr);
-
- optstr=list2str(np_get_defaults("[email protected]", "check_tcp"));
- ok( !strcmp(optstr, "--escape --send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda --expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Fo
o bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda --jail"), "Long options");
- my_free(optstr);
-
- return exit_status();
-}
-
Deleted: nagiosplug/trunk/lib/tests/test_ini.t
===================================================================
--- nagiosplug/trunk/lib/tests/test_ini.t 2009-01-22 07:28:16 UTC (rev 2140)
+++ nagiosplug/trunk/lib/tests/test_ini.t 2009-01-23 07:47:35 UTC (rev 2141)
@@ -1,6 +0,0 @@
-#!/usr/bin/perl
-use Test::More;
-if (! -e "./test_ini") {
- plan skip_all => "./test_ini not compiled - please install tap library and/or enable parse-ini to test";
-}
-exec "./test_ini";
Copied: nagiosplug/trunk/lib/tests/test_ini1.c (from rev 2140, nagiosplug/trunk/lib/tests/test_ini.c)
===================================================================
--- nagiosplug/trunk/lib/tests/test_ini1.c (rev 0)
+++ nagiosplug/trunk/lib/tests/test_ini1.c 2009-01-23 07:47:35 UTC (rev 2141)
@@ -0,0 +1,117 @@
+/*****************************************************************************
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+*
+*****************************************************************************/
+
+#include "common.h"
+#include "utils_base.h"
+#include "parse_ini.h"
+
+#include "tap.h"
+
+void my_free(char *string) {
+ if (string != NULL) {
+ printf("string:\n\t|%s|\n", string);
+ free(string);
+ }
+}
+
+char*
+list2str(np_arg_list *optlst)
+{
+ char *optstr=NULL;
+ np_arg_list *optltmp;
+
+ /* Put everything as a space-separated string */
+ asprintf(&optstr, "");
+ while (optlst) {
+ asprintf(&optstr, "%s%s ", optstr, optlst->arg);
+ optltmp=optlst;
+ optlst=optlst->next;
+ free(optltmp);
+ }
+ /* Strip last whitespace */
+ if (strlen(optstr)>1) optstr[strlen(optstr)-1]='\0';
+
+ return optstr;
+}
+
+int
+main (int argc, char **argv)
+{
+ char *optstr=NULL;
+
+ plan_tests(12);
+
+ optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk"));
+ ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected");
+ my_free(optstr);
+
+ optstr=list2str(np_get_defaults("@./config-tiny.ini", "section"));
+ ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name, without specific");
+ my_free(optstr);
+
+ /*
+ * This check is expected to die - It's commented so we can eventually put
+ * it in a separate file for testing the return value
+ */
+ /* optstr=list2str(np_get_defaults("section_unknown@./config-tiny.ini", "section"));
+ ok( 0, "die if section isn't found");
+ my_free(optstr); */
+
+ optstr=list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk"));
+ ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected");
+ my_free(optstr);
+
+ optstr=list2str(np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk"));
+ ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's filename as section name");
+ my_free(optstr);
+
+ optstr=list2str(np_get_defaults("section2@./config-tiny.ini", "check_disk"));
+ ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section2 with whitespace before section name");
+ my_free(optstr);
+
+ optstr=list2str(np_get_defaults("section3@./config-tiny.ini", "check_disk"));
+ ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section3 with whitespace after section name");
+ my_free(optstr);
+
+ optstr=list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk"));
+ ok( !strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected");
+ my_free(optstr);
+
+ optstr=list2str(np_get_defaults("check_mysql2@./plugin.ini", "check_disk"));
+ ok( !strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected");
+ my_free(optstr);
+
+ optstr=list2str(np_get_defaults("check space_and_flags@./plugin.ini", "check_disk"));
+ ok( !strcmp(optstr, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments");
+ my_free(optstr);
+
+ optstr=list2str(np_get_defaults("Section Two@./config-dos.ini", "check_disk"));
+ ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-dos.ini's Section Two as expected");
+ my_free(optstr);
+
+ optstr=list2str(np_get_defaults("section_twice@./plugin.ini", "check_disk"));
+ ok( !strcmp(optstr, "--foo=bar --bar=foo"), "plugin.ini's section_twice defined twice in the file");
+ my_free(optstr);
+
+ optstr=list2str(np_get_defaults("[email protected]", "check_tcp"));
+ ok( !strcmp(optstr, "--escape --send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda --expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Fo
o bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda --jail"), "Long options");
+ my_free(optstr);
+
+ return exit_status();
+}
+
Copied: nagiosplug/trunk/lib/tests/test_ini1.t (from rev 2140, nagiosplug/trunk/lib/tests/test_ini.t)
===================================================================
--- nagiosplug/trunk/lib/tests/test_ini1.t (rev 0)
+++ nagiosplug/trunk/lib/tests/test_ini1.t 2009-01-23 07:47:35 UTC (rev 2141)
@@ -0,0 +1,6 @@
+#!/usr/bin/perl
+use Test::More;
+if (! -e "./test_ini") {
+ plan skip_all => "./test_ini not compiled - please install tap library and/or enable parse-ini to test";
+}
+exec "./test_ini";
Added: nagiosplug/trunk/lib/tests/test_ini3.c
===================================================================
--- nagiosplug/trunk/lib/tests/test_ini3.c (rev 0)
+++ nagiosplug/trunk/lib/tests/test_ini3.c 2009-01-23 07:47:35 UTC (rev 2141)
@@ -0,0 +1,33 @@
+/*****************************************************************************
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+*
+*****************************************************************************/
+
+#include "parse_ini.h"
+
+int
+main (int argc, char **argv)
+{
+
+ /*
+ * This is for testing arguments expected to die.
+ */
+
+ np_get_defaults(argv[1], argv[0]);
+
+ return 0;
+}
+
Added: nagiosplug/trunk/lib/tests/test_ini3.t
===================================================================
--- nagiosplug/trunk/lib/tests/test_ini3.t (rev 0)
+++ nagiosplug/trunk/lib/tests/test_ini3.t 2009-01-23 07:47:35 UTC (rev 2141)
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+use Test::More;
+use strict;
+use warnings;
+
+if (! -e "./test_ini") {
+ plan skip_all => "./test_ini not compiled - please install tap library and/or enable parse-ini to test";
+}
+
+# array of argument arrays
+# - First value is the expected return code
+# - 2nd value is the NAGIOS_CONFIG_PATH
+# TODO: looks like we look in default path after looking trough this variable - shall we?
+# - 3rd value is the plugin name
+# - 4th is the ini locator
+my @TESTS = (
+ [3, undef, "section", "section_unknown@./config-tiny.ini"],
+);
+
+plan tests => scalar(@TESTS);
+
+my $count=1;
+
+foreach my $args (@TESTS) {
+ my $rc = shift(@$args);
+ if (my $env = shift(@$args)) {
+ $ENV{"NAGIOS_CONFIG_PATH"} = $env;
+ } else {
+ delete($ENV{"NAGIOS_CONFIG_PATH"});
+ }
+ system {'./test_ini2'} @$args;
+ cmp_ok($?>>8, '==', $rc, "Parse-ini die " . $count++);
+}
+
Property changes on: nagiosplug/trunk/lib/tests/test_ini3.t
___________________________________________________________________
Added: svn:executable
+ *
Modified: nagiosplug/trunk/lib/tests/test_opts3.t
===================================================================
--- nagiosplug/trunk/lib/tests/test_opts3.t 2009-01-22 07:28:16 UTC (rev 2140)
+++ nagiosplug/trunk/lib/tests/test_opts3.t 2009-01-23 07:47:35 UTC (rev 2141)
@@ -28,8 +28,12 @@
my $count=1;
foreach my $args (@TESTS) {
- my $rc = shift(@$args);
- $ENV{"NAGIOS_CONFIG_PATH"} = shift(@$args);
+ my $rc = shift(@$args);
+ if (my $env = shift(@$args)) {
+ $ENV{"NAGIOS_CONFIG_PATH"} = $env;
+ } else {
+ delete($ENV{"NAGIOS_CONFIG_PATH"});
+ }
system {'./test_opts3'} @$args;
cmp_ok($?>>8, '==', $rc, "Extra-opts die " . $count++);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.