#!/bin/sh # apts is a testing suite for packages on the Alpine Linux system # In theory, it will work on any distribution that uses the apk-tools # package manager # Author: Jeff Bilyk # Contributor: Natanael Copa # Version History available at http://git.alpinelinux.org/cgit/apts/ # Get file to output to program=$0 usage() { echo "Usage: $program [-he] [-o OUTDIR] [TEST...]" exit 1 } # do 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 "d:eho:" opt; do case "$opt" in d) TESTSDIR="$OPTARG";; e) halt_on_fail=yes;; h) usage;; o) outdir=$OPTARG;; esac done # Remove trailing slash from outdir if ! [ $outdir == "$PWD" ]; then outdir=`echo "$outdir" | sed "s,/$,,"`; fi #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 # if there aren't any args then test all packages if [ $# -eq 0 ]; then set -- * fi totaltests=$# # Initialize counter i=0 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 echo "" echo "$passedtests of $totaltests passed" if [ -n "$failed" ]; then echo "The following packages failed:" echo $failed fi # return success if all tests passed exit $(( $totaltests - $passedtests))