aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-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
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,8 @@
+atconfig
+atlocal
+gcffmt
+gcfpeek
+gcfset
+package.m4
+testsuite
+testsuite.log
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..4312f99
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,84 @@
+# This file is part of grecs - Gray's Extensible Configuration System
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs 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, or (at your option)
+# any later version.
+#
+# Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 gcf1.conf
+DISTCLEANFILES = atconfig $(check_SCRIPTS)
+MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
+
+
+## ------------ ##
+## package.m4. ##
+## ------------ ##
+
+$(srcdir)/package.m4: $(top_srcdir)/configure.ac
+ $(AM_V_GEN){ \
+ echo '# Signature of the current package.'; \
+ echo 'm4_define([AT_PACKAGE_NAME], [@PACKAGE_NAME@])'; \
+ echo 'm4_define([AT_PACKAGE_TARNAME], [@PACKAGE_TARNAME@])'; \
+ echo 'm4_define([AT_PACKAGE_VERSION], [@PACKAGE_VERSION@])'; \
+ echo 'm4_define([AT_PACKAGE_STRING], [@PACKAGE_STRING@])'; \
+ echo 'm4_define([AT_PACKAGE_BUGREPORT], [@PACKAGE_BUGREPORT@])'; \
+ } >$(srcdir)/package.m4
+
+#
+
+## ------------ ##
+## Test suite. ##
+## ------------ ##
+
+TESTSUITE_AT = \
+ format00.at\
+ format01.at\
+ format02.at\
+ cfhelp.at\
+ peek00.at\
+ peek01.at\
+ peek02.at\
+ peek03.at\
+ set.at\
+ testsuite.at
+
+TESTSUITE = $(srcdir)/testsuite
+M4=m4
+
+AUTOTEST = $(AUTOM4TE) --language=autotest
+$(TESTSUITE): package.m4 $(TESTSUITE_AT)
+ $(AUTOTEST) -I $(srcdir) testsuite.at -o $@.tmp
+ mv $@.tmp $@
+
+atconfig: $(top_builddir)/config.status
+ cd $(top_builddir) && ./config.status tests/$@
+
+clean-local:
+ test ! -f $(TESTSUITE) || $(SHELL) $(TESTSUITE) --clean
+
+check-local: atconfig atlocal $(TESTSUITE)
+ $(SHELL) $(TESTSUITE)
+
+# Run the test suite on the *installed* tree.
+#installcheck-local:
+# $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin
+
+noinst_PROGRAMS = \
+ gcffmt\
+ gcfpeek\
+ gcfset
+
+LDADD=../src/libgrecs.a
+INCLUDES = -I$(top_srcdir)/@GRECS_SUBDIR@/src
+
+
+
diff --git a/tests/atlocal.in b/tests/atlocal.in
new file mode 100644
index 0000000..553dae3
--- /dev/null
+++ b/tests/atlocal.in
@@ -0,0 +1,10 @@
+# @configure_input@ -*- shell-script -*-
+# Configurable variable values for Grecs test suite.
+# Copyright (C) 2011 Sergey Poznyakoff
+
+PATH=@abs_builddir@:$PATH
+
+XFAILFILE=$abs_builddir/.badversion
+
+trap "cleanup; test -r $XFAILFILE && cat $XFAILFILE; exit $?" 1 2 13 15
+
diff --git a/tests/cfhelp.at b/tests/cfhelp.at
new file mode 100644
index 0000000..cab6624
--- /dev/null
+++ b/tests/cfhelp.at
@@ -0,0 +1,76 @@
+# This file is part of grecs -*- Autotest -*-
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs 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, or (at your option)
+# any later version.
+#
+# Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP(Help)
+AT_KEYWORDS([help])
+
+AT_CHECK([gcfset -cfhelp],
+[0],
+[# Sample configuration file structure.
+
+# Scalar string
+scalar <label: string>;
+
+# Configure logging logging
+logging {
+ # Send to syslog
+ syslog <arg: boolean>;
+
+ # Set logging facility
+ facility <name: string>;
+
+ # Tag logging messages with this string
+ tag <label: string>;
+
+ # Prefix each message with its priority
+ print-priority <arg: boolean>;
+}
+
+# Mailbox configuration
+mailbox {
+ # Default mailbox pattern
+ mailbox-pattern <arg: string>;
+
+ # Default mailbox type
+ mailbox-type <arg: string>;
+}
+
+# Subprogram configuration
+program <name: string> {
+ # Scalar string
+ scalar <label: string>;
+
+ # Configure logging logging
+ logging {
+ # Send to syslog
+ syslog <arg: boolean>;
+
+ # Set logging facility
+ facility <name: string>;
+
+ # Tag logging messages with this string
+ tag <label: string>;
+
+ # Prefix each message with its priority
+ print-priority <arg: boolean>;
+ }
+}
+
+# list variable
+listvar <arg: list of string>;
+])
+
+AT_CLEANUP
diff --git a/tests/format00.at b/tests/format00.at
new file mode 100644
index 0000000..e7ae15f
--- /dev/null
+++ b/tests/format00.at
@@ -0,0 +1,38 @@
+# This file is part of grecs -*- Autotest -*-
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs 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, or (at your option)
+# any later version.
+#
+# Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP(Format)
+AT_KEYWORDS([format format00])
+
+AT_CHECK([gcffmt $abs_srcdir/gcf1.conf],
+[0],
+[.scalar: "yes"
+.listvar: ("a", "2", "b", "c")
+.compound: "stmt" "2" "foo"
+.mailbox.mailbox-pattern: "maildir:/var/mail;type=index;param=2;user=${user}"
+.mailbox.mailbox-type: "maildir"
+.logging.syslog: "yes"
+.logging.facility: "mail"
+.program="foo".logging.syslog: "yes"
+.program="foo".logging.facility: "local1"
+.program="foo".scalar: "no"
+.program="bar".logging.syslog: "no"
+.program="bar".logging.facility: "local2"
+.program="bar".logging.tag: "baz"
+.program="bar".scalar: "25"
+])
+
+AT_CLEANUP
diff --git a/tests/format01.at b/tests/format01.at
new file mode 100644
index 0000000..b8932e4
--- /dev/null
+++ b/tests/format01.at
@@ -0,0 +1,38 @@
+# This file is part of grecs -*- Autotest -*-
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs 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, or (at your option)
+# any later version.
+#
+# Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Format: locus])
+AT_KEYWORDS([format format01])
+
+AT_CHECK([gcffmt -locus $abs_srcdir/gcf1.conf|sed 's|^.*/gcf1.conf||'],
+[0],
+[:19: .scalar: "yes"
+:22: .listvar: ("a", "2", "b", "c")
+:25: .compound: "stmt" "2" "foo"
+:28: .mailbox.mailbox-pattern: "maildir:/var/mail;type=index;param=2;user=${user}"
+:29: .mailbox.mailbox-type: "maildir"
+:33: .logging.syslog: "yes"
+:34: .logging.facility: "mail"
+:39: .program="foo".logging.syslog: "yes"
+:40: .program="foo".logging.facility: "local1"
+:42: .program="foo".scalar: "no"
+:47: .program="bar".logging.syslog: "no"
+:48: .program="bar".logging.facility: "local2"
+:49: .program="bar".logging.tag: "baz"
+:51: .program="bar".scalar: "25"
+])
+
+AT_CLEANUP
diff --git a/tests/format02.at b/tests/format02.at
new file mode 100644
index 0000000..3ebada6
--- /dev/null
+++ b/tests/format02.at
@@ -0,0 +1,38 @@
+# This file is part of grecs -*- Autotest -*-
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs 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, or (at your option)
+# any later version.
+#
+# Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Format: custom delimiter])
+AT_KEYWORDS([format format02])
+
+AT_CHECK([gcffmt -delim=/ $abs_srcdir/gcf1.conf],
+[0],
+[/scalar: "yes"
+/listvar: ("a", "2", "b", "c")
+/compound: "stmt" "2" "foo"
+/mailbox/mailbox-pattern: "maildir:/var/mail;type=index;param=2;user=${user}"
+/mailbox/mailbox-type: "maildir"
+/logging/syslog: "yes"
+/logging/facility: "mail"
+/program="foo"/logging/syslog: "yes"
+/program="foo"/logging/facility: "local1"
+/program="foo"/scalar: "no"
+/program="bar"/logging/syslog: "no"
+/program="bar"/logging/facility: "local2"
+/program="bar"/logging/tag: "baz"
+/program="bar"/scalar: "25"
+])
+
+AT_CLEANUP
diff --git a/tests/gcf1.conf b/tests/gcf1.conf
new file mode 100644
index 0000000..991fb9b
--- /dev/null
+++ b/tests/gcf1.conf
@@ -0,0 +1,54 @@
+# This file is part of grecs - Gray's Extensible Configuration System
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs 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, or (at your option)
+# any later version.
+#
+# Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+/* Scalar variable.
+*/
+scalar yes;
+
+// List variable.
+listvar ("a", 2, "b", "c");
+
+# Compound value.
+compound stmt 2 foo;
+
+mailbox {
+ mailbox-pattern "maildir:/var/mail;type=index;param=2;user=${user}";
+ mailbox-type "maildir";
+};
+
+logging {
+ syslog yes;
+ facility mail;
+}
+
+program "foo" {
+ logging {
+ syslog yes;
+ facility local1;
+ }
+ scalar no;
+}
+
+program "bar" {
+ logging {
+ syslog no;
+ facility local2;
+ tag "baz";
+ }; # Note: semicolon after closing brace is optional.
+ scalar 25;
+}
+
+ \ No newline at end of file
diff --git a/tests/gcffmt.c b/tests/gcffmt.c
new file mode 100644
index 0000000..cc67b9a
--- /dev/null
+++ b/tests/gcffmt.c
@@ -0,0 +1,67 @@
+/* grecs - Gray's Extensible Configuration System
+ Copyright (C) 2007-2011 Sergey Poznyakoff
+
+ Grecs 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.
+
+ Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <string.h>
+#include <errno.h>
+#include "grecs.h"
+
+static void
+usage(const char *arg, FILE *fp, int code)
+{
+ fprintf(fp, "usage: %s [-h] [-locus] [-delim=char] file\n", arg);
+ exit(code);
+}
+
+int
+main(int argc, char **argv)
+{
+ char *progname = argv[0];
+ char *file = NULL;
+ struct grecs_node *tree, *node;
+ int flags = 0;
+
+ while (--argc) {
+ char *arg = *++argv;
+ if (strcmp(arg, "-locus") == 0)
+ flags |= GRECS_NODE_FLAG_LOCUS;
+ else if (strncmp(arg, "-delim=", 7) == 0)
+ flags |= arg[7];
+ else if (strcmp(arg, "-h") == 0)
+ usage(progname, stdout, 0);
+ else if (arg[0] == '-')
+ usage(progname, stderr, 1);
+ else if (file)
+ usage(progname, stderr, 1);
+ else
+ file = arg;
+ }
+
+ if (!file || argc)
+ usage(progname, stderr, 1);
+
+ tree = grecs_parse(file);
+ if (!tree)
+ exit(1);
+
+ for (node = tree; node; node = node->next) {
+ grecs_format_node(node, flags, stdout);
+ fputc('\n', stdout);
+ }
+ exit(0);
+}
diff --git a/tests/gcfpeek.c b/tests/gcfpeek.c
new file mode 100644
index 0000000..360000d
--- /dev/null
+++ b/tests/gcfpeek.c
@@ -0,0 +1,76 @@
+/* grecs - Gray's Extensible Configuration System
+ Copyright (C) 2007-2011 Sergey Poznyakoff
+
+ Grecs 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.
+
+ Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <string.h>
+#include <errno.h>
+#include "grecs.h"
+
+static void
+usage(const char *arg, FILE *fp, int code)
+{
+ fprintf(fp, "usage: %s [-h] [-locus] [-delim=char] file path\n", arg);
+ exit(code);
+}
+
+int
+main(int argc, char **argv)
+{
+ char *progname = argv[0];
+ char *path = NULL;
+ char *file = NULL;
+ struct grecs_node *tree, *node;
+ int flags = 0;
+ int rc = 2;
+
+ while (--argc) {
+ char *arg = *++argv;
+ if (strcmp(arg, "-locus") == 0)
+ flags |= GRECS_NODE_FLAG_LOCUS;
+ else if (strncmp(arg, "-delim=", 7) == 0)
+ flags |= arg[7];
+ else if (strcmp(arg, "-h") == 0)
+ usage(progname, stdout, 0);
+ else if (arg[0] == '-')
+ usage(progname, stderr, 1);
+ else if (file) {
+ if (path)
+ usage(progname, stderr, 1);
+ else
+ path = arg;
+ } else
+ file = arg;
+ }
+
+ if (!file || !path || argc)
+ usage(progname, stderr, 1);
+
+ tree = grecs_parse(file);
+ if (!tree)
+ exit(1);
+
+ for (node = tree; node; node = node->next) {
+ node = grecs_find_node(node, path);
+ if (!node)
+ break;
+ rc = 0;
+ grecs_format_node(node, flags, stdout);
+ fputc('\n', stdout);
+ }
+ exit(rc);
+}
diff --git a/tests/gcfset.c b/tests/gcfset.c
new file mode 100644
index 0000000..d2264e3
--- /dev/null
+++ b/tests/gcfset.c
@@ -0,0 +1,240 @@
+/* grecs - Gray's Extensible Configuration System
+ Copyright (C) 2007-2011 Sergey Poznyakoff
+
+ Grecs 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.
+
+ Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stddef.h>
+#include <string.h>
+#include <errno.h>
+#include "grecs.h"
+
+struct logging_setup {
+ int use_syslog;
+ int print_priority;
+ char *tag;
+ char *facility;
+};
+
+struct logging_setup logging_setup;
+char *scalar_string;
+char *mailbox_pattern;
+char *mailbox_type;
+struct grecs_list *listvar;
+
+struct program {
+ char *name;
+ struct logging_setup logging_setup;
+ char *scalar_string;
+ grecs_locus_t locus;
+ struct program *next;
+};
+
+struct grecs_list *proglist;
+
+static int
+cb_logging_facility(enum grecs_callback_command cmd,
+ grecs_locus_t *locus,
+ void *varptr,
+ grecs_value_t *value,
+ void *cb_data)
+{
+ if (cmd != grecs_callback_set_value) {
+ grecs_error(locus, 0, _("Unexpected block statement"));
+ return 1;
+ }
+ if (!value || value->type != GRECS_TYPE_STRING) {
+ grecs_error(locus, 0, _("expected string argument"));
+ return 1;
+ }
+
+ *(char**)varptr = grecs_strdup(value->v.string);
+ return 0;
+}
+
+static struct grecs_keyword logging_kwtab[] = {
+ { "syslog", NULL, "Send to syslog",
+ grecs_type_bool, NULL,
+ offsetof(struct logging_setup, use_syslog) },
+ { "facility", "name", "Set logging facility",
+ grecs_type_string, NULL,
+ offsetof(struct logging_setup, facility), cb_logging_facility },
+ { "tag", "label", "Tag logging messages with this string",
+ grecs_type_string, NULL,
+ offsetof(struct logging_setup, tag) },
+ { "print-priority", NULL, "Prefix each message with its priority",
+ grecs_type_bool, NULL,
+ offsetof(struct logging_setup, print_priority) },
+ { NULL },
+};
+
+static struct grecs_keyword mailbox_kwtab[] = {
+ { "mailbox-pattern", NULL, "Default mailbox pattern",
+ grecs_type_string, &mailbox_pattern },
+ { "mailbox-type", NULL, "Default mailbox type",
+ grecs_type_string, &mailbox_type },
+ { NULL },
+};
+
+
+static struct grecs_keyword program_kwtab[] = {
+ { "scalar", "label", "Scalar string",
+ grecs_type_string, NULL, offsetof(struct program,scalar_string) },
+ { "logging", NULL, N_("Configure logging logging"),
+ grecs_type_section, NULL, offsetof(struct program,logging_setup),
+ NULL, NULL, logging_kwtab },
+ { NULL }
+};
+
+static int
+cb_program(enum grecs_callback_command cmd,
+ grecs_locus_t *locus,
+ void *varptr,
+ grecs_value_t *value,
+ void *cb_data)
+{
+ struct program *prog;
+ void **pdata = cb_data;
+
+ switch (cmd) {
+ case grecs_callback_section_begin:
+ if (!value || value->type != GRECS_TYPE_STRING) {
+ grecs_error(locus, 0, _("tag must be a string"));
+ return 0;
+ }
+ prog = grecs_zalloc(sizeof(*prog));
+ prog->name = grecs_strdup(value->v.string);
+ prog->locus = *locus;
+ *pdata = prog;
+ break;
+
+ case grecs_callback_section_end:
+ prog = *pdata;
+ if (!proglist)
+ proglist = grecs_list_create();
+ grecs_list_append(proglist, prog);
+ break;
+
+ case grecs_callback_set_value:
+ grecs_error(locus, 0, _("invalid use of block statement"));
+ }
+ return 0;
+}
+
+static struct grecs_keyword main_kwtab[] = {
+ { "scalar", "label", "Scalar string",
+ grecs_type_string, &scalar_string },
+ { "logging", NULL, N_("Configure logging logging"),
+ grecs_type_section, &logging_setup, 0, NULL,
+ NULL, logging_kwtab },
+ { "mailbox", NULL, N_("Mailbox configuration"),
+ grecs_type_section, NULL, 0, NULL, NULL, mailbox_kwtab },
+ { "program", "name: string", "Subprogram configuration",
+ grecs_type_section, NULL, 0, cb_program, NULL, program_kwtab },
+ { "listvar", NULL, "list variable",
+ grecs_type_string|GRECS_LIST, &listvar },
+ { NULL }
+};
+
+
+#define S(s) ((s) ? (s) : "(null)")
+
+static void
+print_logging_setup(struct logging_setup *p)
+{
+ printf("logging: %d/%s/%s/%d\n",
+ p->use_syslog, S(p->facility), S(p->tag), p->print_priority);
+}
+
+static void
+print_program(struct program *prog)
+{
+ printf("Program %s:\n", prog->name);
+ printf("scalar = %s\n", S(prog->scalar_string));
+ print_logging_setup(&prog->logging_setup);
+}
+
+
+static void
+usage(const char *arg, FILE *fp, int code)
+{
+ fprintf(fp, "usage: %s [-h] [-cfhelp] file\n", arg);
+ exit(code);
+}
+
+int
+main(int argc, char **argv)
+{
+ char *progname = argv[0];
+ const char *file = NULL;
+ struct grecs_node *tree;
+ int cfhelp = 0;
+
+ while (--argc) {
+ char *arg = *++argv;
+ if (strcmp(arg, "-cfhelp") == 0)
+ cfhelp = 1;
+ else if (strcmp(arg, "-h") == 0)
+ usage(progname, stdout, 0);
+ else if (arg[0] == '-')
+ usage(progname, stderr, 1);
+ else if (file)
+ usage(progname, stderr, 1);
+ else
+ file = arg;
+ }
+
+ if ((!file && !cfhelp) || argc)
+ usage(progname, stderr, 1);
+
+ if (cfhelp) {
+ static char docstring[] =
+ "Sample configuration file structure.\n";
+ grecs_format_docstring(docstring, 0, stdout);
+ grecs_format_statement_array(main_kwtab, 1, 0, stdout);
+ exit(0);
+ }
+
+ tree = grecs_parse(file);
+ if (!tree)
+ exit(2);
+
+ if (grecs_tree_process(tree, main_kwtab))
+ exit(2);
+
+ printf("Global settings:\n");
+ printf("scalar = %s\n", S(scalar_string));
+ if (listvar) {
+ struct grecs_list_entry *ep;
+ printf("listvar =");
+ for (ep = listvar->head; ep; ep = ep->next)
+ printf(" \"%s\"", (char*)ep->data);
+ putchar('\n');
+ }
+
+ print_logging_setup(&logging_setup);
+
+ if (proglist) {
+ struct grecs_list_entry *ep;
+
+ printf("Programs configured: %d\n", grecs_list_size(proglist));
+ for (ep = proglist->head; ep; ep = ep->next)
+ print_program(ep->data);
+ }
+
+ exit(0);
+}
+
diff --git a/tests/peek00.at b/tests/peek00.at
new file mode 100644
index 0000000..a3d86ac
--- /dev/null
+++ b/tests/peek00.at
@@ -0,0 +1,25 @@
+# This file is part of grecs -*- Autotest -*-
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs 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, or (at your option)
+# any later version.
+#
+# Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP(Peek)
+AT_KEYWORDS([peek peek00])
+
+AT_CHECK([gcfpeek $abs_srcdir/gcf1.conf .scalar],
+[0],
+[.scalar: "yes"
+])
+
+AT_CLEANUP
diff --git a/tests/peek01.at b/tests/peek01.at
new file mode 100644
index 0000000..c76261c
--- /dev/null
+++ b/tests/peek01.at
@@ -0,0 +1,30 @@
+# This file is part of grecs -*- Autotest -*-
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs 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, or (at your option)
+# any later version.
+#
+# Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP(Peek: nested)
+AT_KEYWORDS([peek peek01])
+
+AT_CHECK([gcfpeek $abs_srcdir/gcf1.conf .program="foo".scalar],
+[0],
+[.program="foo".scalar: "no"
+])
+
+AT_CHECK([gcfpeek $abs_srcdir/gcf1.conf .program="bar".scalar],
+[0],
+[.program="bar".scalar: "25"
+])
+
+AT_CLEANUP
diff --git a/tests/peek02.at b/tests/peek02.at
new file mode 100644
index 0000000..e5c1a4a
--- /dev/null
+++ b/tests/peek02.at
@@ -0,0 +1,26 @@
+# This file is part of grecs -*- Autotest -*-
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs 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, or (at your option)
+# any later version.
+#
+# Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP(Peek: block)
+AT_KEYWORDS([peek peek02])
+
+AT_CHECK([gcfpeek $abs_srcdir/gcf1.conf .logging],
+[0],
+[.logging.syslog: "yes"
+.logging.facility: "mail"
+])
+
+AT_CLEANUP
diff --git a/tests/peek03.at b/tests/peek03.at
new file mode 100644
index 0000000..7590b0c
--- /dev/null
+++ b/tests/peek03.at
@@ -0,0 +1,33 @@
+# This file is part of grecs -*- Autotest -*-
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs 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, or (at your option)
+# any later version.
+#
+# Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP(Peek: block nested)
+AT_KEYWORDS([peek peek03])
+
+AT_CHECK([gcfpeek $abs_srcdir/gcf1.conf .program=foo.logging],
+[0],
+[.program="foo".logging.syslog: "yes"
+.program="foo".logging.facility: "local1"
+])
+
+AT_CHECK([gcfpeek $abs_srcdir/gcf1.conf .program=bar.logging],
+[0],
+[.program="bar".logging.syslog: "no"
+.program="bar".logging.facility: "local2"
+.program="bar".logging.tag: "baz"
+])
+
+AT_CLEANUP
diff --git a/tests/set.at b/tests/set.at
new file mode 100644
index 0000000..7bad831
--- /dev/null
+++ b/tests/set.at
@@ -0,0 +1,38 @@
+# This file is part of grecs -*- Autotest -*-
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs 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, or (at your option)
+# any later version.
+#
+# Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Set values])
+AT_KEYWORDS([set])
+
+AT_CHECK([gcfset $abs_srcdir/gcf1.conf 2>err||exit $?
+sed 's|^.*/gcf1.conf||' err >&2],
+[0],
+[Global settings:
+scalar = yes
+listvar = "a" "2" "b" "c"
+logging: 1/mail/(null)/0
+Programs configured: 2
+Program foo:
+scalar = no
+logging: 1/local1/(null)/0
+Program bar:
+scalar = 25
+logging: 0/local2/baz/0
+],
+[:25: Unknown keyword
+])
+
+AT_CLEANUP \ No newline at end of file
diff --git a/tests/testsuite.at b/tests/testsuite.at
new file mode 100644
index 0000000..3b0ec84
--- /dev/null
+++ b/tests/testsuite.at
@@ -0,0 +1,54 @@
+# This file is part of grecs - Gray's Extensible Configuration System -*- Autotest -*-
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs 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, or (at your option)
+# any later version.
+#
+# Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+m4_version_prereq([2.52g])
+
+dnl # Standard exit codes (from sysexits.h)
+m4_define([EX_OK], 0) dnl successful termination
+m4_define([EX__BASE], 64) dnl base value for error messages
+m4_define([EX_USAGE], 64) dnl command line usage error
+m4_define([EX_DATAERR], 65) dnl data format error
+m4_define([EX_NOINPUT], 66) dnl cannot open input
+m4_define([EX_NOUSER], 67) dnl addressee unknown
+m4_define([EX_NOHOST], 68) dnl host name unknown
+m4_define([EX_UNAVAILABLE], 69) dnl service unavailable
+m4_define([EX_SOFTWARE], 70) dnl internal software error
+m4_define([EX_OSERR], 71) dnl system error (e.g., can't fork)
+m4_define([EX_OSFILE], 72) dnl critical OS file missing
+m4_define([EX_CANTCREAT], 73) dnl can't create (user) output file
+m4_define([EX_IOERR], 74) dnl input/output error
+m4_define([EX_TEMPFAIL], 75) dnl temp failure; user is invited to retry
+m4_define([EX_PROTOCOL], 76) dnl remote error in protocol
+m4_define([EX_NOPERM], 77) dnl permission denied
+m4_define([EX_CONFIG], 78) dnl configuration error
+
+m4_define([AT_SKIP_TEST],[exit 77])
+
+dnl # Begin tests
+
+AT_INIT
+m4_include([format00.at])
+m4_include([format01.at])
+m4_include([format02.at])
+
+m4_include([peek00.at])
+m4_include([peek01.at])
+m4_include([peek02.at])
+m4_include([peek03.at])
+
+m4_include([cfhelp.at])
+m4_include([set.at])
+# End of testsuite.at

Return to:

Send suggestions and report system problems