- 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 <package>"+ 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 packagesif [ $# -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 $failedfi
-# 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
---
Re: [alpine-devel] [PATCH] misc improvements for apts