aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2014-07-29 09:03:50 +0300
committerSergey Poznyakoff <gray@gnu.org>2014-07-29 09:03:50 +0300
commit8397a2858f103397d4ae82156b43f7048e788c3b (patch)
tree834a72cf1ab40701175349000bb5fbbaf06daa59 /tests
parent2e9dee9f4ac310b688281dd840e5c132f26e108f (diff)
downloaddirevent-8397a2858f103397d4ae82156b43f7048e788c3b.tar.gz
direvent-8397a2858f103397d4ae82156b43f7048e788c3b.tar.bz2
Introduce pattern negation.
* doc/dircond.conf.5: Document negated patterns. * doc/dircond.texi: Likewise. * src/config.c (file_name_pattern): A ! in front of a pattern indicates negation. * src/dircond.h (filename_pattern)<neg>: New member. * src/fnpat.c: Honor neg member. * tests/envdump.c (main): don't depend on the order of command line options. * tests/glob02.at: New test case. * tests/re05.at: Likewise. * tests/Makefile.am: Add new files. * tests/testsuite.at: Include new testcases.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/envdump.c17
-rw-r--r--tests/glob02.at67
-rw-r--r--tests/re05.at67
-rw-r--r--tests/testsuite.at4
5 files changed, 150 insertions, 9 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4d209de..6f7f1df 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,5 @@
# This file is part of Dircond
-# Copyright (C) 2012, 2013 Sergey Poznyakoff
+# Copyright (C) 2012-2014 Sergey Poznyakoff
#
# Dircond is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -49,10 +49,12 @@ TESTSUITE_AT = \
env02.at\
env03.at\
glob01.at\
+ glob02.at\
re01.at\
re02.at\
re03.at\
re04.at\
+ re05.at\
testsuite.at\
write.at
diff --git a/tests/envdump.c b/tests/envdump.c
index c803cdb..8a0a0b2 100644
--- a/tests/envdump.c
+++ b/tests/envdump.c
@@ -175,6 +175,7 @@ main(int argc, char **argv)
int i;
char *p;
FILE *fp = NULL;
+ char *file;
char *mode = "w";
int sortenv = 0;
char *include = NULL;
@@ -193,12 +194,7 @@ main(int argc, char **argv)
mode = "a";
break;
case 'f':
- fp = fopen(optarg, mode);
- if (!fp) {
- fprintf(stderr, "%s: ", progname);
- perror(optarg);
- return 1;
- }
+ file = optarg;
break;
case 'h':
printf("usage: %s [-ahsx] [-f FILE] [-i INCLUDELIST] [-k [@]PID[:SIG]] [ARGS...]\n",
@@ -217,7 +213,14 @@ main(int argc, char **argv)
return 1;
}
- if (!fp)
+ if (file) {
+ fp = fopen(file, mode);
+ if (!fp) {
+ fprintf(stderr, "%s: ", progname);
+ perror(file);
+ return 1;
+ }
+ } else
fp = stderr;
fprintf(fp, "# Dump of execution environment\n");
diff --git a/tests/glob02.at b/tests/glob02.at
new file mode 100644
index 0000000..3c43145
--- /dev/null
+++ b/tests/glob02.at
@@ -0,0 +1,67 @@
+# This file is part of Dircond testsuite. -*- Autotest -*-
+# Copyright (C) 2013, 2014 Sergey Poznyakoff
+#
+# Dircond 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.
+#
+# Dircond 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 Dircond. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Globbing pattern negation])
+AT_KEYWORDS([create fname glob glob02 neg])
+
+AT_CHECK([
+cwd=`pwd -P`
+pidfile=$cwd/dircond.pid
+outfile=$cwd/dump
+mkdir dir
+cat > test.conf <<EOT
+pidfile $pidfile;
+debug 10;
+syslog {
+ facility ${TESTSUITE_FACILITY:-local0};
+ tag dircond-test:create;
+}
+watcher {
+ path $cwd/dir;
+ event create;
+ file "!*.tmp";
+ command "$TESTDIR/envdump -s -i DIRCOND_FILE=:DIRCOND_GENEV_ -f $outfile -a";
+ option (stdout,stderr);
+}
+EOT
+
+dircond -lnotice test.conf || exit 1
+waitfile $pidfile 2
+> dir/tempfile
+> dir/file.tmp
+waitfile $outfile 6
+kill `cat $pidfile`
+sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^" $outfile
+],
+[0],
+[# Dump of execution environment
+cwd is (CWD)/dir
+# Arguments
+argv[[0]]=(TESTDIR)/envdump
+argv[[1]]=-s
+argv[[2]]=-i
+argv[[3]]=DIRCOND_FILE=:DIRCOND_GENEV_
+argv[[4]]=-f
+argv[[5]]=(CWD)/dump
+argv[[6]]=-a
+# Environment
+DIRCOND_FILE=tempfile
+DIRCOND_GENEV_CODE=1
+DIRCOND_GENEV_NAME=create
+# End
+])
+
+AT_CLEANUP
diff --git a/tests/re05.at b/tests/re05.at
new file mode 100644
index 0000000..9127960
--- /dev/null
+++ b/tests/re05.at
@@ -0,0 +1,67 @@
+# This file is part of Dircond testsuite. -*- Autotest -*-
+# Copyright (C) 2014 Sergey Poznyakoff
+#
+# Dircond 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.
+#
+# Dircond 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 Dircond. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Regexp negation])
+AT_KEYWORDS([create fname regexp re re05 neg])
+
+AT_CHECK([
+cwd=`pwd -P`
+pidfile=$cwd/dircond.pid
+outfile=$cwd/dump
+mkdir dir
+cat > test.conf <<EOT
+pidfile $pidfile;
+debug 10;
+syslog {
+ facility ${TESTSUITE_FACILITY:-local0};
+ tag dircond-test:create;
+}
+watcher {
+ path $cwd/dir;
+ event create;
+ file "!/\.[[0-9]]+$/";
+ command "$TESTDIR/envdump -s -i DIRCOND_FILE=:DIRCOND_GENEV_ -f $outfile -a";
+ option (stdout,stderr);
+}
+EOT
+
+dircond -lnotice test.conf || exit 1
+waitfile $pidfile 2
+> dir/file
+> dir/file.1234
+waitfile $outfile 6
+kill `cat $pidfile`
+sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^" $outfile
+],
+[0],
+[# Dump of execution environment
+cwd is (CWD)/dir
+# Arguments
+argv[[0]]=(TESTDIR)/envdump
+argv[[1]]=-s
+argv[[2]]=-i
+argv[[3]]=DIRCOND_FILE=:DIRCOND_GENEV_
+argv[[4]]=-f
+argv[[5]]=(CWD)/dump
+argv[[6]]=-a
+# Environment
+DIRCOND_FILE=file
+DIRCOND_GENEV_CODE=1
+DIRCOND_GENEV_NAME=create
+# End
+])
+
+AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
index dbbd147..730a558 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -1,5 +1,5 @@
# This file is part of Dircond testsuite. -*- Autotest -*-
-# Copyright (C) 2013 Sergey Poznyakoff
+# Copyright (C) 2013, 2014 Sergey Poznyakoff
#
# Dircond is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -36,8 +36,10 @@ m4_include([env03.at])
AT_BANNER([Filename selection])
m4_include([glob01.at])
+m4_include([glob02.at])
m4_include([re01.at])
m4_include([re02.at])
m4_include([re03.at])
m4_include([re04.at])
+m4_include([re05.at])

Return to:

Send suggestions and report system problems to the System administrator.