diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tests/Makefile.am | 6 | ||||
-rw-r--r-- | lib/tests/test_opts1.c | 8 | ||||
-rw-r--r-- | lib/tests/test_opts2.c | 6 | ||||
-rw-r--r-- | lib/tests/test_opts3.c | 31 | ||||
-rwxr-xr-x | lib/tests/test_opts3.t | 31 |
5 files changed, 72 insertions, 10 deletions
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am index f36c0be2..4bab2f2a 100644 --- a/lib/tests/Makefile.am +++ b/lib/tests/Makefile.am | |||
@@ -7,9 +7,9 @@ check_PROGRAMS = @EXTRA_TEST@ | |||
7 | 7 | ||
8 | INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins | 8 | INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins |
9 | 9 | ||
10 | EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd test_base64 test_ini test_opts1 test_opts2 | 10 | EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd test_base64 test_ini test_opts1 test_opts2 test_opts3 |
11 | 11 | ||
12 | np_test_scripts = test_base64.t test_cmd.t test_disk.t test_ini.t test_opts1.t test_opts2.t test_tcp.t test_utils.t | 12 | 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 |
13 | np_test_files = config-dos.ini config-opts.ini config-tiny.ini plugin.ini plugins.ini | 13 | np_test_files = config-dos.ini config-opts.ini config-tiny.ini plugin.ini plugins.ini |
14 | EXTRA_DIST = $(np_test_scripts) $(np_test_files) | 14 | EXTRA_DIST = $(np_test_scripts) $(np_test_files) |
15 | 15 | ||
@@ -28,7 +28,7 @@ AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags) | |||
28 | AM_LDFLAGS = $(tap_ldflags) -ltap | 28 | AM_LDFLAGS = $(tap_ldflags) -ltap |
29 | LDADD = $(top_srcdir)/lib/libnagiosplug.a $(top_srcdir)/gl/libgnu.a | 29 | LDADD = $(top_srcdir)/lib/libnagiosplug.a $(top_srcdir)/gl/libgnu.a |
30 | 30 | ||
31 | 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 | 31 | 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 |
32 | 32 | ||
33 | test: ${noinst_PROGRAMS} | 33 | test: ${noinst_PROGRAMS} |
34 | perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS) | 34 | perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS) |
diff --git a/lib/tests/test_opts1.c b/lib/tests/test_opts1.c index ea984032..b73e1a1f 100644 --- a/lib/tests/test_opts1.c +++ b/lib/tests/test_opts1.c | |||
@@ -1,18 +1,18 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by | 4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | *****************************************************************************/ | 16 | *****************************************************************************/ |
17 | 17 | ||
18 | #include "common.h" | 18 | #include "common.h" |
diff --git a/lib/tests/test_opts2.c b/lib/tests/test_opts2.c index 2646b2fc..e50f23e4 100644 --- a/lib/tests/test_opts2.c +++ b/lib/tests/test_opts2.c | |||
@@ -1,15 +1,15 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by | 4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
diff --git a/lib/tests/test_opts3.c b/lib/tests/test_opts3.c new file mode 100644 index 00000000..b64270da --- /dev/null +++ b/lib/tests/test_opts3.c | |||
@@ -0,0 +1,31 @@ | |||
1 | /***************************************************************************** | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 3 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | * | ||
16 | *****************************************************************************/ | ||
17 | |||
18 | #include "extra_opts.h" | ||
19 | |||
20 | int | ||
21 | main (int argc, char **argv) | ||
22 | { | ||
23 | |||
24 | /* | ||
25 | * This is for testing arguments expected to die. | ||
26 | */ | ||
27 | argv=np_extra_opts(&argc, argv, argv[0]); | ||
28 | |||
29 | return 0; | ||
30 | } | ||
31 | |||
diff --git a/lib/tests/test_opts3.t b/lib/tests/test_opts3.t new file mode 100755 index 00000000..47ec26b3 --- /dev/null +++ b/lib/tests/test_opts3.t | |||
@@ -0,0 +1,31 @@ | |||
1 | #!/usr/bin/perl | ||
2 | use Test::More; | ||
3 | use strict; | ||
4 | use warnings; | ||
5 | |||
6 | if (! -e "./test_opts3") { | ||
7 | plan skip_all => "./test_opts3 not compiled - please install tap library and/or enable parse-ini to test"; | ||
8 | } | ||
9 | |||
10 | # array of argument arrays | ||
11 | # - first value is the NAGIOS_CONFIG_PATH | ||
12 | # - 2nd value is the plugin name | ||
13 | # - 3rc and up are arguments | ||
14 | my @TESTS = ( | ||
15 | ['/nonexistent', 'prog_name', 'arg1', '--extra-opts', '--arg3', 'val2'], | ||
16 | ['.', 'prog_name', 'arg1', '--extra-opts=missing@./config-opts.ini', '--arg3', 'val2'], | ||
17 | ['.', 'prog_name', 'arg1', '--extra-opts', 'missing@./config-opts.ini', '--arg3', 'val2'], | ||
18 | ['.', 'check_missing', 'arg1', '--extra-opts=@./config-opts.ini', '--arg3', 'val2'], | ||
19 | ['.', 'check_missing', 'arg1', '--extra-opts', '--arg3', 'val2'], | ||
20 | ); | ||
21 | |||
22 | plan tests => scalar(@TESTS); | ||
23 | |||
24 | my $count=1; | ||
25 | |||
26 | foreach my $args (@TESTS) { | ||
27 | $ENV{"NAGIOS_CONFIG_PATH"} = shift(@$args); | ||
28 | system {'./test_opts3'} @$args; | ||
29 | cmp_ok($?>>8, '==', 3, "Extra-opts die " . $count++); | ||
30 | } | ||
31 | |||