summaryrefslogtreecommitdiff
path: root/test/utils.bash
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-10-22 20:40:50 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2013-10-22 20:40:50 +0200
commit34e60841a44ee688792e87863aa67db469d39fa8 (patch)
treed4ec57728121d87b029d8b729c98494356015061 /test/utils.bash
parent4452df33f080c314f9b4c6a6504f254edc500282 (diff)
downloadappstore-34e60841a44ee688792e87863aa67db469d39fa8.tar.gz
appstore-34e60841a44ee688792e87863aa67db469d39fa8.tar.bz2
appstore-34e60841a44ee688792e87863aa67db469d39fa8.tar.xz
appstore-34e60841a44ee688792e87863aa67db469d39fa8.zip
wip
Diffstat (limited to 'test/utils.bash')
-rw-r--r--test/utils.bash176
1 files changed, 176 insertions, 0 deletions
diff --git a/test/utils.bash b/test/utils.bash
new file mode 100644
index 0000000..cd6fcf0
--- /dev/null
+++ b/test/utils.bash
@@ -0,0 +1,176 @@
+#!/bin/bash
+
+workdir=test-run
+
+# TODO: assert that the exit code is 1 for 'usage' outputs.
+exit_usage=1
+exit_usage_wrong=0
+
+setup() {
+ ORIG_PATH=$PATH
+ APPSTORE_HOME=$(cd $BATS_TEST_DIRNAME/..; echo `pwd`)
+ PATH=/bin:/usr/bin
+ PATH=$PATH:$APPSTORE_HOME
+
+ rm -rf $BATS_TMPDIR/appstore
+ mkdir $BATS_TMPDIR/appstore
+
+ HOME=$BATS_TMPDIR/appstore-home
+
+ cd $BATS_TMPDIR/appstore
+
+ REPO=$BATS_TMPDIR/repo
+ REPO_URL="file://$REPO"
+ FIXED_REPO_URL="file://`fix_path $REPO`"
+
+ if [ "`declare -f setup_inner >/dev/null; echo $?`" = 0 ]
+ then
+ setup_inner
+ fi
+}
+
+echo_lines() {
+ echo lines:
+ for line in "${lines[@]}"; do echo $line; done
+ echo status=$status
+}
+
+mkzip() {
+(
+ cd $BATS_TEST_DIRNAME/data/$1
+ rm -f ../$1.zip
+ zip -qr ../$1.zip *
+)
+}
+
+install_artifact() {
+ local artifactId=${1}; shift
+ local version=${1-1.0-SNAPSHOT}
+ describe -Dfile=`fix_path $APPSTORE_HOME/test/data/$artifactId.zip` -DgeneratePom
+ PATH=$ORIG_PATH mvn deploy:deploy-file -Durl=$FIXED_REPO_URL \
+ -Dfile=`fix_path $APPSTORE_HOME/test/data/$artifactId.zip` -DgeneratePom \
+ -DgroupId=org.example -DartifactId=$artifactId -Dversion=$version -Dpackaging=zip
+}
+
+check_status=yes
+
+app() {
+ echo app $@
+ run $APPSTORE_HOME/app $@
+ echo_lines
+
+ if [ "$check_status" = yes ]
+ then
+ eq '$status' 0
+ fi
+
+ check_status=yes
+}
+
+app_libexec() {
+ local x=`PATH=$APPSTORE_HOME/libexec:/bin:/usr/bin which $1`
+
+ echo libexec/$@
+ shift
+ run "$x" $@
+
+ echo_lines
+
+ if [ "$check_status" = yes ]
+ then
+ eq '$status' 0
+ fi
+
+ check_status=yes
+}
+
+fix_path_uname=`uname -s`
+fix_path() {
+ case $fix_path_uname in
+ CYGWIN_NT*)
+ cygpath -wa $1
+ ;;
+ *)
+ echo $1
+ ;;
+ esac
+}
+
+describe() {
+ echo "# " $@ >&3
+}
+
+can_read() {
+ if [ -r "$1" ]
+ then
+ return 0
+ else
+ echo "Can't read $1"
+ return 1
+ fi
+}
+
+can_not_read() {
+ if [ ! -r "$1" ]
+ then
+ return 0
+ else
+ echo "Can read $1"
+ return 1
+ fi
+}
+
+is_directory() {
+ if [ ! -d "$1" ]
+ then
+ echo "Not a directory: $1" 2>&1
+ return 1
+ fi
+}
+
+eq() {
+ local ex="$1"
+ local e="$2"
+ local a="`eval echo $ex`"
+
+ if [[ $e == $a ]]
+ then
+ return 0
+ fi
+
+ echo "Assertion failed: $ex"
+ echo "Expected: $e"
+ echo "Actual: $a"
+ exit 1
+}
+
+neq() {
+ local ex="$1"
+ local e="$2"
+ local a="`eval echo $ex`"
+
+ if [[ $e != $a ]]
+ then
+ return 0
+ fi
+
+ echo "Not-equal assertion failed: $ex"
+ echo "Expected: $e"
+ echo "Actual: $a"
+ exit 1
+}
+
+match() {
+ local ex="$1"
+ local regex="$2"
+ local a="`eval echo $ex`"
+
+ if [[ $a =~ $regex ]]
+ then
+ return 0
+ fi
+
+ echo "Match failed: $ex =~ $regex"
+ echo "Value: $a"
+ exit 1
+}