#!/usr/bin/env zsh setopt err_exit trap "print -P '\n%N:%i: %B%F{red}Test faild!%F{default}%b'" ZERR function stringcmp { diff -u <(echo $1) <(echo $2) } test_pdir=$(mktemp -dt pkgdir.XXXXXX) test_proot=$(mktemp -dt pkgroot.XXXXXX) test_home=$(mktemp -dt pkghome.XXXXXX) cat << meow test directories: PDIR = $test_pdir PKG_ROOT = $test_proot HOME = $test_home meow echo "# setting up PKG_ROOT" cd $test_proot git clone ${1-git://git.tabularazor.org/~derf/pkg} core cp core/include/pkglist pkglist for repo in ra rb rc; ( mkdir $repo cd $repo git init touch foo mkdir bin touch bin/$repo chmod 755 bin/$repo git add . git commit -m 'initial commit' ) echo "# bootstrapping PDIR" cd $test_home export HOME=$test_home $test_proot/core/include/bootstrap $test_proot $test_pdir echo "# checking for success" [[ -e $test_home/.pkg.conf ]] [[ -d $test_proot/core ]] [[ -d $test_pdir/core ]] [[ -L $test_home/bin/pkg ]] [[ -L $test_home/bin/checklinks ]] [[ -x $(readlink $test_home/bin/pkg) ]] [[ -x $(readlink $test_home/bin/checklinks) ]] echo "# pkg list local" stringcmp "core" "$(pkg list)" stringcmp "core" "$(pkg list local)" echo "# pkg list not-installed" stringcmp "ra\nrb\nrc" "$(pkg list not-installed)" echo "# pkg list all" stringcmp "core\nra\nrb\nrc" "$(pkg list all)" echo "# pkg add (no such repo)" ! pkg add weltfrieden echo "# pkg add (already installed)" ! pkg add core echo "# pkg add (ok)" pkg add ra [[ -e $test_pdir/ra/foo ]] [[ -d $test_pdir/ra/.git ]] echo "# pkg add (already installed)" ! pkg add ra echo "# populate_collected (~/bin)" [[ -L $test_home/bin/ra ]] [[ -x $(readlink $test_home/bin/ra) ]] repeat 2 { echo "# pkg list" stringcmp "core\nra" "$(pkg list local)" stringcmp "rb\nrc" "$(pkg list not-installed)" stringcmp "core\nra\nrb\nrc" "$(pkg list remote)" pkg update } echo "# pkg remove (not installed/nonexistent)" ! pkg remove suckage ! pkg remove rb echo "# pkg remove (ok)" pkg remove ra echo "# genocide_collected (~/bin)" [[ ! -L $test_home/bin/ra ]] repeat 2 { echo "# pkg list" stringcmp "core" "$(pkg list local)" stringcmp "ra\nrb\nrc" "$(pkg list not-installed)" stringcmp "core\nra\nrb\nrc" "$(pkg list remote)" pkg update } rm -rf $test_pdir $test_proot $test_home print -P '%F{green} test passed%F{default}'