#! /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 # pkg/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 --fetch-option --no-verify-peer # # --tar bsdtar # # --sha256 shasum # --sha256 sha256-freebsd # trap 'exit 1' ERR tmp_file=`mktemp` # Remove temporary file on exit. Cover the case when exit due to an error. # trap 'rm -f $tmp_file' EXIT function error () { echo "$*" 1>&2 exit 1 } bpkg="../bpkg/bpkg" cfg=/tmp/conf if [ "${MSYSTEM:0:5}" = "MINGW" -o "${MSYSTEM:0:4}" = "MSYS" ]; then msys=y fi 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 and name prefixes. Note that the local path is carefully # crafted so that we end up with the same repository names in both cases. This # is necessary for the authentication tests to work in both cases. # if [ "$remote" = "y" ]; then rep=https://build2.org/bpkg/1 repn=build2.org/ else rep=pkg/1/build2.org repn=build2.org/ 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 [ "$cmd" = "cfg-fetch" -o \ "$cmd" = "rep-info" ]; then ops="$ops --auth all" fi if [ -t 0 ]; then $bpkg $cmd $ops $* else $bpkg $cmd $ops $* >$tmp_file diff --strip-trailing-cr -u - $tmp_file 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 [ "$cmd" = "cfg-fetch" -o \ "$cmd" = "rep-info" ]; then ops="$ops --auth all" 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 # Repository certificate fingerprint. # function rep_cert_fp () { cat $1/repositories | \ sed -n '/^-----BEGIN CERTIFICATE-----$/,/^-----END CERTIFICATE-----$/p' | \ openssl x509 -sha256 -noout -fingerprint | \ sed -n 's/^SHA256 Fingerprint=\(.*\)$/\1/p' } # Edit file with sed. # function edit () { local path=$1; shift sed "$@" $path > $path.bak mv $path.bak $path } # Repository absolute location from a relative path. # function location () { if [ "$remote" = "y" ]; then echo "$rep/$1" elif [ "$msys" = "y" ]; then # Convert Windows path like c:/abc/xyz to the c:\abc\xyz canonical form. # echo "`pwd -W`/$rep/$1" | sed 's%/%\\%g' else echo "`pwd`/$rep/$1" fi } ## ## Low-level commands. ## ## ## pkg-verify ## fail pkg-verify # archive expected fail pkg-verify ./no-such-file # archive does not exist fail pkg-verify pkg/1/build2.org/common/not-a-package.tar.gz fail pkg-verify --silent pkg/1/build2.org/common/not-a-package.tar.gz test pkg-verify pkg/1/build2.org/common/hello/libhello-1.0.0+1.tar.gz ## ## rep-create ## fail rep-create # no 'repositories' file fail rep-create pkg/1/build2.org/satisfy # unexpected files test rep-create pkg/1/build2.org/common/hello --key key.pem test rep-create pkg/1/build2.org/common/foo/stable test rep-create pkg/1/build2.org/common/foo/testing test rep-create pkg/1/build2.org/common/bar/stable test rep-create pkg/1/build2.org/common/bar/testing test rep-create pkg/1/build2.org/common/bar/unstable ## ## rep-info ## fail rep-info # repository location expected test rep-info --trust-yes $rep/common/foo/testing <= 1.1.0 location: libbar-1.1.1.tar.gz sha256sum: d09700602ff78ae405b6d4850e34660e939d27676e015a23b549884497c8bb45 EOF hello_fp=`rep_cert_fp pkg/1/build2.org/common/hello` test rep-info -m -p --trust $hello_fp $rep/common/hello <= 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 pkg/1/build2.org/status/stable test rep-create pkg/1/build2.org/status/extra test rep-create pkg/1/build2.org/status/testing test rep-create pkg/1/build2.org/status/unstable # basics # test cfg-create --wipe stat libfoo/1.0.0 "unknown" stat libfoo "unknown" test cfg-add $rep/status/stable test cfg-fetch --trust-yes 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 cfg-add $rep/status/extra test cfg-fetch --trust-yes stat libbar "available 1.1.0+1" test cfg-add $rep/status/stable test cfg-fetch --trust-yes stat libbar "available 1.1.0+1 1.0.0" test cfg-create --wipe test cfg-add $rep/status/testing test cfg-fetch --trust-yes stat libbar "available 1.1.0 1.0.0+1 1.0.0" test cfg-create --wipe test cfg-add $rep/status/unstable test cfg-fetch --trust-yes 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 cfg-add $rep/common/hello test cfg-fetch --trust $hello_fp fail pkg-update # package name expected fail pkg-update libhello # no such package test pkg-fetch libhello/1.0.0+1 fail pkg-update libhello # wrong package state test pkg-purge libhello # src == out # test pkg-fetch libhello/1.0.0+1 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 pkg/1/build2.org/common/libhello-1.0.0+1 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 cfg-add $rep/common/hello test cfg-fetch --trust $hello_fp fail pkg-clean # package name expected fail pkg-clean libhello # no such package test pkg-fetch libhello/1.0.0+1 fail pkg-clean libhello # wrong package state test pkg-purge libhello # src == out # test pkg-fetch libhello/1.0.0+1 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 pkg/1/build2.org/common/libhello-1.0.0+1 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 cfg-add $rep/common/hello test cfg-fetch --trust $hello_fp test pkg-fetch libhello/1.0.0+1 test pkg-unpack libhello test pkg-configure libhello test pkg-update libhello test pkg-clean libhello test pkg-disfigure libhello test pkg-purge libhello ## ## pkg-build ## # 1 (libfoo) # test rep-create pkg/1/build2.org/satisfy/t1 test cfg-create --wipe fail pkg-build -p # package name expected fail pkg-build -p libfoo # unknown package fail pkg-build -p libfoo/1.0.0 # unknown package test pkg-build -p pkg/1/build2.org/satisfy/libfoo-1.1.0.tar.gz <= 1.1.0) # test rep-create pkg/1/build2.org/satisfy/t4a test rep-create pkg/1/build2.org/satisfy/t4b test rep-create pkg/1/build2.org/satisfy/t4c test rep-create pkg/1/build2.org/satisfy/t4d test cfg-create --wipe test cfg-add $rep/satisfy/t4c test cfg-fetch --trust-yes test pkg-build -p libbaz <> pkg/1/build2.org/auth/signature-mismatch/signature << EOF signature: \\ XBjnmXXVHY0RqMI0gL/P4t/vuWwK9JJkLl4Qf2gMxq5k2WQ2CIE56DfG0RaGklgKcI3UxsQZvMQI 5PNtAHJDjteQ+BqY0io8A43KPX+2LKMU+I825sKmPRjCLYleGM3mNndDkWfYtAzYk5AmR2piqRz0 D7CLq9GIoQQZO4Fw44muaQDMCRcXy8Txx2jDnretQjx/C0ZQw4M/cd6/cKEKUmLITDkBig9oVlSh tpxHqWz5NTbO3vm8ILc03AwiOJHwZweLb6ocJ6a467IJa+F/xUm9B09k8wFWMs+jHXXzHDE0syv7 lqWL7SvHSjVFrGVFKS6nx7lCj2b8XFiGlwWIwjY4m/VK/5QmbL/lC4f+ww5XT5NG5iYh/eMaCxCJ zTg5iZsWNLhrx9uKNrL5xC4z0OONRVOwzu7gsqr0GLWewPyhH0AqJLgOSkw9N7FJwbv2IKNZ88YA u2YMXNkXytcQvENLVQDX5oxvUMEurUJFOCuYB/SEnpcwkV5h9RtXzIFVy4OCTU2MhQHDEldI8s7w Hga/ct4WupgE228gGdgwJLCbHx6AWBlS9iL10AdS8JkQ9LaZwTMHHz44f8y00X4MiT06gpgDeoQD rUyP0KNG65tdWnVTMqg6Q/YXhtRZLHoD6+QbiYLlruR1phu4y4fDt7AKxoXfeme/a86A37UogZY= \\ EOF # cfg-fetch # signed_fp=`rep_cert_fp pkg/1/build2.org/auth/signed` test cfg-create --wipe test cfg-add $rep/auth/signed test cfg-fetch --trust $signed_fp test cfg-fetch test cfg-create --wipe test cfg-add $rep/auth/signed test cfg-fetch --trust-no --trust $signed_fp test cfg-fetch test cfg-fetch --trust-no # certificate is already trusted test cfg-create --wipe test cfg-add $rep/auth/signed test cfg-fetch --trust-yes test cfg-fetch test cfg-create --wipe test cfg-add $rep/auth/signed fail cfg-fetch --trust-no test cfg-create --wipe test cfg-add $rep/auth/signed fail cfg-fetch --trust-yes --trust-no # inconsistent options test cfg-create --wipe test cfg-add $rep/auth/unsigned1 test cfg-fetch --trust-yes test cfg-fetch test cfg-add $rep/auth/unsigned2 test cfg-fetch test cfg-fetch --trust-no # certificates are already trusted test cfg-create --wipe test cfg-add $rep/auth/unsigned1 fail cfg-fetch --trust-no test cfg-create --wipe test cfg-add $rep/auth/name-mismatch fail cfg-fetch --trust-yes # certificate name mismatch test cfg-create --wipe test cfg-add $rep/auth/expired fail cfg-fetch --trust-yes # certificate expired test cfg-create --wipe test cfg-add $rep/auth/sha256sum-mismatch fail cfg-fetch --trust-yes # packages file checksum mismatch test cfg-create --wipe test cfg-add $rep/auth/signature-mismatch fail cfg-fetch --trust-yes # packages file signature:mismatch # rep-info # test cfg-create --wipe test rep-info --trust-no --trust $signed_fp -d $cfg $rep/auth/signed <