aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2008-12-30 12:34:20 +0000
committerMike Frysinger <vapier@gentoo.org>2008-12-30 12:34:20 +0000
commit7a50f6b8867561b85c24a56c3ba73aa7d8abbf61 (patch)
treeb33c96e9332fe1f757e8d9072fda691a593d89b8 /tests
parenttweak style slightly to make source tests happy (diff)
downloadpax-utils-7a50f6b8867561b85c24a56c3ba73aa7d8abbf61.tar.gz
pax-utils-7a50f6b8867561b85c24a56c3ba73aa7d8abbf61.tar.bz2
pax-utils-7a50f6b8867561b85c24a56c3ba73aa7d8abbf61.zip
add test framework
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile12
-rw-r--r--tests/source/Makefile8
-rwxr-xr-xtests/source/dotest118
-rwxr-xr-xtests/source/space.py31
4 files changed, 169 insertions, 0 deletions
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..8d78cfb
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,12 @@
+SUBDIRS = source
+
+.PHONY: all test check clean
+all test check clean:
+ $(MAKE) $(patsubst %,subdir_%_$@,$(SUBDIRS))
+
+# subdir_source_all
+_SUBTAR = $(patsubst subdir_%,%,$@)
+_SUBDIR = $(shell expr $(_SUBTAR) : '\(.*\)_[^_]*$$')
+_TARGET = $(shell expr $(_SUBTAR) : '.*_\([^_]*\)$$')
+subdir_%:
+ $(MAKE) -C $(_SUBDIR) $(_TARGET)
diff --git a/tests/source/Makefile b/tests/source/Makefile
new file mode 100644
index 0000000..62084f0
--- /dev/null
+++ b/tests/source/Makefile
@@ -0,0 +1,8 @@
+all: check
+
+test check:
+ ./dotest
+
+clean:
+
+.PHONY: all check clean test
diff --git a/tests/source/dotest b/tests/source/dotest
new file mode 100755
index 0000000..70df9f9
--- /dev/null
+++ b/tests/source/dotest
@@ -0,0 +1,118 @@
+#!/bin/bash
+
+[ -e /etc/init.d/functions.sh ] && source /etc/init.d/functions.sh
+
+ret=0
+
+testit() {
+ if [ -s $1 ] ; then
+ echo ${BAD}FAIL${NORMAL}: $1
+ cat $1
+ rm -f $1
+ ret=1
+ return
+ fi
+ rm -f $1
+ echo ${GOOD}PASS${NORMAL}: $1
+}
+
+
+#
+# check for misc common typos
+#
+find ../.. \
+ '(' -type d -a '(' -name CVS -o -name tests ')' -prune ')' \
+ -o '(' -type f -a -print0 ')' | xargs -0 \
+ grep -n -I \
+ -e '\<compatability\>' \
+ -e '\<compatable\>' \
+ -e '\<fordeground\>' \
+ -e '\<depency\>' \
+ -e '\<defalt\>' \
+ -e '\<remaing\>' \
+ -e '\<queuing\>' \
+ -e '\<detatch\>' \
+ -e '\<sempahore\>' \
+ -e '\<reprenstative\>' \
+ -e '\<overriden\>' \
+ -e '\<readed\>' \
+ -e '\<formated\>' \
+ -e '\<algorithic\>' \
+ -e '\<deamon\>' \
+ -e '\<derefernce\>' \
+ | sed -e "s:^\.\./\.\./::g" > src.typos
+testit src.typos
+
+
+
+#
+# don't allow obsolete functions
+#
+find ../.. '(' -name '*.c' -o -name '*.h' ')' -print0 | xargs -0 \
+ grep -n -E -e '\<(bcmp|bcopy|bzero|getwd|index|mktemp|rindex|utimes)\>[[:space:]]*\(' \
+ | sed -e "s:^\.\./\.\./::g" > src.obsolete.funcs
+testit src.obsolete.funcs
+
+
+
+#
+# make sure people use our constants
+#
+find ../.. '(' -name '*.c' -o -name '*.h' ')' -print0 | xargs -0 \
+ grep -n -E -e '\<PATH_MAX\>' | grep -v __PAX_UTILS_PATH_MAX \
+ | sed -e "s:^\.\./\.\./::g" > src.bad.constants
+testit src.bad.constants
+
+
+
+#
+# don't allow obsolete headers
+#
+find ../.. '(' -name '*.c' -o -name '*.h' ')' -print0 | xargs -0 \
+ grep -n -E -e '\<(malloc|memory|sys/(errno|fcntl|signal|stropts|termios|unistd))\.h\>' \
+ | sed -e "s:^\.\./\.\./::g" > src.obsolete.headers
+testit src.obsolete.headers
+
+
+
+#
+# make sure people use the x* helper funcs
+#
+xfuncs=$(printf '%s|' $(sed -n 's:.*x\([^(]*\)(.*:\1:p' ../../xfuncs.h))
+xfuncs=${xfuncs:0:${#xfuncs}-1}
+find ../.. '(' -name '*.c' -o -name '*.h' ')' -print0 | xargs -0 \
+ grep -n -E -e "\<(${xfuncs})[[:space:]]*\(" \
+ | grep -v xfuncs.c \
+ | sed -e "s:^\.\./\.\./::g" > src.use.xfuncs
+testit src.use.xfuncs
+
+
+#
+# check for style
+#
+find ../.. '(' -name '*.c' -o -name '*.h' ')' -print0 | xargs -0 \
+ grep -n -E \
+ -e '\<(for|if|switch|while)\(' \
+ -e '\<(for|if|switch|while) \( ' \
+ -e ' ;' \
+ -e '[[:space:]]$' \
+ -e '\){' \
+ -e '(^|[^:])//' \
+ | sed -e "s:^\.\./\.\./::g" > src.style
+testit src.style
+
+
+# Stupid BSD makes us check for this..
+if [ $(type -P md5sum) != "" ]; then
+ for x in $(find ../.. '(' -name '*.c' -o -name '*.h' ')' ); do
+ python space.py $x > $x~
+ if [[ $(md5sum $x | awk '{print $1}') != $(md5sum $x~ | awk '{print $1}') ]]; then
+ diff -u $x $x~
+ #cp $x~ $x
+ fi
+ rm $x~
+ done > src.space
+ testit src.space
+fi
+
+exit ${ret}
diff --git a/tests/source/space.py b/tests/source/space.py
new file mode 100755
index 0000000..f1baff9
--- /dev/null
+++ b/tests/source/space.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+
+# Very simple src checker.
+# Trim trailing whitespace and consecutive newlines.
+# -solar 2007
+
+import os
+import sys
+
+def crapspace(fname):
+ chars = True
+ fp = open(fname, "r")
+ line = fp.readline()
+ while line:
+ line = line.rstrip()
+ if line:
+ chars = True
+ print line
+ else:
+ if chars:
+ print ""
+ chars = False
+
+ line = fp.readline()
+
+if __name__ == "__main__":
+ if len(sys.argv) < 2:
+ sys.stderr.write( "Usage: rstrip <file>\n")
+ sys.exit(1)
+
+ crapspace(sys.argv[1])