#! /usr/bin/env bash # Usage: test.sh [test-options] [bpkg-common-options] # # Test options are: # # -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. # # --remote # Test using the remote repositories. Normally, you would first run the # local test in order to create the repositories, then publish them (see # repository/publish.sh), and finally run the remote test. # # --valgrind # Run under valgrind (takes forever). # # Some common bpkg use-cases worth testing: # # --fetch wget # --fetch curl # --fetch fetch --tar bsdtar # trap 'exit 1' ERR function error () { echo "$*" 1>&2 exit 1 } bpkg="../bpkg/bpkg" cfg=/tmp/conf verbose=n remote=n options= while [ $# -gt 0 ]; do case $1 in -v) verbose=y shift ;; --remote) remote=y shift ;; --valgrind) bpkg="valgrind -q $bpkg" shift ;; *) # If this is the --verbose bpkg option, switch to the verbose # mode as well. # if [ "$1" == "--verbose" ]; then verbose=y fi options="$options $1" shift ;; esac done if [ "$verbose" != "y" ]; then options="$options -q" fi bpkg="$bpkg $options" # Repository location, name, and absolute location prefixes. # if [ "$remote" = "y" ]; then rep=http://pkg.cppget.org/tests/1 repn=cppget.org/ repa=$rep else rep=repository/1 repn= repa=`pwd`/$rep fi # # function test () { local cmd=$1; shift local ops= if [ "$cmd" != "rep-create" -a \ "$cmd" != "rep-info" -a \ "$cmd" != "pkg-verify" ]; 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" -a \ "$cmd" != "pkg-verify" ]; 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 s=`$bpkg pkg-status -d $cfg $1` if [ "$s" != "$2" ]; then error "status $1: '"$s"', expected: '"$2"'" fi } # Verify path is gone (no longer exists) # function gone () { if [ -e "$1" ]; then error "path $1 still exists" fi } #if false; then ## ## Low-level commands. ## ## ## pkg-verify ## fail pkg-verify # archive expected fail pkg-verify ./no-such-file # archive does not exist fail pkg-verify repository/1/common/not-a-package.tar.gz fail pkg-verify --silent repository/1/common/not-a-package.tar.gz test pkg-verify repository/1/common/hello/libhello-1.0.0.tar.gz ## ## rep-create ## fail rep-create # no 'repositories' file fail rep-create repository/1/satisfy # unexpected files test rep-create repository/1/common/hello test rep-create repository/1/common/foo/stable test rep-create repository/1/common/foo/testing test rep-create repository/1/common/bar/stable test rep-create repository/1/common/bar/testing test rep-create repository/1/common/bar/unstable ## ## rep-info ## fail rep-info # repository location expected test rep-info $rep/common/foo/testing <= 1.1.0 location: libbar-1.1.1.tar.gz EOF ## ## cfg-create ## test cfg-create --wipe cxx config.install.root=/tmp/install stat libfoo unknown test cfg-create --wipe config.install.root=/tmp/install cxx stat libfoo unknown ## ## rep-add ## test cfg-create --wipe fail rep-add # repository location expected fail rep-add stable # invalid location fail rep-add http:// # invalid location # relative path # test rep-add ./1/bar/stable fail rep-add ./1/../1/bar/stable # duplicate # absolute path # test rep-add /tmp/1/foo/stable fail rep-add /tmp/1/../1/foo/stable # duplicate # remote URL # test rep-add http://pkg.example.org/1/testing fail rep-add http://www.example.org/1/testing # duplicate ## ## rep-fetch ## test cfg-create --wipe fail rep-fetch # no repositories # hello repository # test cfg-create --wipe test rep-add $rep/common/hello test rep-fetch test rep-fetch # bar/unstable repository # test cfg-create --wipe test rep-add $rep/common/bar/unstable test rep-fetch test rep-fetch # both # test cfg-create --wipe test rep-add $rep/common/hello test rep-add $rep/common/bar/unstable test rep-fetch test rep-fetch ## ## pkg-fetch ## test rep-create repository/1/fetch/t1 test cfg-create --wipe fail pkg-fetch -e # archive expected fail pkg-fetch -e ./no-such-file # archive does not exist fail pkg-fetch # package name expected fail pkg-fetch libfoo # package version expected fail pkg-fetch libfoo/1/2/3 # invalid package version fail pkg-fetch libfoo/1.0.0 # no repositories test rep-add $rep/fetch/t1 fail pkg-fetch libfoo/1.0.0 # no packages test rep-fetch fail pkg-fetch libfoo/2+1.0.0 # not available test cfg-create --wipe test rep-add $rep/fetch/t1 test rep-fetch test pkg-fetch libfoo/1.0.0 stat libfoo/1.0.0 fetched fail pkg-fetch libfoo/1.0.0 fail pkg-fetch -e repository/1/fetch/libfoo-1.0.0.tar.gz test pkg-purge libfoo test pkg-fetch -e repository/1/fetch/libfoo-1.0.0.tar.gz stat libfoo/1.0.0 fetched test pkg-unpack libfoo test pkg-fetch -r libfoo/1.1.0 stat libfoo/1.1.0 fetched test pkg-unpack libfoo test pkg-fetch -r -e repository/1/fetch/libfoo-1.0.0.tar.gz stat libfoo/1.0.0 fetched test pkg-fetch -r libfoo/1.1.0 stat libfoo/1.1.0 fetched test pkg-fetch -r -e repository/1/fetch/libfoo-1.0.0.tar.gz stat libfoo/1.0.0 fetched test pkg-purge libfoo # hello # test cfg-create --wipe test rep-add $rep/common/hello test rep-fetch test pkg-fetch libhello/1.0.0 test pkg-purge libhello ## ## pkg-unpack ## test cfg-create --wipe fail pkg-unpack -r # replace only with existing fail pkg-unpack -e # package directory expected fail pkg-unpack # package name expected test rep-add $rep/fetch/t1 test rep-fetch # existing # fail pkg-unpack -e ./no-such-dir # package directory does not exist fail pkg-unpack -e ./repository # not a package directory test pkg-fetch libfoo/1.0.0 fail pkg-unpack -e repository/1/fetch/libfoo-1.1.0 # already exists test pkg-purge libfoo test pkg-unpack -e repository/1/fetch/libfoo-1.1.0 stat libfoo/1.1.0 unpacked test pkg-purge libfoo # existing & replace # test pkg-fetch libfoo/1.0.0 fail pkg-unpack -e repository/1/fetch/libfoo-1.1.0 test pkg-unpack -r -e repository/1/fetch/libfoo-1.1.0 stat libfoo/1.1.0 unpacked test pkg-purge libfoo test pkg-fetch libfoo/1.0.0 test pkg-unpack libfoo fail pkg-unpack -e repository/1/fetch/libfoo-1.1.0 test pkg-unpack -r -e repository/1/fetch/libfoo-1.1.0 stat libfoo/1.1.0 unpacked test pkg-purge libfoo # package name # fail pkg-unpack libfoo # no such package in configuration test pkg-unpack -e repository/1/fetch/libfoo-1.1.0 fail pkg-unpack libfoo # wrong package state test pkg-purge libfoo test pkg-fetch libfoo/1.0.0 stat libfoo/1.0.0 fetched test pkg-unpack libfoo stat libfoo/1.0.0 unpacked test pkg-purge libfoo # hello # test cfg-create --wipe test rep-add $rep/common/hello test rep-fetch test pkg-fetch libhello/1.0.0 test pkg-unpack libhello test pkg-purge libhello ## ## pkg-purge ## test cfg-create --wipe fail pkg-purge # missing package name fail pkg-purge libfoo # no such package # purge fetched # test pkg-fetch -e repository/1/fetch/libfoo-1.0.0.tar.gz test pkg-purge libfoo stat libfoo unknown # --keep # test pkg-fetch -e repository/1/fetch/libfoo-1.0.0.tar.gz test pkg-purge -k libfoo stat libfoo "fetched 1.0.0" test pkg-purge libfoo # archive and --purge # cp repository/1/fetch/libfoo-1.0.0.tar.gz $cfg/ test pkg-fetch -e -p $cfg/libfoo-1.0.0.tar.gz test pkg-purge libfoo stat libfoo unknown gone $cfg/libfoo-1.0.0.tar.gz # no archive but --keep # test pkg-unpack -e repository/1/fetch/libfoo-1.1.0 fail pkg-purge --keep libfoo stat libfoo "unpacked 1.1.0" test pkg-purge libfoo # purge unpacked directory # test pkg-unpack -e repository/1/fetch/libfoo-1.1.0 test pkg-purge libfoo stat libfoo unknown # purge unpacked archive # test pkg-fetch -e repository/1/fetch/libfoo-1.0.0.tar.gz test pkg-unpack libfoo test pkg-purge libfoo stat libfoo unknown gone $cfg/libfoo-1.0.0 # purge unpacked archive but --keep # test pkg-fetch -e repository/1/fetch/libfoo-1.0.0.tar.gz test pkg-unpack libfoo test pkg-purge --keep libfoo stat libfoo "fetched 1.0.0" gone $cfg/libfoo-1.0.0 test pkg-purge libfoo stat libfoo unknown # directory and --purge # cp -r repository/1/fetch/libfoo-1.1.0 $cfg/ test pkg-unpack -e -p $cfg/libfoo-1.1.0 test pkg-purge libfoo stat libfoo unknown gone $cfg/libfoo-1.1.0 # archive and --purge # cp repository/1/fetch/libfoo-1.0.0.tar.gz $cfg/ test pkg-fetch -e -p $cfg/libfoo-1.0.0.tar.gz test pkg-unpack libfoo test pkg-purge libfoo stat libfoo unknown gone $cfg/libfoo-1.0.0 gone $cfg/libfoo-1.0.0.tar.gz # broken # cp repository/1/fetch/libfoo-1.0.0.tar.gz $cfg/ test pkg-fetch -e -p $cfg/libfoo-1.0.0.tar.gz test pkg-unpack libfoo chmod 000 $cfg/libfoo-1.0.0 fail pkg-purge libfoo stat libfoo/1.0.0 broken fail pkg-purge libfoo # need --force fail pkg-purge -f -k libfoo # can't keep broken fail pkg-purge -f libfoo # out directory still exists chmod 755 $cfg/libfoo-1.0.0 rm -r $cfg/libfoo-1.0.0 fail pkg-purge -f libfoo # archive still exists rm $cfg/libfoo-1.0.0.tar.gz test pkg-purge -f libfoo stat libfoo unknown ## ## pkg-configure/pkg-disfigure ## test cfg-create --wipe test rep-add $rep/common/hello test rep-fetch fail pkg-configure # package name expected fail pkg-configure config.dist.root=/tmp # ditto fail pkg-configure libhello libhello # unexpected argument fail pkg-configure libhello1 # no such package fail pkg-disfigure # package name expected fail pkg-disfigure libhello1 # no such package test pkg-fetch libhello/1.0.0 fail pkg-configure libhello # wrong package state fail pkg-disfigure libhello # wrong package state test pkg-purge libhello # src == out # test pkg-fetch libhello/1.0.0 test pkg-unpack libhello test pkg-configure libhello stat libhello "configured 1.0.0" test pkg-disfigure libhello stat libhello "unpacked 1.0.0" test pkg-purge libhello stat libhello/1.0.0 available # src != out # test cfg-create --wipe test pkg-unpack -e repository/1/common/libhello-1.0.0 test pkg-configure libhello stat libhello "configured 1.0.0" test pkg-disfigure libhello stat libhello "unpacked 1.0.0" test pkg-purge libhello stat libhello unknown gone $cfg/libhello-1.0.0 # out still exists after disfigure # test pkg-unpack -e repository/1/common/libhello-1.0.0 test pkg-configure libhello touch $cfg/libhello-1.0.0/stray fail pkg-disfigure libhello stat libhello/1.0.0 broken rm -r $cfg/libhello-1.0.0 test pkg-purge -f libhello stat libhello unknown # disfigure failed # test pkg-unpack -e repository/1/common/libhello-1.0.0 test pkg-configure libhello chmod 555 $cfg/libhello-1.0.0 fail pkg-disfigure libhello stat libhello/1.0.0 broken chmod 755 $cfg/libhello-1.0.0 rm -r $cfg/libhello-1.0.0 test pkg-purge -f libhello stat libhello unknown # configure failed but disfigure succeeds # test pkg-unpack -e repository/1/common/libhello-1.0.0 mkdir -p $cfg/libhello-1.0.0/build chmod 555 $cfg/libhello-1.0.0/build fail pkg-configure libhello stat libhello "unpacked 1.0.0" test pkg-purge libhello stat libhello unknown # configure and disfigure both failed # test pkg-unpack -e repository/1/common/libhello-1.0.0 mkdir -p $cfg/libhello-1.0.0/build chmod 555 $cfg/libhello-1.0.0 $cfg/libhello-1.0.0/build # Trip both con/dis. fail pkg-configure libhello stat libhello/1.0.0 broken chmod 755 $cfg/libhello-1.0.0 $cfg/libhello-1.0.0/build rm -r $cfg/libhello-1.0.0 test pkg-purge -f libhello stat libhello unknown # dependency management # test rep-create repository/1/depend/stable test cfg-create --wipe test rep-add $rep/depend/stable test rep-fetch test pkg-fetch libbar/1.0.0 test pkg-unpack libbar fail pkg-configure libbar # no libfoo stat libbar/1.0.0 "unpacked" test pkg-fetch libfoo/1.0.0 test pkg-unpack libfoo fail pkg-configure libbar # libfoo not configured test pkg-configure libfoo test pkg-configure libbar fail pkg-disfigure libfoo # libbar still depends on libfoo test pkg-disfigure libbar test pkg-disfigure libfoo test pkg-purge libbar test pkg-purge libfoo test pkg-fetch libfoo/1.0.0 test pkg-unpack libfoo test pkg-configure libfoo test pkg-fetch libbar/1.1.0 test pkg-unpack libbar fail pkg-configure libbar # libfoo >= 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 $rep/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 $rep/status/extra test rep-fetch stat libbar "available 1.1.0-1" test rep-add $rep/status/stable test rep-fetch stat libbar "available 1.1.0-1 1.0.0" test cfg-create --wipe test rep-add $rep/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 $rep/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 ## test cfg-create --wipe test rep-add $rep/common/hello test rep-fetch fail pkg-update # package name expected fail pkg-update libhello # no such package test pkg-fetch libhello/1.0.0 fail pkg-update libhello # wrong package state test pkg-purge libhello # src == out # test pkg-fetch libhello/1.0.0 test pkg-unpack libhello test pkg-configure libhello test pkg-update libhello test pkg-update libhello test pkg-disfigure libhello test pkg-purge libhello # src != out # test cfg-create --wipe test pkg-unpack -e repository/1/common/libhello-1.0.0 test pkg-configure libhello test pkg-update libhello test pkg-update libhello test pkg-disfigure libhello test pkg-purge libhello ## ## pkg-clean ## test cfg-create --wipe test rep-add $rep/common/hello test rep-fetch fail pkg-clean # package name expected fail pkg-clean libhello # no such package test pkg-fetch libhello/1.0.0 fail pkg-clean libhello # wrong package state test pkg-purge libhello # src == out # test pkg-fetch libhello/1.0.0 test pkg-unpack libhello test pkg-configure libhello test pkg-update libhello test pkg-clean libhello test pkg-clean libhello test pkg-disfigure libhello test pkg-purge libhello # src != out # test cfg-create --wipe test pkg-unpack -e repository/1/common/libhello-1.0.0 test pkg-configure libhello test pkg-update libhello test pkg-clean libhello test pkg-clean libhello test pkg-disfigure libhello test pkg-purge libhello ## ## Low-level command scenarios. ## # build and clean package # test cfg-create --wipe cxx test rep-add $rep/common/hello test rep-fetch test pkg-fetch libhello/1.0.0 test pkg-unpack libhello test pkg-configure libhello test pkg-update libhello test pkg-clean libhello test pkg-disfigure libhello test pkg-purge libhello ## ## High-level commands. ## ## ## build ## # 1 (libfoo) # 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 rep-create repository/1/satisfy/t4d test cfg-create --wipe test rep-add $rep/satisfy/t4c test rep-fetch test build -p libbaz <