Basic setup for tests

Based on the test setup of stub.sh: https://github.com/jimeh/stub.sh
This commit is contained in:
2014-05-24 11:01:23 +01:00
parent 2aa549ff70
commit 1bf087faa3
5 changed files with 85 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
test/assert.sh
test/stub.sh

4
.travis.yml Normal file
View File

@@ -0,0 +1,4 @@
language: bash
script: make test
before_install:
- sudo apt-get install bc

37
Makefile Normal file
View File

@@ -0,0 +1,37 @@
test: prepare
./test.sh
prepare: test/assert.sh test/stub.sh
test/assert.sh:
test -f "test/assert.sh" || ( \
echo "fetching test/assert.sh..." && \
curl -s -L -o test/assert.sh \
https://raw.github.com/lehmannro/assert.sh/v1.0.2/assert.sh \
)
update-assert.sh: remove-assert.sh test/assert.sh
remove-assert.sh:
test -f "test/assert.sh" && \
rm "test/assert.sh" && \
echo "removed test/assert.sh"
test/stub.sh:
test -f "test/stub.sh" || ( \
echo "fetching test/stub.sh..." && \
curl -s -L -o test/stub.sh \
https://raw.github.com/jimeh/stub.sh/v0.3.0/stub.sh \
)
update-stub.sh: remove-stub.sh test/stub.sh
remove-stub.sh:
test -f "test/stub.sh" && \
rm "test/stub.sh" && \
echo "removed test/stub.sh"
.SILENT:
.PHONY: test prepare \
test/assert.sh update-assert.sh remove-assert.sh \
test/stub.sh update-stub.sh remove-stub.sh

34
test.sh Executable file
View File

@@ -0,0 +1,34 @@
#! /usr/bin/env bash
resolve_link() {
$(type -p greadlink readlink | head -1) $1
}
abs_dirname() {
local cwd="$(pwd)"
local path="$1"
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done
pwd
cd "$cwd"
}
testdir="$(abs_dirname "$0")/test"
testfiles="$(find "$testdir" -name "*-test.sh")"
RET=0
for testfile in $testfiles; do
echo ""
echo "running: ${testfile/#$(dirname "$testdir")\//}"
cd "$(dirname "$testfile")"
"$testfile"
if [ "$?" != "0" ]; then RET=1; fi
done
echo ""
exit $RET

8
test/test-helper.sh Normal file
View File

@@ -0,0 +1,8 @@
[ -n "$TEST_DEBUG" ] && set -x
# Set testroot variable.
testroot="$(dirname "$BASH_SOURCE")"
# Include assert.sh and stub.sh libraries.
source "${testroot}/assert.sh"
source "${testroot}/stub.sh"