summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-10-14 08:55:36 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-10-14 08:55:36 +0200
commite9a22d5165c2dda5a0e10506977081222549a8eb (patch)
tree995e471a537719ecd950dfdccb8043836ab406ce
parenta7a62352c46b5d2b37baaa09f8145b1171ca79fb (diff)
downloadapp.sh-e9a22d5165c2dda5a0e10506977081222549a8eb.tar.gz
app.sh-e9a22d5165c2dda5a0e10506977081222549a8eb.tar.bz2
app.sh-e9a22d5165c2dda5a0e10506977081222549a8eb.tar.xz
app.sh-e9a22d5165c2dda5a0e10506977081222549a8eb.zip
o Making sure ./app can be symlinked to an installation.
o More tests.
-rwxr-xr-xapp22
-rw-r--r--docs/README.md5
-rwxr-xr-x[-rw-r--r--]test/01-help.bats30
-rwxr-xr-xtest/02-app-help.bats38
-rw-r--r--test/utils.bash24
5 files changed, 92 insertions, 27 deletions
diff --git a/app b/app
index dc70ab0..0c4cbd1 100755
--- a/app
+++ b/app
@@ -2,6 +2,20 @@
set -e
+PRG="$0"
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG="`dirname "$PRG"`/$link"
+ fi
+done
+
+APPSH_HOME=`dirname "$PRG"`
+APPSH_HOME=`cd "$APPSH_HOME" && pwd`
+
if [ -z "$BASEDIR" ]
then
BASEDIR=`dirname $0`
@@ -28,10 +42,10 @@ method_usage() {
echo "Run $0 -h <group> for more help" >&2
}
-. $BASEDIR/.app/lib/app-common
-. $BASEDIR/.app/lib/app-app
-. $BASEDIR/.app/lib/app-conf
-. $BASEDIR/.app/lib/app-operate
+. $APPSH_HOME/.app/lib/app-common
+. $APPSH_HOME/.app/lib/app-app
+. $APPSH_HOME/.app/lib/app-conf
+. $APPSH_HOME/.app/lib/app-operate
main() {
local method
diff --git a/docs/README.md b/docs/README.md
index 8845059..f818faf 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -97,3 +97,8 @@ Method Contract
* `APPSH_INSTANCE`
* `APPSH_METHOD`
+Unclassified:
+
+* `APPSH_HOME`
+* `BASEDIR`
+
diff --git a/test/01-help.bats b/test/01-help.bats
index 7d38592..8bd4fd7 100644..100755
--- a/test/01-help.bats
+++ b/test/01-help.bats
@@ -1,33 +1,17 @@
-#!/bin/bash
+#!/usr/bin/env bats
+# vim: set filetype=sh :
-workdir=test-run
-
-# TODO: assert that the exit code is 1 for 'usage' outputs.
-exit_usage=0
-
-setup() {
- rm -rf $workdir
-}
-
-echo_lines() {
- for line in "${lines[@]}"; do echo $line; done
-}
+load utils
@test "./app" {
- run ./app; echo_lines
- [ $status -eq $exit_usage ]
+ app; echo_lines
+ [ $status -eq $exit_usage_wrong ]
[ $(expr "${lines[0]}" : "usage: ./app .*") -ne 0 ]
}
@test "./app foo" {
- run ./app foo; echo_lines
- [ $status -eq $exit_usage ]
+ app foo; echo_lines
+ [ $status -eq $exit_usage_wrong ]
[ "${lines[0]}" = "Error: No such method group: foo" ]
[ $(expr "${lines[1]}" : "usage: ./app .*") -ne 0 ]
}
-
-@test "./app app" {
- run ./app app; echo_lines
- [ $status -eq $exit_usage ]
- [ $(expr "${lines[0]}" : "usage: ./app app .*") -ne 0 ]
-}
diff --git a/test/02-app-help.bats b/test/02-app-help.bats
new file mode 100755
index 0000000..460762f
--- /dev/null
+++ b/test/02-app-help.bats
@@ -0,0 +1,38 @@
+#!/usr/bin/env bats
+# vim: set filetype=sh :
+
+load utils
+
+@test "./app app" {
+ app app; echo_lines
+ [ $status -eq $exit_usage_wrong ]
+ [ $(expr "${lines[0]}" : "usage: ./app app .*") -ne 0 ]
+ [ ${#lines[*]} == 6 ]
+}
+
+@test "./app app install" {
+ app app install; echo_lines
+ [ $status -eq $exit_usage ]
+ [ $(expr "${lines[0]}" : "usage: install .*") -ne 0 ]
+ [ ${#lines[*]} == 6 ]
+}
+
+@test "./app app list" {
+ app app list; echo_lines
+ [ $status -eq 0 ]
+ [ ${#lines[*]} == 0 ]
+}
+
+@test "./app app list-versions" {
+ app app list-versions; echo_lines
+ [ $status -eq $exit_usage ]
+ [ $(expr "${lines[0]}" : "usage: list-versions .*") -ne 0 ]
+ [ ${#lines[*]} == 2 ]
+}
+
+@test "./app app set-current" {
+ app app "set-current"; echo_lines
+ [ $status -eq $exit_usage ]
+ [ $(expr "${lines[0]}" : "usage: set-current .*") -ne 0 ]
+ [ ${#lines[*]} == 1 ]
+}
diff --git a/test/utils.bash b/test/utils.bash
new file mode 100644
index 0000000..eacabe8
--- /dev/null
+++ b/test/utils.bash
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+workdir=test-run
+
+# TODO: assert that the exit code is 1 for 'usage' outputs.
+exit_usage=1
+exit_usage_wrong=0
+
+echo_lines() {
+ for line in "${lines[@]}"; do echo $line; done
+}
+
+APPSH=$(pwd)/app
+
+setup() {
+ rm -rf $BATS_TMPDIR/app.sh
+ mkdir $BATS_TMPDIR/app.sh
+ cd $BATS_TMPDIR/app.sh
+ ln -s $APPSH
+}
+
+app() {
+ run ./app "$@"
+}