From 2c953a5d1a0d1b3eb5b4a291fe3fbacb004cc88d Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 21 Nov 2010 04:32:04 -0300 Subject: [PATCH] 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 --- qpkg/Makefile | 14 ++++++++- qpkg/test/Common | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ qpkg/test/minpkg | 43 ++++++++++++++++++++++++++ qpkg/test/prereq | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 212 insertions(+), 1 deletion(-) create mode 100755 qpkg/test/Common create mode 100755 qpkg/test/minpkg create mode 100755 qpkg/test/prereq diff --git a/qpkg/Makefile b/qpkg/Makefile index 3c42ea2..e482a38 100644 --- a/qpkg/Makefile +++ b/qpkg/Makefile @@ -38,7 +38,7 @@ endif # ----- Rules ----------------------------------------------------------------- -.PHONY: all jlime openwrt clean spotless +.PHONY: all jlime openwrt test tests valgrind clean spotless all: qpkg rbtest @@ -62,6 +62,18 @@ qpkg: $(OBJS_qpkg) 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 --------------------------------------------------------------- clean: diff --git a/qpkg/test/Common b/qpkg/test/Common new file mode 100755 index 0000000..a7f7671 --- /dev/null +++ b/qpkg/test/Common @@ -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 diff --git a/qpkg/test/minpkg b/qpkg/test/minpkg new file mode 100755 index 0000000..0051b5e --- /dev/null +++ b/qpkg/test/minpkg @@ -0,0 +1,43 @@ +#!/bin/sh +. ./Common + +############################################################################### + +qpkg_fail "no Version field" <