-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·118 lines (84 loc) · 2.66 KB
/
test.sh
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
# strict mode
set -o errexit -o pipefail -o noclobber -o nounset
IFS=$'\n\t'
function error() { echo "$(tput setaf 1)$*$(tput sgr0)" >&2 && exit 1; }
function log() { echo "$(tput setaf 6)$*$(tput sgr0)"; }
# tap header
export ntap=1
export tap_total=21
echo "1..$tap_total"
# tap tests
function tap() {
[[ $? -eq 0 ]] || echo -n "not "
local description=$1 && shift
echo "ok $ntap $(tput setaf 4)$description$(tput sgr0)"
((ntap += 1))
}
export output
export code
function smash() {
output=$(bash ./smash.sh "$@") && code=$?
# debug
}
function debug() {
echo "$output"
log "==> state" && cat smash/engine/state
log "==> plan" && cat smash/engine/plan
log "==> end"
}
log "start with clean workspace"
rm -rf smash/engine target
[[ "$(wc -l ./smash.sh | awk '{ print $1 }')" -lt 200 ]]
tap "with a script of <200 lines" $?
[[ ! -d target ]]
tap "we start without ./target" $?
log "run ./smash.sh with no args"
smash
[[ $code -eq 0 ]]
tap "script exits with 0" $?
[[ "$(wc -l ./smash/engine/plan | awk '{ print $1 }')" -eq 3 ]]
tap "work was planned" $?
[[ $output =~ "==> run" && $output =~ "run smash/make_target/run" ]]
tap "one run script planned" $?
[[ $output =~ "==> test" && $output =~ "test smash/make_target/test" ]]
tap "one test script planned" $?
[[ $output =~ "! excute work" ]]
tap "work was done" $?
[[ $output =~ "==> done" ]]
tap "smash reports completing successfully" $?=true
[[ $(echo "$output" | wc -l | awk '{ print $1 }') -gt 20 ]]
tap "we log everything to the user" $?
[[ -d target && -f target/version ]]
tap "we now have the artifact ./target/version" $?
log "run ./smash.sh again"
smash
[[ $code -eq 0 ]]
tap "script exits with 0" $?
[[ "$(wc -l ./smash/engine/plan | awk '{ print $1 }')" -eq 1 ]]
tap "no work was planned" $?
[[ ! $output =~ "$ smash/make_target/run" ]]
tap "no work was done" $?
log "clear the workspace and do a dry run"
rm -rf smash/engine target
smash -n
[[ ! -d target ]]
tap "smash did not create ./target" $?
[[ $(echo "$output" | wc -l | awk '{ print $1 }') -gt 10 ]]
tap "we log everything to the user" $?
[[ $output =~ "==> run" && $output =~ "==> run" ]]
tap "both planned steps were dry run" $?
[[ $output =~ "==> done" ]]
tap "smash reports completing successfully" $?
log "run smash plan silently"
smash -s
[[ -d target && -f target/version ]]
tap "we have the artifact ./target/version" $?
[[ $(echo "$output" | wc -l | awk '{ print $1 }') -eq 1 ]]
tap "nothing gets logged to the user" $?
[[ $output =~ "==> done" ]]
tap "except that smash was successfully completed" $?
log "clean all test artifacts"
rm -rf smash/engine target
[[ $ntap -eq $tap_total ]]
tap "ran expected number of tests in ./test.sh" $?