X-Original-To: alpine-devel@lists.alpinelinux.org Delivered-To: alpine-devel@lists.alpinelinux.org Received: from mail.alpinelinux.org (mail.alpinelinux.org [213.234.126.132]) by lists.alpinelinux.org (Postfix) with ESMTP id 1A2071EB587 for ; Tue, 28 Dec 2010 15:57:21 +0000 (UTC) Received: from ncdev.alpinelinux.org (build.alpinelinux.org [91.220.88.20]) by mail.alpinelinux.org (Postfix) with ESMTP id E674650A8B0B5; Tue, 28 Dec 2010 15:57:19 +0000 (UTC) From: Natanael Copa To: alpine-devel@lists.alpinelinux.org Cc: Natanael Copa Subject: [alpine-devel] [PATCH] misc improvements for apts Date: Tue, 28 Dec 2010 15:56:51 +0000 Message-Id: <1293551811-32485-1-git-send-email-ncopa@alpinelinux.org> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: X-Mailinglist: alpine-devel Precedence: list List-Id: Alpine Development List-Unsubscribe: List-Post: List-Help: List-Subscribe: - allow run aots directly from git dir - do not require the OUTFILE param, instead only out to stdout - by default, run all tests even if any fails - allow halt on first error with -e option - send output from test to $tst.out - allow specify outdir for *.out files with -o DIR - no special logic for generic-apk - strip .out from given test name so you can easily re-run all failed tests with: 'apts *.out' --- apts | 152 +++++++++++++++++++++++++------------------------------------ apts.conf | 2 +- 2 files changed, 63 insertions(+), 91 deletions(-) diff --git a/apts b/apts index eb8128d..8cb4ccb 100755 --- a/apts +++ b/apts @@ -10,112 +10,84 @@ program=$0 usage() { - echo "Usage: $program outputfile " + echo "Usage: $program [-he] [-o OUTDIR] [TEST...]" exit 1 } +# dont not halt on fail by default +halt_on_fail= + +# default outdir is current working dir +outdir="$PWD" + +# default TESTDIR to $PWD/tests so we can run it directly from git dir +# allow override with APTS_DIR env var +if [ -d .git ] && [ -d tests ]; then + TESTSDIR=${APTS_DIR:-"$PWD/tests"} +else + # default to /usr/share/apts/tests + TESTSDIR=${APTS_DIR:-"/usr/share/apts/tests"} + # allow use to override + if [ -r /etc/apts/apts.conf ]; then + . /etc/apts/apts.conf + fi +fi + # parse opts -while getopts "h" opt; do +while getopts "d:eho:" opt; do case "$opt" in + d) TESTSDIR="$OPTARG";; + e) halt_on_fail=yes;; h) usage;; - help) usage;; + o) outdir=$OPTARG;; esac done -OUTFILE=$1 +#remove opts so that package(s) is $@ +shift $(( $OPTIND - 1 )) + +# CD to test file dir. will print error message if needed so we dont bother +cd "$TESTSDIR" || exit 1 -# are there any file arguments +# if there aren't any args then test all packages if [ $# -eq 0 ]; then - echo "no outfile specified" - usage + set -- * fi -#remove opts so that package is $@ -shift $(( $OPTIND - 1 )) - -# shift once more -shift +totaltests=$# -# Get directory with test files -. /etc/apts/apts.conf +# Initialize counter +i=0 -# Check that TESTSDIR exists before proceeding -test -e $TESTSDIR -if [ $? -gt 0 ]; then - echo "Test file directory $TESTSDIR doesn't exit" && exit 1; -fi +echo "${totaltests} tests to be run" +passedtests="0" +failed= +for tst in "$@"; do + # Increment counter for tested packages + i=$((i + 1)) + outfile="$outdir"/$tst.out + echo -n "Testing ${tst%.out} (${i}/${totaltests})..." + if /bin/sh -e $tst $tst > "$outfile" 2>&1; then + # test passed + echo " ok" + rm "$outfile" + passedtests=$((passedtests + 1)) + else + # test failed + echo " failed" + failed="$failed $tst" + [ -n "$halt_on_fail" ] && break + fi +done -# CD to test file dir -cd $TESTSDIR +echo "" +echo "$passedtests of $totaltests passed" -# if there aren't any args besides outfile test all packages -if [ $# -eq 0 ]; then - - # Initialize counter - i=1 - - # Get total number of packages for status counters - totaltests=`ls ./tests/ | wc -w` - echo "All (${totaltests}) packages to be tested" - passedtests="0" - for package in `ls ./tests/`; do - echo "Testing $package apk (${i}/${totaltests})" - - # Increment counter for tested packages - i=$((i + 1)) - /bin/sh -e ./tests/$package $package >> "$OUTFILE" 2>&1 - - # If exit code is non-zero, exit apts - if [ $? -gt 0 ]; then - echo "$package failed tests" && exit 1; - fi - - # Log to both outfile and stdout - echo "$package passed tests" >> "$OUTFILE" - echo "$package passed tests" - passedtests=$((passedtests + 1)) - done - echo "$passedtests of $totaltests passed" - exit 0; +if [ -n "$failed" ]; then + echo "The following packages failed:" + echo $failed fi -# If script still running, there's args, so test all specified packages -i=1 - -# Loop through all packages specified -while [ $# -gt 0 ]; do - echo "Package $i: $1" - PACKAGE=$1 - - # does testing file exist - test -e ./tests/$PACKAGE - - # If no testing file exists then run generic-apk - if [ "$?" == "1" ]; then - echo "Testing file for $PACKAGE does not exist" - /bin/sh -e ./tests/generic-apk $PACKAGE >> "$OUTFILE" 2>&1 - - # If exit code is non-zero, exit apts - if [ $? -gt 0 ]; then - echo "$PACKAGE failed tests" && exit 1; - fi - # if script is running, package passed tests - echo "$PACKAGE passed tests" - - # if testing file exists, then keep running - else - echo "Testing $PACKAGE apk" - /bin/sh -e ./tests/$PACKAGE $PACKAGE >> "$OUTFILE" 2>&1 - - # If exit code is non-zero, exit apts - if [ $? -gt 0 ]; then - echo "$PACKAGE failed tests" && exit 1; - fi - - echo "$PACKAGE passed tests" - fi - - # Increment counter and shift to next arg - i=$((i + 1)) - shift -done +# return success if all tests passed +exit $(( $totaltests - $passedtests)) + diff --git a/apts.conf b/apts.conf index 4caf878..85ce08d 100644 --- a/apts.conf +++ b/apts.conf @@ -1 +1 @@ -TESTSDIR=/usr/share/apts/ +TESTSDIR=/usr/share/apts/tests -- 1.7.3.4 --- Unsubscribe: alpine-devel+unsubscribe@lists.alpinelinux.org Help: alpine-devel+help@lists.alpinelinux.org ---