-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.bats
More file actions
83 lines (73 loc) · 1.44 KB
/
test.bats
File metadata and controls
83 lines (73 loc) · 1.44 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
#!/usr/bin/env bats
export SYSTEM_NAME="$(uname -s | tr '[:upper:]' '[:lower:]')"
@test "[add] default" {
run make test
echo "output: $output"
echo "status: $status"
assert_success
}
flunk() {
{
if [[ "$#" -eq 0 ]]; then
cat -
else
echo "$*"
fi
}
return 1
}
assert_equal() {
if [[ "$1" != "$2" ]]; then
{
echo "expected: $1"
echo "actual: $2"
} | flunk
fi
}
assert_exit_status() {
exit_status="$1"
if [[ "$status" -ne "$exit_status" ]]; then
{
echo "expected exit status: $exit_status"
echo "actual exit status: $status"
} | flunk
flunk
fi
}
assert_failure() {
if [[ "$status" -eq 0 ]]; then
flunk "expected failed exit status"
elif [[ "$#" -gt 0 ]]; then
assert_output "$1"
fi
}
assert_success() {
if [[ "$status" -ne 0 ]]; then
flunk "command failed with exit status $status"
elif [[ "$#" -gt 0 ]]; then
assert_output "$1"
fi
}
assert_output() {
local expected
if [[ $# -eq 0 ]]; then
expected="$(cat -)"
else
expected="$1"
fi
assert_equal "$expected" "$output"
}
assert_output_contains() {
local input="$output"
local expected="$1"
local count="${2:-1}"
local found=0
until [ "${input/$expected/}" = "$input" ]; do
input="${input/$expected/}"
found=$((found + 1))
done
assert_equal "$count" "$found"
}
assert_output_not_exists() {
[[ -z "$output" ]] || flunk "expected no output, found some"
}