summaryrefslogtreecommitdiffabout
path: root/tests
Unidiff
Diffstat (limited to 'tests') (more/less context) (show whitespace changes)
-rw-r--r--tests/.gitignore8
-rw-r--r--tests/Makefile.am84
-rw-r--r--tests/atlocal.in10
-rw-r--r--tests/cfhelp.at76
-rw-r--r--tests/format00.at38
-rw-r--r--tests/format01.at38
-rw-r--r--tests/format02.at38
-rw-r--r--tests/gcf1.conf54
-rw-r--r--tests/gcffmt.c67
-rw-r--r--tests/gcfpeek.c76
-rw-r--r--tests/gcfset.c240
-rw-r--r--tests/peek00.at25
-rw-r--r--tests/peek01.at30
-rw-r--r--tests/peek02.at26
-rw-r--r--tests/peek03.at33
-rw-r--r--tests/set.at38
-rw-r--r--tests/testsuite.at54
17 files changed, 935 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..3110c40
--- a/dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,8 @@
1atconfig
2atlocal
3gcffmt
4gcfpeek
5gcfset
6package.m4
7testsuite
8testsuite.log
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..4312f99
--- a/dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,84 @@
1# This file is part of grecs - Gray's Extensible Configuration System
2# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
3#
4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Grecs is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16
17EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 gcf1.conf
18DISTCLEANFILES = atconfig $(check_SCRIPTS)
19MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
20
21
22## ------------ ##
23## package.m4. ##
24## ------------ ##
25
26$(srcdir)/package.m4: $(top_srcdir)/configure.ac
27 $(AM_V_GEN){ \
28 echo '# Signature of the current package.'; \
29 echo 'm4_define([AT_PACKAGE_NAME], [@PACKAGE_NAME@])'; \
30 echo 'm4_define([AT_PACKAGE_TARNAME], [@PACKAGE_TARNAME@])'; \
31 echo 'm4_define([AT_PACKAGE_VERSION], [@PACKAGE_VERSION@])'; \
32 echo 'm4_define([AT_PACKAGE_STRING], [@PACKAGE_STRING@])'; \
33 echo 'm4_define([AT_PACKAGE_BUGREPORT], [@PACKAGE_BUGREPORT@])'; \
34 } >$(srcdir)/package.m4
35
36#
37
38## ------------ ##
39## Test suite. ##
40## ------------ ##
41
42TESTSUITE_AT = \
43 format00.at\
44 format01.at\
45 format02.at\
46 cfhelp.at\
47 peek00.at\
48 peek01.at\
49 peek02.at\
50 peek03.at\
51 set.at\
52 testsuite.at
53
54TESTSUITE = $(srcdir)/testsuite
55M4=m4
56
57AUTOTEST = $(AUTOM4TE) --language=autotest
58$(TESTSUITE): package.m4 $(TESTSUITE_AT)
59 $(AUTOTEST) -I $(srcdir) testsuite.at -o $@.tmp
60 mv $@.tmp $@
61
62atconfig: $(top_builddir)/config.status
63 cd $(top_builddir) && ./config.status tests/$@
64
65clean-local:
66 test ! -f $(TESTSUITE) || $(SHELL) $(TESTSUITE) --clean
67
68check-local: atconfig atlocal $(TESTSUITE)
69 $(SHELL) $(TESTSUITE)
70
71# Run the test suite on the *installed* tree.
72#installcheck-local:
73 #$(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin
74
75noinst_PROGRAMS = \
76 gcffmt\
77 gcfpeek\
78 gcfset
79
80LDADD=../src/libgrecs.a
81INCLUDES = -I$(top_srcdir)/@GRECS_SUBDIR@/src
82
83
84
diff --git a/tests/atlocal.in b/tests/atlocal.in
new file mode 100644
index 0000000..553dae3
--- a/dev/null
+++ b/tests/atlocal.in
@@ -0,0 +1,10 @@
1# @configure_input@ -*- shell-script -*-
2# Configurable variable values for Grecs test suite.
3# Copyright (C) 2011 Sergey Poznyakoff
4
5PATH=@abs_builddir@:$PATH
6
7XFAILFILE=$abs_builddir/.badversion
8
9trap "cleanup; test -r $XFAILFILE && cat $XFAILFILE; exit $?" 1 2 13 15
10
diff --git a/tests/cfhelp.at b/tests/cfhelp.at
new file mode 100644
index 0000000..cab6624
--- a/dev/null
+++ b/tests/cfhelp.at
@@ -0,0 +1,76 @@
1# This file is part of grecs -*- Autotest -*-
2# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
3#
4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Grecs is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP(Help)
18AT_KEYWORDS([help])
19
20AT_CHECK([gcfset -cfhelp],
21[0],
22[# Sample configuration file structure.
23
24# Scalar string
25scalar <label: string>;
26
27# Configure logging logging
28logging {
29 # Send to syslog
30 syslog <arg: boolean>;
31
32 # Set logging facility
33 facility <name: string>;
34
35 # Tag logging messages with this string
36 tag <label: string>;
37
38 # Prefix each message with its priority
39 print-priority <arg: boolean>;
40}
41
42# Mailbox configuration
43mailbox {
44 # Default mailbox pattern
45 mailbox-pattern <arg: string>;
46
47 # Default mailbox type
48 mailbox-type <arg: string>;
49}
50
51# Subprogram configuration
52program <name: string> {
53 # Scalar string
54 scalar <label: string>;
55
56 # Configure logging logging
57 logging {
58 # Send to syslog
59 syslog <arg: boolean>;
60
61 # Set logging facility
62 facility <name: string>;
63
64 # Tag logging messages with this string
65 tag <label: string>;
66
67 # Prefix each message with its priority
68 print-priority <arg: boolean>;
69 }
70}
71
72# list variable
73listvar <arg: list of string>;
74])
75
76AT_CLEANUP
diff --git a/tests/format00.at b/tests/format00.at
new file mode 100644
index 0000000..e7ae15f
--- a/dev/null
+++ b/tests/format00.at
@@ -0,0 +1,38 @@
1# This file is part of grecs -*- Autotest -*-
2# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
3#
4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Grecs is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP(Format)
18AT_KEYWORDS([format format00])
19
20AT_CHECK([gcffmt $abs_srcdir/gcf1.conf],
21[0],
22[.scalar: "yes"
23.listvar: ("a", "2", "b", "c")
24.compound: "stmt" "2" "foo"
25.mailbox.mailbox-pattern: "maildir:/var/mail;type=index;param=2;user=${user}"
26.mailbox.mailbox-type: "maildir"
27.logging.syslog: "yes"
28.logging.facility: "mail"
29.program="foo".logging.syslog: "yes"
30.program="foo".logging.facility: "local1"
31.program="foo".scalar: "no"
32.program="bar".logging.syslog: "no"
33.program="bar".logging.facility: "local2"
34.program="bar".logging.tag: "baz"
35.program="bar".scalar: "25"
36])
37
38AT_CLEANUP
diff --git a/tests/format01.at b/tests/format01.at
new file mode 100644
index 0000000..b8932e4
--- a/dev/null
+++ b/tests/format01.at
@@ -0,0 +1,38 @@
1# This file is part of grecs -*- Autotest -*-
2# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
3#
4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Grecs is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP([Format: locus])
18AT_KEYWORDS([format format01])
19
20AT_CHECK([gcffmt -locus $abs_srcdir/gcf1.conf|sed 's|^.*/gcf1.conf||'],
21[0],
22[:19: .scalar: "yes"
23:22: .listvar: ("a", "2", "b", "c")
24:25: .compound: "stmt" "2" "foo"
25:28: .mailbox.mailbox-pattern: "maildir:/var/mail;type=index;param=2;user=${user}"
26:29: .mailbox.mailbox-type: "maildir"
27:33: .logging.syslog: "yes"
28:34: .logging.facility: "mail"
29:39: .program="foo".logging.syslog: "yes"
30:40: .program="foo".logging.facility: "local1"
31:42: .program="foo".scalar: "no"
32:47: .program="bar".logging.syslog: "no"
33:48: .program="bar".logging.facility: "local2"
34:49: .program="bar".logging.tag: "baz"
35:51: .program="bar".scalar: "25"
36])
37
38AT_CLEANUP
diff --git a/tests/format02.at b/tests/format02.at
new file mode 100644
index 0000000..3ebada6
--- a/dev/null
+++ b/tests/format02.at
@@ -0,0 +1,38 @@
1# This file is part of grecs -*- Autotest -*-
2# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
3#
4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Grecs is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP([Format: custom delimiter])
18AT_KEYWORDS([format format02])
19
20AT_CHECK([gcffmt -delim=/ $abs_srcdir/gcf1.conf],
21[0],
22[/scalar: "yes"
23/listvar: ("a", "2", "b", "c")
24/compound: "stmt" "2" "foo"
25/mailbox/mailbox-pattern: "maildir:/var/mail;type=index;param=2;user=${user}"
26/mailbox/mailbox-type: "maildir"
27/logging/syslog: "yes"
28/logging/facility: "mail"
29/program="foo"/logging/syslog: "yes"
30/program="foo"/logging/facility: "local1"
31/program="foo"/scalar: "no"
32/program="bar"/logging/syslog: "no"
33/program="bar"/logging/facility: "local2"
34/program="bar"/logging/tag: "baz"
35/program="bar"/scalar: "25"
36])
37
38AT_CLEANUP
diff --git a/tests/gcf1.conf b/tests/gcf1.conf
new file mode 100644
index 0000000..991fb9b
--- a/dev/null
+++ b/tests/gcf1.conf
@@ -0,0 +1,54 @@
1# This file is part of grecs - Gray's Extensible Configuration System
2# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
3#
4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Grecs is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16
17/* Scalar variable.
18*/
19scalar yes;
20
21// List variable.
22listvar ("a", 2, "b", "c");
23
24# Compound value.
25compound stmt 2 foo;
26
27mailbox {
28 mailbox-pattern "maildir:/var/mail;type=index;param=2;user=${user}";
29 mailbox-type "maildir";
30};
31
32logging {
33 syslog yes;
34 facility mail;
35}
36
37program "foo" {
38 logging {
39 syslog yes;
40 facility local1;
41 }
42 scalar no;
43}
44
45program "bar" {
46 logging {
47 syslog no;
48 facility local2;
49 tag "baz";
50 }; # Note: semicolon after closing brace is optional.
51 scalar 25;
52}
53
54 \ No newline at end of file
diff --git a/tests/gcffmt.c b/tests/gcffmt.c
new file mode 100644
index 0000000..cc67b9a
--- a/dev/null
+++ b/tests/gcffmt.c
@@ -0,0 +1,67 @@
1/* grecs - Gray's Extensible Configuration System
2 Copyright (C) 2007-2011 Sergey Poznyakoff
3
4 Grecs is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3 of the License, or (at your
7 option) any later version.
8
9 Grecs is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with Grecs. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifdef HAVE_CONFIG_H
18# include <config.h>
19#endif
20#include <string.h>
21#include <errno.h>
22#include "grecs.h"
23
24static void
25usage(const char *arg, FILE *fp, int code)
26{
27 fprintf(fp, "usage: %s [-h] [-locus] [-delim=char] file\n", arg);
28 exit(code);
29}
30
31int
32main(int argc, char **argv)
33{
34 char *progname = argv[0];
35 char *file = NULL;
36 struct grecs_node *tree, *node;
37 int flags = 0;
38
39 while (--argc) {
40 char *arg = *++argv;
41 if (strcmp(arg, "-locus") == 0)
42 flags |= GRECS_NODE_FLAG_LOCUS;
43 else if (strncmp(arg, "-delim=", 7) == 0)
44 flags |= arg[7];
45 else if (strcmp(arg, "-h") == 0)
46 usage(progname, stdout, 0);
47 else if (arg[0] == '-')
48 usage(progname, stderr, 1);
49 else if (file)
50 usage(progname, stderr, 1);
51 else
52 file = arg;
53 }
54
55 if (!file || argc)
56 usage(progname, stderr, 1);
57
58 tree = grecs_parse(file);
59 if (!tree)
60 exit(1);
61
62 for (node = tree; node; node = node->next) {
63 grecs_format_node(node, flags, stdout);
64 fputc('\n', stdout);
65 }
66 exit(0);
67}
diff --git a/tests/gcfpeek.c b/tests/gcfpeek.c
new file mode 100644
index 0000000..360000d
--- a/dev/null
+++ b/tests/gcfpeek.c
@@ -0,0 +1,76 @@
1/* grecs - Gray's Extensible Configuration System
2 Copyright (C) 2007-2011 Sergey Poznyakoff
3
4 Grecs is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3 of the License, or (at your
7 option) any later version.
8
9 Grecs is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with Grecs. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifdef HAVE_CONFIG_H
18# include <config.h>
19#endif
20#include <string.h>
21#include <errno.h>
22#include "grecs.h"
23
24static void
25usage(const char *arg, FILE *fp, int code)
26{
27 fprintf(fp, "usage: %s [-h] [-locus] [-delim=char] file path\n", arg);
28 exit(code);
29}
30
31int
32main(int argc, char **argv)
33{
34 char *progname = argv[0];
35 char *path = NULL;
36 char *file = NULL;
37 struct grecs_node *tree, *node;
38 int flags = 0;
39 int rc = 2;
40
41 while (--argc) {
42 char *arg = *++argv;
43 if (strcmp(arg, "-locus") == 0)
44 flags |= GRECS_NODE_FLAG_LOCUS;
45 else if (strncmp(arg, "-delim=", 7) == 0)
46 flags |= arg[7];
47 else if (strcmp(arg, "-h") == 0)
48 usage(progname, stdout, 0);
49 else if (arg[0] == '-')
50 usage(progname, stderr, 1);
51 else if (file) {
52 if (path)
53 usage(progname, stderr, 1);
54 else
55 path = arg;
56 } else
57 file = arg;
58 }
59
60 if (!file || !path || argc)
61 usage(progname, stderr, 1);
62
63 tree = grecs_parse(file);
64 if (!tree)
65 exit(1);
66
67 for (node = tree; node; node = node->next) {
68 node = grecs_find_node(node, path);
69 if (!node)
70 break;
71 rc = 0;
72 grecs_format_node(node, flags, stdout);
73 fputc('\n', stdout);
74 }
75 exit(rc);
76}
diff --git a/tests/gcfset.c b/tests/gcfset.c
new file mode 100644
index 0000000..d2264e3
--- a/dev/null
+++ b/tests/gcfset.c
@@ -0,0 +1,240 @@
1/* grecs - Gray's Extensible Configuration System
2 Copyright (C) 2007-2011 Sergey Poznyakoff
3
4 Grecs is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3 of the License, or (at your
7 option) any later version.
8
9 Grecs is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with Grecs. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifdef HAVE_CONFIG_H
18# include <config.h>
19#endif
20#include <stddef.h>
21#include <string.h>
22#include <errno.h>
23#include "grecs.h"
24
25struct logging_setup {
26 int use_syslog;
27 int print_priority;
28 char *tag;
29 char *facility;
30};
31
32struct logging_setup logging_setup;
33char *scalar_string;
34char *mailbox_pattern;
35char *mailbox_type;
36struct grecs_list *listvar;
37
38struct program {
39 char *name;
40 struct logging_setup logging_setup;
41 char *scalar_string;
42 grecs_locus_t locus;
43 struct program *next;
44};
45
46struct grecs_list *proglist;
47
48static int
49cb_logging_facility(enum grecs_callback_command cmd,
50 grecs_locus_t *locus,
51 void *varptr,
52 grecs_value_t *value,
53 void *cb_data)
54{
55 if (cmd != grecs_callback_set_value) {
56 grecs_error(locus, 0, _("Unexpected block statement"));
57 return 1;
58 }
59 if (!value || value->type != GRECS_TYPE_STRING) {
60 grecs_error(locus, 0, _("expected string argument"));
61 return 1;
62 }
63
64 *(char**)varptr = grecs_strdup(value->v.string);
65 return 0;
66}
67
68static struct grecs_keyword logging_kwtab[] = {
69 { "syslog", NULL, "Send to syslog",
70 grecs_type_bool, NULL,
71 offsetof(struct logging_setup, use_syslog) },
72 { "facility", "name", "Set logging facility",
73 grecs_type_string, NULL,
74 offsetof(struct logging_setup, facility), cb_logging_facility },
75 { "tag", "label", "Tag logging messages with this string",
76 grecs_type_string, NULL,
77 offsetof(struct logging_setup, tag) },
78 { "print-priority", NULL, "Prefix each message with its priority",
79 grecs_type_bool, NULL,
80 offsetof(struct logging_setup, print_priority) },
81 { NULL },
82};
83
84static struct grecs_keyword mailbox_kwtab[] = {
85 { "mailbox-pattern", NULL, "Default mailbox pattern",
86 grecs_type_string, &mailbox_pattern },
87 { "mailbox-type", NULL, "Default mailbox type",
88 grecs_type_string, &mailbox_type },
89 { NULL },
90};
91
92
93static struct grecs_keyword program_kwtab[] = {
94 { "scalar", "label", "Scalar string",
95 grecs_type_string, NULL, offsetof(struct program,scalar_string) },
96 { "logging", NULL, N_("Configure logging logging"),
97 grecs_type_section, NULL, offsetof(struct program,logging_setup),
98 NULL, NULL, logging_kwtab },
99 { NULL }
100};
101
102static int
103cb_program(enum grecs_callback_command cmd,
104 grecs_locus_t *locus,
105 void *varptr,
106 grecs_value_t *value,
107 void *cb_data)
108{
109 struct program *prog;
110 void **pdata = cb_data;
111
112 switch (cmd) {
113 case grecs_callback_section_begin:
114 if (!value || value->type != GRECS_TYPE_STRING) {
115 grecs_error(locus, 0, _("tag must be a string"));
116 return 0;
117 }
118 prog = grecs_zalloc(sizeof(*prog));
119 prog->name = grecs_strdup(value->v.string);
120 prog->locus = *locus;
121 *pdata = prog;
122 break;
123
124 case grecs_callback_section_end:
125 prog = *pdata;
126 if (!proglist)
127 proglist = grecs_list_create();
128 grecs_list_append(proglist, prog);
129 break;
130
131 case grecs_callback_set_value:
132 grecs_error(locus, 0, _("invalid use of block statement"));
133 }
134 return 0;
135}
136
137static struct grecs_keyword main_kwtab[] = {
138 { "scalar", "label", "Scalar string",
139 grecs_type_string, &scalar_string },
140 { "logging", NULL, N_("Configure logging logging"),
141 grecs_type_section, &logging_setup, 0, NULL,
142 NULL, logging_kwtab },
143 { "mailbox", NULL, N_("Mailbox configuration"),
144 grecs_type_section, NULL, 0, NULL, NULL, mailbox_kwtab },
145 { "program", "name: string", "Subprogram configuration",
146 grecs_type_section, NULL, 0, cb_program, NULL, program_kwtab },
147 { "listvar", NULL, "list variable",
148 grecs_type_string|GRECS_LIST, &listvar },
149 { NULL }
150};
151
152
153#define S(s) ((s) ? (s) : "(null)")
154
155static void
156print_logging_setup(struct logging_setup *p)
157{
158 printf("logging: %d/%s/%s/%d\n",
159 p->use_syslog, S(p->facility), S(p->tag), p->print_priority);
160}
161
162static void
163print_program(struct program *prog)
164{
165 printf("Program %s:\n", prog->name);
166 printf("scalar = %s\n", S(prog->scalar_string));
167 print_logging_setup(&prog->logging_setup);
168}
169
170
171static void
172usage(const char *arg, FILE *fp, int code)
173{
174 fprintf(fp, "usage: %s [-h] [-cfhelp] file\n", arg);
175 exit(code);
176}
177
178int
179main(int argc, char **argv)
180{
181 char *progname = argv[0];
182 const char *file = NULL;
183 struct grecs_node *tree;
184 int cfhelp = 0;
185
186 while (--argc) {
187 char *arg = *++argv;
188 if (strcmp(arg, "-cfhelp") == 0)
189 cfhelp = 1;
190 else if (strcmp(arg, "-h") == 0)
191 usage(progname, stdout, 0);
192 else if (arg[0] == '-')
193 usage(progname, stderr, 1);
194 else if (file)
195 usage(progname, stderr, 1);
196 else
197 file = arg;
198 }
199
200 if ((!file && !cfhelp) || argc)
201 usage(progname, stderr, 1);
202
203 if (cfhelp) {
204 static char docstring[] =
205 "Sample configuration file structure.\n";
206 grecs_format_docstring(docstring, 0, stdout);
207 grecs_format_statement_array(main_kwtab, 1, 0, stdout);
208 exit(0);
209 }
210
211 tree = grecs_parse(file);
212 if (!tree)
213 exit(2);
214
215 if (grecs_tree_process(tree, main_kwtab))
216 exit(2);
217
218 printf("Global settings:\n");
219 printf("scalar = %s\n", S(scalar_string));
220 if (listvar) {
221 struct grecs_list_entry *ep;
222 printf("listvar =");
223 for (ep = listvar->head; ep; ep = ep->next)
224 printf(" \"%s\"", (char*)ep->data);
225 putchar('\n');
226 }
227
228 print_logging_setup(&logging_setup);
229
230 if (proglist) {
231 struct grecs_list_entry *ep;
232
233 printf("Programs configured: %d\n", grecs_list_size(proglist));
234 for (ep = proglist->head; ep; ep = ep->next)
235 print_program(ep->data);
236 }
237
238 exit(0);
239}
240
diff --git a/tests/peek00.at b/tests/peek00.at
new file mode 100644
index 0000000..a3d86ac
--- a/dev/null
+++ b/tests/peek00.at
@@ -0,0 +1,25 @@
1# This file is part of grecs -*- Autotest -*-
2# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
3#
4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Grecs is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP(Peek)
18AT_KEYWORDS([peek peek00])
19
20AT_CHECK([gcfpeek $abs_srcdir/gcf1.conf .scalar],
21[0],
22[.scalar: "yes"
23])
24
25AT_CLEANUP
diff --git a/tests/peek01.at b/tests/peek01.at
new file mode 100644
index 0000000..c76261c
--- a/dev/null
+++ b/tests/peek01.at
@@ -0,0 +1,30 @@
1# This file is part of grecs -*- Autotest -*-
2# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
3#
4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Grecs is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP(Peek: nested)
18AT_KEYWORDS([peek peek01])
19
20AT_CHECK([gcfpeek $abs_srcdir/gcf1.conf .program="foo".scalar],
21[0],
22[.program="foo".scalar: "no"
23])
24
25AT_CHECK([gcfpeek $abs_srcdir/gcf1.conf .program="bar".scalar],
26[0],
27[.program="bar".scalar: "25"
28])
29
30AT_CLEANUP
diff --git a/tests/peek02.at b/tests/peek02.at
new file mode 100644
index 0000000..e5c1a4a
--- a/dev/null
+++ b/tests/peek02.at
@@ -0,0 +1,26 @@
1# This file is part of grecs -*- Autotest -*-
2# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
3#
4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Grecs is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP(Peek: block)
18AT_KEYWORDS([peek peek02])
19
20AT_CHECK([gcfpeek $abs_srcdir/gcf1.conf .logging],
21[0],
22[.logging.syslog: "yes"
23.logging.facility: "mail"
24])
25
26AT_CLEANUP
diff --git a/tests/peek03.at b/tests/peek03.at
new file mode 100644
index 0000000..7590b0c
--- a/dev/null
+++ b/tests/peek03.at
@@ -0,0 +1,33 @@
1# This file is part of grecs -*- Autotest -*-
2# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
3#
4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Grecs is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP(Peek: block nested)
18AT_KEYWORDS([peek peek03])
19
20AT_CHECK([gcfpeek $abs_srcdir/gcf1.conf .program=foo.logging],
21[0],
22[.program="foo".logging.syslog: "yes"
23.program="foo".logging.facility: "local1"
24])
25
26AT_CHECK([gcfpeek $abs_srcdir/gcf1.conf .program=bar.logging],
27[0],
28[.program="bar".logging.syslog: "no"
29.program="bar".logging.facility: "local2"
30.program="bar".logging.tag: "baz"
31])
32
33AT_CLEANUP
diff --git a/tests/set.at b/tests/set.at
new file mode 100644
index 0000000..7bad831
--- a/dev/null
+++ b/tests/set.at
@@ -0,0 +1,38 @@
1# This file is part of grecs -*- Autotest -*-
2# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
3#
4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Grecs is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP([Set values])
18AT_KEYWORDS([set])
19
20AT_CHECK([gcfset $abs_srcdir/gcf1.conf 2>err||exit $?
21sed 's|^.*/gcf1.conf||' err >&2],
22[0],
23[Global settings:
24scalar = yes
25listvar = "a" "2" "b" "c"
26logging: 1/mail/(null)/0
27Programs configured: 2
28Program foo:
29scalar = no
30logging: 1/local1/(null)/0
31Program bar:
32scalar = 25
33logging: 0/local2/baz/0
34],
35[:25: Unknown keyword
36])
37
38AT_CLEANUP \ No newline at end of file
diff --git a/tests/testsuite.at b/tests/testsuite.at
new file mode 100644
index 0000000..3b0ec84
--- a/dev/null
+++ b/tests/testsuite.at
@@ -0,0 +1,54 @@
1# This file is part of grecs - Gray's Extensible Configuration System -*- Autotest -*-
2# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
3#
4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Grecs is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16
17m4_version_prereq([2.52g])
18
19dnl # Standard exit codes (from sysexits.h)
20m4_define([EX_OK], 0) dnl successful termination
21m4_define([EX__BASE], 64) dnl base value for error messages
22m4_define([EX_USAGE], 64) dnl command line usage error
23m4_define([EX_DATAERR], 65) dnl data format error
24m4_define([EX_NOINPUT], 66) dnl cannot open input
25m4_define([EX_NOUSER], 67) dnl addressee unknown
26m4_define([EX_NOHOST], 68) dnl host name unknown
27m4_define([EX_UNAVAILABLE], 69) dnl service unavailable
28m4_define([EX_SOFTWARE], 70) dnl internal software error
29m4_define([EX_OSERR], 71) dnl system error (e.g., can't fork)
30m4_define([EX_OSFILE], 72) dnl critical OS file missing
31m4_define([EX_CANTCREAT], 73) dnl can't create (user) output file
32m4_define([EX_IOERR], 74) dnl input/output error
33m4_define([EX_TEMPFAIL], 75) dnl temp failure; user is invited to retry
34m4_define([EX_PROTOCOL], 76) dnl remote error in protocol
35m4_define([EX_NOPERM], 77) dnl permission denied
36m4_define([EX_CONFIG], 78) dnl configuration error
37
38m4_define([AT_SKIP_TEST],[exit 77])
39
40dnl # Begin tests
41
42AT_INIT
43m4_include([format00.at])
44m4_include([format01.at])
45m4_include([format02.at])
46
47m4_include([peek00.at])
48m4_include([peek01.at])
49m4_include([peek02.at])
50m4_include([peek03.at])
51
52m4_include([cfhelp.at])
53m4_include([set.at])
54# End of testsuite.at

Return to:

Send suggestions and report system problems to the System administrator.