aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-06-01 10:34:35 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-06-01 10:34:35 +0300
commitab6f93af727e412091e7f664c4f77d1723115529 (patch)
tree868d44dec26a889d6c552078d02930b4151b3c35
parent89033528634fc77d74983cf717e7ec93bfd6ac4c (diff)
downloaddirevent-ab6f93af727e412091e7f664c4f77d1723115529.tar.gz
direvent-ab6f93af727e412091e7f664c4f77d1723115529.tar.bz2
Test command line expansions.
* envdump.c: Accept unrecognized command line parameters. Use -f option to redirect output to a file. All uses updated. * cmdexp.at: New file. * Makefile.am: Add cmdexp.at * testsuite.at: Include cmdexp.at
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/attrib.at5
-rw-r--r--tests/cmdexp.at75
-rw-r--r--tests/create.at5
-rw-r--r--tests/delete.at5
-rw-r--r--tests/envdump.c31
-rw-r--r--tests/remove.at5
-rw-r--r--tests/testsuite.at2
-rw-r--r--tests/write.at5
9 files changed, 104 insertions, 30 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ae569f0..ff3dfc8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -40,6 +40,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
TESTSUITE_AT = \
attrib.at\
+ cmdexp.at\
create.at\
delete.at\
testsuite.at\
diff --git a/tests/attrib.at b/tests/attrib.at
index feab6e4..199d48e 100644
--- a/tests/attrib.at
+++ b/tests/attrib.at
@@ -32,7 +32,7 @@ syslog {
watcher {
path $cwd/dir;
event attrib;
- command "$TESTDIR/envdump -s -i DIRCOND_FILE=:DIRCOND_EVENT $outfile";
+ command "$TESTDIR/envdump -s -i DIRCOND_FILE=:DIRCOND_EVENT -f $outfile";
option (stdout,stderr);
}
EOT
@@ -56,7 +56,8 @@ argv[[0]]=(TESTDIR)/envdump
argv[[1]]=-s
argv[[2]]=-i
argv[[3]]=DIRCOND_FILE=:DIRCOND_EVENT
-argv[[4]]=(CWD)/dump
+argv[[4]]=-f
+argv[[5]]=(CWD)/dump
# Environment
DIRCOND_EVENT=attrib
DIRCOND_EVENT_CODE=4
diff --git a/tests/cmdexp.at b/tests/cmdexp.at
new file mode 100644
index 0000000..f968060
--- /dev/null
+++ b/tests/cmdexp.at
@@ -0,0 +1,75 @@
+# This file is part of Dircond testsuite. -*- Autotest -*-
+# Copyright (C) 2013 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([Command line expansions])
+AT_KEYWORDS([cmdexp])
+
+AT_CHECK([
+cwd=`pwd`
+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:write;
+}
+watcher {
+ path $cwd/dir;
+ event write;
+ command "$TESTDIR/envdump -s -i DIRCOND_FILE=:DIRCOND_EVENT -f $outfile file=\$file event=\$sie_event_id";
+ option (stdout,stderr);
+}
+EOT
+
+cat > dir/testfile <<EOT
+now is the
+time for all
+men
+EOT
+
+dircond -lnotice test.conf || exit 1
+waitfile $pidfile 2
+echo "to come to" >> dir/testfile
+
+waitfile $outfile 6
+res=$?
+kill `cat $pidfile`
+test $? -ne 0 && exit 1
+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_EVENT
+argv[[4]]=-f
+argv[[5]]=(CWD)/dump
+argv[[6]]=file=testfile
+argv[[7]]=event=write
+# Environment
+DIRCOND_EVENT=write
+DIRCOND_EVENT_CODE=2
+DIRCOND_FILE=testfile
+# End
+])
+
+AT_CLEANUP
diff --git a/tests/create.at b/tests/create.at
index ace1af1..54bc914 100644
--- a/tests/create.at
+++ b/tests/create.at
@@ -32,7 +32,7 @@ syslog {
watcher {
path $cwd/dir;
event create;
- command "$TESTDIR/envdump -s -i DIRCOND_FILE=:DIRCOND_EVENT $outfile";
+ command "$TESTDIR/envdump -s -i DIRCOND_FILE=:DIRCOND_EVENT -f $outfile";
option (stdout,stderr);
}
EOT
@@ -52,7 +52,8 @@ argv[[0]]=(TESTDIR)/envdump
argv[[1]]=-s
argv[[2]]=-i
argv[[3]]=DIRCOND_FILE=:DIRCOND_EVENT
-argv[[4]]=(CWD)/dump
+argv[[4]]=-f
+argv[[5]]=(CWD)/dump
# Environment
DIRCOND_EVENT=create
DIRCOND_EVENT_CODE=1
diff --git a/tests/delete.at b/tests/delete.at
index 971708d..4ba59ff 100644
--- a/tests/delete.at
+++ b/tests/delete.at
@@ -32,7 +32,7 @@ syslog {
watcher {
path $cwd/dir;
event delete;
- command "$TESTDIR/envdump -s -i DIRCOND_FILE=:DIRCOND_EVENT $outfile";
+ command "$TESTDIR/envdump -s -i DIRCOND_FILE=:DIRCOND_EVENT -f $outfile";
option (stdout,stderr);
}
EOT
@@ -53,7 +53,8 @@ argv[[0]]=(TESTDIR)/envdump
argv[[1]]=-s
argv[[2]]=-i
argv[[3]]=DIRCOND_FILE=:DIRCOND_EVENT
-argv[[4]]=(CWD)/dump
+argv[[4]]=-f
+argv[[5]]=(CWD)/dump
# Environment
DIRCOND_EVENT=delete
DIRCOND_EVENT_CODE=8
diff --git a/tests/envdump.c b/tests/envdump.c
index 7eec186..c803cdb 100644
--- a/tests/envdump.c
+++ b/tests/envdump.c
@@ -174,7 +174,7 @@ main(int argc, char **argv)
{
int i;
char *p;
- FILE *fp;
+ FILE *fp = NULL;
char *mode = "w";
int sortenv = 0;
char *include = NULL;
@@ -187,13 +187,21 @@ main(int argc, char **argv)
progname++;
else
progname = argv[0];
- while ((i = getopt(argc, argv, "ahi:k:s")) != EOF)
+ while ((i = getopt(argc, argv, "af:hi:k:s")) != EOF)
switch (i) {
case 'a':
mode = "a";
break;
+ case 'f':
+ fp = fopen(optarg, mode);
+ if (!fp) {
+ fprintf(stderr, "%s: ", progname);
+ perror(optarg);
+ return 1;
+ }
+ break;
case 'h':
- printf("usage: %s [-ahs] [-i INCLUDELIST] [-k [@]PID[:SIG]] [FILE]\n",
+ printf("usage: %s [-ahsx] [-f FILE] [-i INCLUDELIST] [-k [@]PID[:SIG]] [ARGS...]\n",
progname);
return 0;
case 's':
@@ -205,27 +213,12 @@ main(int argc, char **argv)
case 'k':
read_pid_and_sig(optarg, &pid, &sig);
break;
-
default:
return 1;
}
- switch (argc - optind) {
- case 0:
+ if (!fp)
fp = stderr;
- break;
- case 1:
- fp = fopen(argv[optind], mode);
- if (!fp) {
- fprintf(stderr, "%s: ", progname);
- perror(argv[optind]);
- return 1;
- }
- break;
- default:
- fprintf(stderr, "%s: too many arguments", progname);
- return 1;
- }
fprintf(fp, "# Dump of execution environment\n");
p = agetcwd();
diff --git a/tests/remove.at b/tests/remove.at
index aaf6cb0..3495a7c 100644
--- a/tests/remove.at
+++ b/tests/remove.at
@@ -32,7 +32,7 @@ syslog {
watcher {
path $cwd/dir;
event create;
- command "$TESTDIR/envdump -s -i DIRCOND_FILE=:DIRCOND_SYS_ $outfile";
+ command "$TESTDIR/envdump -s -i DIRCOND_FILE=:DIRCOND_SYS_ -f $outfile";
option (stdout,stderr);
}
EOT
@@ -52,7 +52,8 @@ argv[[0]]=(TESTDIR)/envdump
argv[[1]]=-s
argv[[2]]=-i
argv[[3]]=DIRCOND_FILE=:DIRCOND_SYS_
-argv[[4]]=(CWD)/dump
+argv[[4]]=-f
+argv[[5]]=(CWD)/dump
# Environment
DIRCOND_FILE=file
DIRCOND_SYS_EVENT=CREATE
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 19d1e5f..31b090f 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -25,5 +25,5 @@ m4_include([create.at])
m4_include([delete.at])
m4_include([write.at])
m4_include([attrib.at])
-
+m4_include([cmdexp.at])
diff --git a/tests/write.at b/tests/write.at
index bce98da..9fb469d 100644
--- a/tests/write.at
+++ b/tests/write.at
@@ -32,7 +32,7 @@ syslog {
watcher {
path $cwd/dir;
event write;
- command "$TESTDIR/envdump -s -i DIRCOND_FILE=:DIRCOND_EVENT $outfile";
+ command "$TESTDIR/envdump -s -i DIRCOND_FILE=:DIRCOND_EVENT -f $outfile";
option (stdout,stderr);
}
EOT
@@ -61,7 +61,8 @@ argv[[0]]=(TESTDIR)/envdump
argv[[1]]=-s
argv[[2]]=-i
argv[[3]]=DIRCOND_FILE=:DIRCOND_EVENT
-argv[[4]]=(CWD)/dump
+argv[[4]]=-f
+argv[[5]]=(CWD)/dump
# Environment
DIRCOND_EVENT=write
DIRCOND_EVENT_CODE=2

Return to:

Send suggestions and report system problems to the System administrator.