mirror of
https://github.com/jimeh/stub.sh.git
synced 2026-02-19 13:46:40 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| de104f7cd5 | |||
| 58e1b8dfa7 | |||
| e8388b911b | |||
| d9e3e14c76 | |||
|
|
f46506d00e | ||
|
|
59a69b883f | ||
| 1f6dc46f3f | |||
| 332cfb8d28 | |||
| f3e0f666cb | |||
| 47ce28bba6 | |||
| 6e8e9fcfcf | |||
|
|
0ea845751e | ||
| 3b02e60207 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
test/assert.sh
|
||||
test/assert.sh
|
||||
test-runner.sh
|
||||
@@ -1,2 +1,4 @@
|
||||
language: node_js
|
||||
script: INVARIANT=1 make test
|
||||
language: c
|
||||
before_install:
|
||||
- sudo apt-get install bc
|
||||
script: make test
|
||||
|
||||
44
Makefile
44
Makefile
@@ -1,12 +1,38 @@
|
||||
test: prepare
|
||||
./test.sh
|
||||
test: bootstrap
|
||||
./test-runner.sh
|
||||
|
||||
prepare:
|
||||
test -f "test/assert.sh" || ( \
|
||||
echo "fetching assert.sh..." && \
|
||||
curl -s -L -o test/assert.sh \
|
||||
https://raw.github.com/lehmannro/assert.sh/v1.0.2/assert.sh \
|
||||
)
|
||||
bootstrap: test-runner.sh test/assert.sh
|
||||
clean: remove_test-runner.sh remove_assert.sh
|
||||
update: update_test-runner.sh update_assert.sh
|
||||
|
||||
test/assert.sh:
|
||||
echo "fetching assert.sh..." && \
|
||||
curl -s -L -o test/assert.sh \
|
||||
https://raw.github.com/lehmannro/assert.sh/v1.0.2/assert.sh
|
||||
|
||||
remove_assert.sh:
|
||||
( \
|
||||
test -f "test/assert.sh" && rm "test/assert.sh" && \
|
||||
echo "removed test/assert.sh" \
|
||||
) || exit 0
|
||||
|
||||
update_assert.sh: remove_assert.sh test/assert.sh
|
||||
|
||||
test-runner.sh:
|
||||
echo "fetching test-runner.sh..." && \
|
||||
curl -s -L -o test-runner.sh \
|
||||
https://github.com/jimeh/test-runner.sh/raw/master/test-runner.sh && \
|
||||
chmod +x test-runner.sh
|
||||
|
||||
remove_test-runner.sh:
|
||||
( \
|
||||
test -f "test-runner.sh" && rm "test-runner.sh" && \
|
||||
echo "removed test-runner.sh" \
|
||||
) || exit 0
|
||||
|
||||
update_test-runner.sh: remove_test-runner.sh test-runner.sh
|
||||
|
||||
.SILENT:
|
||||
.PHONY: test prepare
|
||||
.PHONY: test bootstrap clean update \
|
||||
remove_test-runner.sh update_test-runner.sh \
|
||||
remove_assert.sh update_assert.sh
|
||||
|
||||
@@ -74,7 +74,7 @@ stub_called_exactly_times uname 2 # returns 0 (success)
|
||||
restore uname
|
||||
```
|
||||
|
||||
Asserting stub has been called with specific attributes:
|
||||
Asserting stub has been called with specific arguments:
|
||||
|
||||
```bash
|
||||
source "stub.sh"
|
||||
@@ -91,7 +91,7 @@ stub_called_with uname -r # returns 0 (success)
|
||||
restore uname
|
||||
```
|
||||
|
||||
Asserting stub has been called X number of times with specific attributes:
|
||||
Asserting stub has been called X number of times with specific arguments:
|
||||
|
||||
```bash
|
||||
source "stub.sh"
|
||||
|
||||
6
stub.sh
6
stub.sh
@@ -1,5 +1,6 @@
|
||||
# !/usr/bin/env bash
|
||||
# stub.sh 1.0.1 - stubbing helpers for simplifying bash script tests.
|
||||
#
|
||||
# stub.sh 1.0.2 - stubbing helpers for simplifying bash script tests.
|
||||
# https://github.com/jimeh/stub.sh
|
||||
#
|
||||
# (The MIT License)
|
||||
@@ -98,7 +99,7 @@ stub_and_eval() {
|
||||
fi
|
||||
|
||||
# Create the stub.
|
||||
eval "$(echo -e "${cmd}() {\n __stub_call \"${cmd}\" \$@\n $2\n}")"
|
||||
eval "$( printf "%s" "${cmd}() { __stub_call \"${cmd}\" \$@; $2;}")"
|
||||
}
|
||||
|
||||
|
||||
@@ -415,5 +416,4 @@ __stub_clean() {
|
||||
eval "unset STUB_${index}_CALLS"
|
||||
STUB_INDEX=(${STUB_INDEX[@]/${cmd}=*/})
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
34
test.sh
34
test.sh
@@ -1,34 +0,0 @@
|
||||
#! /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
|
||||
Reference in New Issue
Block a user