mirror of
git://projects.qi-hardware.com/wernermisc.git
synced 2024-11-15 06:17:31 +02:00
qpkg: added regression test harness and a few tests
- Makefile (test, tests, valgrind): new targets to run regression tests - test/Common: test harness (adapted from fped) - test/minpkg: test minimum package definition - test/prereq: test basic prerequisite queries
This commit is contained in:
parent
83c716424f
commit
2c953a5d1a
@ -38,7 +38,7 @@ endif
|
|||||||
|
|
||||||
# ----- Rules -----------------------------------------------------------------
|
# ----- Rules -----------------------------------------------------------------
|
||||||
|
|
||||||
.PHONY: all jlime openwrt clean spotless
|
.PHONY: all jlime openwrt test tests valgrind clean spotless
|
||||||
|
|
||||||
all: qpkg rbtest
|
all: qpkg rbtest
|
||||||
|
|
||||||
@ -62,6 +62,18 @@ qpkg: $(OBJS_qpkg)
|
|||||||
|
|
||||||
rbtest: $(OBJS_rbtest)
|
rbtest: $(OBJS_rbtest)
|
||||||
|
|
||||||
|
# ----- Tests -----------------------------------------------------------------
|
||||||
|
|
||||||
|
test tests: all
|
||||||
|
LANG= sh -c \
|
||||||
|
'passed=0 && cd test && \
|
||||||
|
for n in [a-z]*; do \
|
||||||
|
[ $$n != core ] && SCRIPT=$$n CWD_PREFIX=.. . ./$$n; done; \
|
||||||
|
echo "Passed all $$passed tests"'
|
||||||
|
|
||||||
|
valgrind:
|
||||||
|
VALGRIND="valgrind -q" $(MAKE) tests
|
||||||
|
|
||||||
# ----- Cleanup ---------------------------------------------------------------
|
# ----- Cleanup ---------------------------------------------------------------
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
79
qpkg/test/Common
Executable file
79
qpkg/test/Common
Executable file
@ -0,0 +1,79 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Common - Elements shared by all regression tests for qpkg
|
||||||
|
#
|
||||||
|
# Written 2010 by Werner Almesberger
|
||||||
|
# Copyright 2010 Werner Almesberger
|
||||||
|
#
|
||||||
|
# This program 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 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
qpkg()
|
||||||
|
{
|
||||||
|
echo -n "$1: " 1>&2
|
||||||
|
shift
|
||||||
|
cat >_in
|
||||||
|
$VALGRIND ${QPKG:-../qpkg} _in "$@" >_out 2>&1 || {
|
||||||
|
echo FAILED "($SCRIPT)" 1>&2
|
||||||
|
cat _out
|
||||||
|
rm -f _in _out
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
rm -f _in
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
qpkg_fail()
|
||||||
|
{
|
||||||
|
echo -n "$1: " 1>&2
|
||||||
|
shift
|
||||||
|
cat >_in
|
||||||
|
$VALGRIND ${QPKG:-../qpkg} _in "$@" >_out 2>&1 && {
|
||||||
|
echo FAILED "($SCRIPT)" 1>&2
|
||||||
|
cat _out
|
||||||
|
rm -f _in _out
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
rm -f _in
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
expect()
|
||||||
|
{
|
||||||
|
diff -u - "$@" _out >_diff || {
|
||||||
|
echo FAILED "($SCRIPT)" 1>&2
|
||||||
|
cat _diff 1>&2
|
||||||
|
rm -f _out _diff
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
echo PASSED 1>&2
|
||||||
|
rm -f _out _diff
|
||||||
|
passed=`expr ${passed:-0} + 1`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
expect_grep()
|
||||||
|
{
|
||||||
|
grep "$1" <_out >_tmp || exit 1
|
||||||
|
mv _tmp _out
|
||||||
|
shift
|
||||||
|
expect "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
expect_sed()
|
||||||
|
{
|
||||||
|
sed "$1" <_out >_tmp || exit 1
|
||||||
|
mv _tmp _out
|
||||||
|
shift
|
||||||
|
expect "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if [ ! -z "$CWD_PREFIX" -a ! -z "$QPKG" -a "$QPKG" = "${QPKG#/}" ]; then
|
||||||
|
QPKG="$CWD_PREFIX/$QPKG"
|
||||||
|
fi
|
43
qpkg/test/minpkg
Executable file
43
qpkg/test/minpkg
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
. ./Common
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
qpkg_fail "no Version field" <<EOF
|
||||||
|
Package: test
|
||||||
|
EOF
|
||||||
|
expect <<EOF
|
||||||
|
package test has no version
|
||||||
|
EOF
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
qpkg_fail "no Architecture field" <<EOF
|
||||||
|
Package: test
|
||||||
|
Version: 1
|
||||||
|
EOF
|
||||||
|
expect <<EOF
|
||||||
|
package test version 1 has no architecture
|
||||||
|
EOF
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
qpkg_fail "no Filename field" <<EOF
|
||||||
|
Package: whatever
|
||||||
|
Version: 1
|
||||||
|
Architecture: test
|
||||||
|
EOF
|
||||||
|
expect <<EOF
|
||||||
|
package whatever version 1 has no file name (nor is it installed)
|
||||||
|
EOF
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
qpkg "minimum package definition" <<EOF
|
||||||
|
Package: whatever
|
||||||
|
Version: 1
|
||||||
|
Architecture: test
|
||||||
|
Filename: whatever_1_test.ipkg
|
||||||
|
EOF
|
||||||
|
expect <<EOF
|
||||||
|
EOF
|
77
qpkg/test/prereq
Executable file
77
qpkg/test/prereq
Executable file
@ -0,0 +1,77 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
. ./Common
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
qpkg "new prereq for new package" prereq foo <<EOF
|
||||||
|
Package: bar
|
||||||
|
Version: 1
|
||||||
|
Architecture: test
|
||||||
|
Filename: bar_1_test.ipkg
|
||||||
|
|
||||||
|
Package: foo
|
||||||
|
Version: 0
|
||||||
|
Architecture: test
|
||||||
|
Depends: bar
|
||||||
|
Filename: foo_0_test.ipkg
|
||||||
|
EOF
|
||||||
|
expect <<EOF
|
||||||
|
bar_1_test.ipkg
|
||||||
|
EOF
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
qpkg "installed prereq for new package (install record first)" prereq foo <<EOF
|
||||||
|
Package: bar
|
||||||
|
Version: 1
|
||||||
|
Architecture: test
|
||||||
|
Filename: bar_1_test.ipkg
|
||||||
|
|
||||||
|
Package: bar
|
||||||
|
Version: 1
|
||||||
|
Architecture: test
|
||||||
|
Status: installed
|
||||||
|
|
||||||
|
Package: foo
|
||||||
|
Version: 0
|
||||||
|
Architecture: test
|
||||||
|
Depends: bar
|
||||||
|
Filename: foo_0_test.ipkg
|
||||||
|
EOF
|
||||||
|
expect <<EOF
|
||||||
|
EOF
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
qpkg "installed prereq for new package (package record first)" prereq foo <<EOF
|
||||||
|
Package: foo
|
||||||
|
Version: 0
|
||||||
|
Architecture: test
|
||||||
|
Depends: bar
|
||||||
|
Filename: foo_0_test.ipkg
|
||||||
|
|
||||||
|
Package: bar
|
||||||
|
Version: 1
|
||||||
|
Architecture: test
|
||||||
|
Status: installed
|
||||||
|
|
||||||
|
Package: bar
|
||||||
|
Version: 1
|
||||||
|
Architecture: test
|
||||||
|
Filename: bar_1_test.ipkg
|
||||||
|
EOF
|
||||||
|
expect <<EOF
|
||||||
|
EOF
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
qpkg_fail "unknown prereq for new package" prereq foo <<EOF
|
||||||
|
Package: foo
|
||||||
|
Version: 0
|
||||||
|
Architecture: test
|
||||||
|
Depends: bar
|
||||||
|
Filename: foo_0_test.ipkg
|
||||||
|
EOF
|
||||||
|
expect <<EOF
|
||||||
|
can't resolve foo
|
||||||
|
EOF
|
Loading…
Reference in New Issue
Block a user