aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-10-19 19:07:43 +0200
committerMattias Andrée <maandree@kth.se>2017-10-19 19:07:43 +0200
commitf7fedd90fb3f7d3110f2ff976639c7f8ec51fbad (patch)
treeb1099b364a4d3a1f90f8178b7a192c931a63bc29
parentSimplify (diff)
downloadxtest-f7fedd90fb3f7d3110f2ff976639c7f8ec51fbad.tar.gz
xtest-f7fedd90fb3f7d3110f2ff976639c7f8ec51fbad.tar.bz2
xtest-f7fedd90fb3f7d3110f2ff976639c7f8ec51fbad.tar.xz
Add test
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--.gitignore2
-rw-r--r--Makefile7
-rw-r--r--mksocket.c37
-rwxr-xr-xtest81
4 files changed, 125 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index d98bca5..154d5f5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,5 @@
*.su
*.out
/xtest
+/mksocket
+/.testdir
diff --git a/Makefile b/Makefile
index 62a0f76..9cc8113 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
CONFIGFILE = config.mk
include $(CONFIGFILE)
-all: xtest
+all: xtest mksocket
.o:
$(CC) -o $@ $^ $(LDFLAGS)
@@ -13,6 +13,9 @@ all: xtest
xtest.o: arg.h
+check: xtest mksocket
+ ./test
+
install: xtest
mkdir -p -- "$(DESTDIR)$(PREFIX)/bin"
mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man1"
@@ -27,7 +30,7 @@ uninstall:
-rm -rf -- "$(DESTDIR)$(PREFIX)/share/licenses/xtest"
clean:
- -rm -f -- xtest *.o
+ -rm -rf -- xtest mksocket *.o .testdir
.SUFFIXES: .o .c.o
diff --git a/mksocket.c b/mksocket.c
new file mode 100644
index 0000000..0cf6e8d
--- /dev/null
+++ b/mksocket.c
@@ -0,0 +1,37 @@
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int
+main(int argc, char *argv[])
+{
+ struct sockaddr_un addr;
+ int fd;
+
+ if (argc != 2)
+ abort();
+ fd = socket(PF_UNIX, SOCK_STREAM, 0);
+ if (fd < 0) {
+ perror("mksocket");
+ return 1;
+ }
+ memset(&addr, 0, sizeof(addr));
+ addr.sun_family = AF_UNIX;
+ if (strlen(argv[1]) >= sizeof(addr.sun_path)) {
+ errno = ENAMETOOLONG;
+ perror("mksocket");
+ return 1;
+ }
+ strcpy(addr.sun_path, argv[1]);
+ if (bind(fd, (void *)&addr, (socklen_t)sizeof(addr))) {
+ perror("mksocket");
+ return 1;
+ }
+ close(fd);
+
+ return 0;
+}
diff --git a/test b/test
new file mode 100755
index 0000000..14d9ede
--- /dev/null
+++ b/test
@@ -0,0 +1,81 @@
+#!/bin/sh
+
+rm -rf .testdir
+
+set -v
+set -e
+
+! ./xtest 2>/dev/null
+! ./xtest . 2>/dev/null
+
+simple_test() {
+ test $(printf '%s\n' "$2"/* | ./xtest -$1 | wc -l) -gt 0
+ printf '%s\n' "$2"/* | ./xtest -$1 | while read f; do
+ test -$1 "$f"
+ done
+
+ test $(printf '%s\n' "$2"/* | ./xtest +$1 | wc -l) -gt 0
+ printf '%s\n' "$2"/* | ./xtest +$1 | while read f; do
+ ! test -$1 "$f"
+ done
+
+ test $(./xtest -$1 "$2"/* | wc -l) -gt 0
+ ./xtest -$1 "$2"/* | while read f; do
+ if ! test "$f" = /dev/stdin; then
+ test -$1 "$f"
+ fi
+ done
+
+ test $(./xtest +$1 "$2"/* | wc -l) -gt 0
+ ./xtest +$1 "$2"/* | while read f; do
+ if ! test "$f" = /dev/stdout; then
+ ! test -$1 "$f"
+ fi
+ done
+}
+
+simple_test b /dev
+simple_test c /dev
+simple_test d /dev
+simple_test f /dev
+
+mkdir -p .testdir
+touch .testdir/r .testdir/w .testdir/x .testdir/k .testdir/u .testdir/g
+printf x > .testdir/s
+chmod 100 .testdir/x
+chmod 200 .testdir/w
+chmod 400 .testdir/r
+chmod 1000 .testdir/k
+chmod 2000 .testdir/g
+chmod 4000 .testdir/u
+ln -s 'non existent file' .testdir/h
+mkfifo .testdir/p
+./mksocket .testdir/S
+simple_test e .testdir
+simple_test r .testdir
+simple_test w .testdir
+simple_test x .testdir
+simple_test s .testdir
+simple_test h .testdir
+simple_test L .testdir
+simple_test p .testdir
+simple_test k .testdir
+simple_test u .testdir
+simple_test g .testdir
+simple_test S .testdir
+
+find .testdir -print0 | ./xtest -0x > .testdir/nul
+find .testdir | ./xtest -x > .testdir/lf
+find .testdir -print0 | ./xtest -0x | tr '\0' '\n' > .testdir/tr
+! diff .testdir/nul .testdir/lf >/dev/null
+diff .testdir/tr .testdir/lf >/dev/null
+
+for f in 0 1 2 3 4 5 6 x y z; do
+ if test $(xtest -t $f | wc -l) = 0; then
+ ! test -t $f
+ else
+ test -t $f
+ fi
+done
+
+rm -rf .testdir