forked from codehearts/shpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshpy-shunit2
More file actions
86 lines (66 loc) · 1.54 KB
/
shpy-shunit2
File metadata and controls
86 lines (66 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
assertCallCount() {
if [ $# -lt 2 ] || [ $# -gt 3 ]; then
echo 'Usage: assertCallCount [MESSAGE] SPY COUNT' >&2
return 1
fi
# shellcheck disable=SC2039
local val
if [ $# -eq 2 ]; then
assertEquals "$2" "$(getSpyCallCount "$1")"
else
assertEquals "$1" "$3" "$(getSpyCallCount "$2")"
fi
}
assertCalledWith() {
if [ $# -lt 1 ]; then
echo 'Usage: assertCalledWith SPY [ARG]...' >&2
return 1
fi
# shellcheck disable=SC2039
local val
wasSpyCalledWith "$@"
assertTrue $?
val=$?
examineNextSpyCall "$1"
return $val
}
assertCalledWith_() {
if [ $# -lt 2 ]; then
echo 'Usage: assertCalledWith_ MESSAGE SPY [ARG]...' >&2
return 1
fi
# shellcheck disable=SC2039
local message val
message=$1
shift
wasSpyCalledWith "$@"
assertTrue "$message" $?
val=$?
examineNextSpyCall "$1"
return $val
}
assertCalledOnceWith() {
${_SHUNIT_LINENO_}
if [ $# -lt 1 ]; then
echo 'Usage: assertCalledOnceWith SPY [ARG]...' >&2
return 1
fi
assertCallCount "$1" 1 &&
assertCalledWith "$@"
}
assertCalledOnceWith_() {
if [ $# -lt 2 ]; then
echo 'Usage: assertCalledOnceWith_ MESSAGE SPY [ARG]...' >&2
return 1
fi
assertCallCount "$1" "$2" 1 &&
assertCalledWith_ "$@"
}
assertNeverCalled() {
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
echo 'Usage: assertNeverCalled [MESSAGE] SPY' >&2
return 1
fi
assertCallCount "$@" 0
}