From e229d0889faef3931240d5e348c1c70917c7d7f5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 12 Oct 2015 09:04:13 +0200 Subject: Move test script to tests/ --- tests/test.sh | 1047 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1047 insertions(+) create mode 100755 tests/test.sh (limited to 'tests') diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 0000000..c553f58 --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,1047 @@ +#! /usr/bin/env bash + +# -v Run verbose. By default, this script runs bpkg quiet and suppresses +# error messages in the fail tests. Note that when this options is +# specified, bpkg is called with default verbosity level. If you want +# more bpkg diagnostics, add the --verbose N option. +# + +trap 'exit 1' ERR + +function error () +{ + echo "$*" 1>&2 + exit 1 +} + +bpkg="../bpkg/bpkg" +#bpkg="valgrind -q ../bpkg/bpkg" +#bpkg="../bpkg/bpkg --fetch curl" +#bpkg="../bpkg/bpkg --fetch fetch --tar bsdtar" +cfg=/tmp/conf +pkg=libhello +ver=1.0.0 +pkga=../../hello/dist/$pkg-$ver.tar.bz2 +pkgd=../../hello/dist/$pkg-$ver +out=$cfg/`basename $pkgd` +rep=../../hello/1/hello + +abs_rep=`pwd`/repository/1 + +verbose=n +options= + +while [ $# -gt 0 ]; do + case $1 in + -v) + verbose=y + shift + ;; + *) + options="$options $1" + shift + ;; + esac +done + +if [ "$verbose" != "y" ]; then + options="$options -q" +fi + +bpkg="$bpkg $options" + +# +# +function test () +{ + local cmd=$1; shift + local ops= + + if [ "$cmd" != "rep-create" -a "$cmd" != "rep-info" ]; then + ops="-d $cfg" + fi + + if [ -t 0 ]; then + $bpkg $cmd $ops $* + else + # There is no way to get the exit code in process substitution + # so ruin the output. + # + diff -u - <($bpkg $cmd $ops $* || echo "") + fi + + if [ $? -ne 0 ]; then + error "failed: $bpkg $cmd $ops $*" + fi +} + +function fail () +{ + local cmd=$1; shift + local ops= + + if [ "$cmd" != "rep-create" -a "$cmd" != "rep-info" ]; then + ops="-d $cfg" + fi + + if [ "$verbose" = "y" ]; then + $bpkg $cmd $ops $* + else + $bpkg $cmd $ops $* 2>/dev/null + fi + + if [ $? -eq 0 ]; then + error "succeeded: $bpkg $cmd $ops $*" + fi + + return 0 +} + +# Verify package status. +# +function stat () +{ + local c="$bpkg pkg-status -d $cfg" + + if [ $# -eq 1 ]; then + c="$c $pkg/$ver" + elif [ $# -eq 2 ]; then + c="$c $1"; shift + fi + + local s=`$c` + + if [ "$s" != "$1" ]; then + error "status: '"$s"', expected: '"$1"'" + fi +} + +# Verify path is gone (no longer exists) +# +function gone () +{ + if [ -e "$1" ]; then + error "path $1 still exists" + fi +} + +## +## rep-create +## + +fail rep-create # no 'repositories' file + +test rep-create repository/1/misc/stable +test rep-create repository/1/misc/testing + +test rep-create repository/1/math/stable +test rep-create repository/1/math/testing +test rep-create repository/1/math/unstable + +## +## rep-info +## + +fail rep-info # repository location expected + +test rep-info repository/1/misc/testing <= 1.1.0 +test pkg-disfigure libfoo +test pkg-purge libfoo +test pkg-fetch libfoo/1.1.0 +test pkg-unpack libfoo +test pkg-configure libfoo +test pkg-configure libbar +test pkg-disfigure libbar +test pkg-disfigure libfoo +test pkg-purge libfoo +test pkg-purge libbar + +test pkg-fetch libfoo/1.1.0 +test pkg-unpack libfoo +test pkg-configure libfoo +test pkg-fetch libbar/1.2.0 +test pkg-unpack libbar +fail pkg-configure libbar # libfoo >= 1.2.0 +test pkg-disfigure libfoo +test pkg-purge libfoo +test pkg-fetch libfoo/1.2.0 +test pkg-unpack libfoo +test pkg-configure libfoo +test pkg-configure libbar +fail pkg-disfigure libfoo # "package libbar on libfoo >= 1.2.0" +test pkg-disfigure libbar +test pkg-disfigure libfoo +test pkg-purge libfoo +test pkg-purge libbar + +test pkg-fetch libfoo/1.1.0 +test pkg-unpack libfoo +test pkg-configure libfoo +test pkg-fetch libbar/1.3.0 +test pkg-unpack libbar +fail pkg-configure libbar # incompatible constraints +test pkg-disfigure libfoo +test pkg-purge libfoo +test pkg-purge libbar + +## +## pkg-status (also tested in pkg-{fetch,unpack,configure,disfigure,purge} +## + +test rep-create repository/1/status/stable +test rep-create repository/1/status/extra +test rep-create repository/1/status/testing +test rep-create repository/1/status/unstable + +# basics +# +test cfg-create --wipe +stat libfoo/1.0.0 "unknown" +stat libfoo "unknown" +test rep-add repository/1/status/stable +test rep-fetch +stat libfoo/1.0.0 "available" +stat libfoo "available 1.0.0" +test pkg-fetch libfoo/1.0.0 +stat libfoo/1.0.0 "fetched" +stat libfoo "fetched 1.0.0" + +# multiple versions/revisions +# +test cfg-create --wipe +test rep-add repository/1/status/extra +test rep-fetch +stat libbar "available 1.1.0-1" +test rep-add repository/1/status/stable +test rep-fetch +stat libbar "available 1.1.0-1 1.0.0" + +test cfg-create --wipe +test rep-add repository/1/status/testing +test rep-fetch +stat libbar "available 1.1.0 1.0.0-1 1.0.0" + +test cfg-create --wipe +test rep-add repository/1/status/unstable +test rep-fetch +stat libbar "available 2.0.0 1.1.0 1.0.0-1 1.0.0" +test pkg-fetch libbar/1.0.0-1 +stat libbar "fetched 1.0.0-1; available 2.0.0 1.1.0" +test pkg-purge libbar +test pkg-fetch libbar/2.0.0 +stat libbar "fetched 2.0.0" + +## +## pkg-update +## + +fail pkg-update # package name expected +fail pkg-update $pkg # no such package +test pkg-fetch -e $pkga +fail pkg-update $pkg # wrong package state +test pkg-purge $pkg + +# src == out +# +test pkg-fetch -e $pkga +test pkg-unpack $pkg +test pkg-configure $pkg +test pkg-update $pkg +test pkg-update $pkg +test pkg-disfigure $pkg +test pkg-purge $pkg + +# src != out +# +test pkg-unpack -e $pkgd +test pkg-configure $pkg +test pkg-update $pkg +test pkg-update $pkg +test pkg-disfigure $pkg +test pkg-purge $pkg + +## +## pkg-clean +## + +fail pkg-clean # package name expected +fail pkg-clean $pkg # no such package +test pkg-fetch -e $pkga +fail pkg-clean $pkg # wrong package state +test pkg-purge $pkg + +# src == out +# +test pkg-fetch -e $pkga +test pkg-unpack $pkg +test pkg-configure $pkg +test pkg-update $pkg +test pkg-clean $pkg +test pkg-clean $pkg +test pkg-disfigure $pkg +test pkg-purge $pkg + +# src != out +# +test pkg-unpack -e $pkgd +test pkg-configure $pkg +test pkg-update $pkg +test pkg-clean $pkg +test pkg-clean $pkg +test pkg-disfigure $pkg +test pkg-purge $pkg + +## +## Low-level command scenarios. +## + +# build package from remote repository +# +test cfg-create --wipe cxx +test rep-add http://pkg.cppget.org/1/hello +test rep-fetch +test pkg-fetch $pkg/$ver +test pkg-unpack $pkg +test pkg-configure $pkg +test pkg-update $pkg +test pkg-clean $pkg +test pkg-disfigure $pkg +test pkg-purge $pkg + +## +## High-level commands. +## + +## +## build +## + +# 1 +# +test rep-create repository/1/satisfy/t1 +test cfg-create --wipe + +fail build -p # package name expected +fail build -p libfoo # unknown package +fail build -p libfoo/1.0.0 # unknown package +test build -p repository/1/satisfy/libfoo-1.1.0.tar.gz <= 1.1.0) +# +test rep-create repository/1/satisfy/t4a +test rep-create repository/1/satisfy/t4b +test rep-create repository/1/satisfy/t4c +test cfg-create --wipe +test rep-add repository/1/satisfy/t4c +test rep-fetch + +test build -p libbaz <