X-Original-To: alpine-devel@lists.alpinelinux.org Delivered-To: alpine-devel@lists.alpinelinux.org Received: from mail-bw0-f54.google.com (mail-bw0-f54.google.com [209.85.214.54]) by lists.alpinelinux.org (Postfix) with ESMTP id 55D0F1EBFEE for ; Fri, 31 Dec 2010 11:38:43 +0000 (UTC) Received: by bwz12 with SMTP id 12so4989686bwz.13 for ; Fri, 31 Dec 2010 03:38:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=lAXz/0vMg7ms5Hzxsq28DxCvlwT0HmF5HXcHfGGtvjE=; b=QrywFMG+TO46UHrQ831bsBqMKVVCwpoAUzebwQngViAy0NTjQgaNoVIKh31UMwY12J YdO35MWeE3JQ7kmvv0Dlo8vBaZ9JW6vz1m2jEjYK/XqgvqSmUSs86TOFTZlH0tgvle4Q w4bG6avcLC98WY8znq8trN4nhiebCwHFJIA4w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=UlZJj6LkVpM813a1qR4mP4nXVVhYb8xKCjN7xXAOoY0PPlj9BtYzx+K5ZPYqHw9VE+ O5F4JtHk0wWyakzpK3k44c9MCGbPac2VpzkpXIErQHZXa5Kte+RvZnWJr08zW6DeY/6M gku8mE0IEq6uuL/OPTAIP8Wd/bzUc3ohIzEW4= X-Mailinglist: alpine-devel Precedence: list List-Id: Alpine Development List-Unsubscribe: List-Post: List-Help: List-Subscribe: MIME-Version: 1.0 Received: by 10.204.46.154 with SMTP id j26mr13363687bkf.134.1293795522621; Fri, 31 Dec 2010 03:38:42 -0800 (PST) Received: by 10.204.118.13 with HTTP; Fri, 31 Dec 2010 03:38:42 -0800 (PST) In-Reply-To: <1293551811-32485-1-git-send-email-ncopa@alpinelinux.org> References: <1293551811-32485-1-git-send-email-ncopa@alpinelinux.org> Date: Fri, 31 Dec 2010 06:38:42 -0500 Message-ID: Subject: Re: [alpine-devel] [PATCH] misc improvements for apts From: Jeff Bilyk To: Natanael Copa Cc: alpine-devel@lists.alpinelinux.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Applied. On Tue, Dec 28, 2010 at 10:56 AM, Natanael Copa wro= te: > - 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 > =A0tests with: 'apts *.out' > --- > =A0apts =A0 =A0 =A0| =A0152 +++++++++++++++++++++++++--------------------= ---------------- > =A0apts.conf | =A0 =A02 +- > =A02 files changed, 63 insertions(+), 91 deletions(-) > > diff --git a/apts b/apts > index eb8128d..8cb4ccb 100755 > --- a/apts > +++ b/apts > @@ -10,112 +10,84 @@ > =A0program=3D$0 > > =A0usage() { > - =A0 =A0 =A0 echo "Usage: $program outputfile " > + =A0 =A0 =A0 echo "Usage: $program [-he] [-o OUTDIR] [TEST...]" > =A0 =A0 =A0 =A0exit 1 > =A0} > > +# dont not halt on fail by default > +halt_on_fail=3D > + > +# default outdir is current working dir > +outdir=3D"$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 > + =A0 =A0 =A0 TESTSDIR=3D${APTS_DIR:-"$PWD/tests"} > +else > + =A0 =A0 =A0 # default to /usr/share/apts/tests > + =A0 =A0 =A0 TESTSDIR=3D${APTS_DIR:-"/usr/share/apts/tests"} > + =A0 =A0 =A0 # allow use to override > + =A0 =A0 =A0 if [ -r /etc/apts/apts.conf ]; then > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 . /etc/apts/apts.conf > + =A0 =A0 =A0 fi > +fi > + > =A0# parse opts > -while getopts "h" opt; do > +while getopts "d:eho:" opt; do > =A0 =A0 =A0 =A0case "$opt" in > + =A0 =A0 =A0 d) TESTSDIR=3D"$OPTARG";; > + =A0 =A0 =A0 e) halt_on_fail=3Dyes;; > =A0 =A0 =A0 =A0h) usage;; > - =A0 =A0 =A0 help) usage;; > + =A0 =A0 =A0 o) outdir=3D$OPTARG;; > =A0 =A0 =A0 =A0esac > =A0done > > -OUTFILE=3D$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 bot= her > +cd "$TESTSDIR" || exit 1 > > -# are there any file arguments > +# if there aren't any args then test all packages > =A0if [ $# -eq 0 ]; then > - =A0 =A0 =A0 echo "no outfile specified" > - =A0 =A0 =A0 usage > + =A0 =A0 =A0 set -- * > =A0fi > > -#remove opts so that package is $@ > -shift $(( $OPTIND - 1 )) > - > -# shift once more > -shift > +totaltests=3D$# > > -# Get directory with test files > -. /etc/apts/apts.conf > +# Initialize counter > +i=3D0 > > -# Check that TESTSDIR exists before proceeding > -test -e $TESTSDIR > -if [ $? -gt 0 ]; then > - =A0 =A0 =A0 echo "Test file directory $TESTSDIR doesn't exit" && exit 1= ; > -fi > +echo "${totaltests} tests to be run" > +passedtests=3D"0" > +failed=3D > +for tst in "$@"; do > + =A0 =A0 =A0 # Increment counter for tested packages > + =A0 =A0 =A0 i=3D$((i + 1)) > + =A0 =A0 =A0 outfile=3D"$outdir"/$tst.out > + =A0 =A0 =A0 echo -n "Testing ${tst%.out} (${i}/${totaltests})..." > + =A0 =A0 =A0 if /bin/sh -e $tst $tst > "$outfile" 2>&1; then > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 # test passed > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 echo " ok" > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rm "$outfile" > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 passedtests=3D$((passedtests + 1)) > + =A0 =A0 =A0 else > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 # test failed > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 echo " failed" > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 failed=3D"$failed $tst" > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 [ -n "$halt_on_fail" ] && break > + =A0 =A0 =A0 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 > - > - =A0 =A0 =A0 # Initialize counter > - =A0 =A0 =A0 i=3D1 > - > - =A0 =A0 =A0 # Get total number of packages for status counters > - =A0 =A0 =A0 totaltests=3D`ls ./tests/ | wc -w` > - =A0 =A0 =A0 echo "All (${totaltests}) packages to be tested" > - =A0 =A0 =A0 passedtests=3D"0" > - =A0 =A0 =A0 for package in `ls ./tests/`; do > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0echo "Testing $package apk (${i}/${total= tests})" > - > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 # Increment counter for tested packages > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 i=3D$((i + 1)) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 /bin/sh -e ./tests/$package $package >> "$O= UTFILE" 2>&1 > - > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 # If exit code is non-zero, exit apts > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 if [ $? -gt 0 ]; then > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 echo "$package failed tests= " && exit 1; > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 fi > - > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 # Log to both outfile and stdout > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 echo "$package passed tests" >> "$OUTFILE" > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 echo "$package passed tests" > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 passedtests=3D$((passedtests + 1)) > - =A0 =A0 =A0 =A0done > - =A0 =A0 =A0 echo "$passedtests of $totaltests passed" > - =A0 =A0 =A0 exit 0; > +if [ -n "$failed" ]; then > + =A0 =A0 =A0 echo "The following packages failed:" > + =A0 =A0 =A0 echo $failed > =A0fi > > -# If script still running, there's args, so test all specified packages > -i=3D1 > - > -# Loop through all packages specified > -while [ $# -gt 0 ]; do > - =A0 =A0 =A0 echo "Package $i: $1" > - =A0 =A0 =A0 PACKAGE=3D$1 > - > - =A0 =A0 =A0 # does testing file exist > - =A0 =A0 =A0 test -e ./tests/$PACKAGE > - > - =A0 =A0 =A0 # If no testing file exists then run generic-apk > - =A0 =A0 =A0 if [ "$?" =3D=3D "1" ]; then > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 echo "Testing file for $PACKAGE does not ex= ist" > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 /bin/sh -e ./tests/generic-apk $PACKAGE >> = "$OUTFILE" 2>&1 > - > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 # If =A0exit code is non-zero, exit apts > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 if [ $? -gt 0 ]; then > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 echo "$PACKAGE failed tests= " && exit 1; > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 fi > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 # if script is running, package passed test= s > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 echo "$PACKAGE passed tests" > - > - =A0 =A0 =A0 # if testing file exists, then keep running > - =A0 =A0 =A0 else > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 echo "Testing $PACKAGE apk" > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 /bin/sh -e ./tests/$PACKAGE $PACKAGE >> "$O= UTFILE" 2>&1 > - > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 # If =A0exit code is non-zero, exit apts > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 if [ $? -gt 0 ]; then > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 echo "$PACKAGE failed tests= " && exit 1; > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 fi > - > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 echo "$PACKAGE passed tests" > - =A0 =A0 =A0 fi > - > - =A0 =A0 =A0 # Increment counter and shift to next arg > - =A0 =A0 =A0 i=3D$((i + 1)) > - =A0 =A0 =A0 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=3D/usr/share/apts/ > +TESTSDIR=3D/usr/share/apts/tests > -- > 1.7.3.4 > > > > --- > Unsubscribe: =A0alpine-devel+unsubscribe@lists.alpinelinux.org > Help: =A0 =A0 =A0 =A0 alpine-devel+help@lists.alpinelinux.org > --- > > --=20 Jeff --- Unsubscribe: alpine-devel+unsubscribe@lists.alpinelinux.org Help: alpine-devel+help@lists.alpinelinux.org ---