-
Notifications
You must be signed in to change notification settings - Fork 2
/
build
executable file
·73 lines (60 loc) · 1.3 KB
/
build
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
#!/usr/bin/env bash
# In this script, do whatever you do to build and test your project.
assert() {
if $@; then
printf ' %s %b%s%b\n' '🍻' '\e[1;32m' "$*" '\e[0m'
return 0
fi
printf ' %s %b%s%b\n' '💩' '\e[1;31m' "$*" '\e[0m'
return 1
}
smoke-test() {
printf '%s\n' "${FUNCNAME[0]}"
assert test 1 = 1
}
loads-calculator-test() {
printf '%s\n' "${FUNCNAME[0]}"
source ./calculator
assert test $? = 0
}
adds-operands-test() {
printf '%s\n' "${FUNCNAME[0]}"
source ./calculator
add 40 2
assert test $? = 42
}
subtracts-operands-test() {
printf '%s\n' "${FUNCNAME[0]}"
source ./calculator
subtract 40 2
assert test $? = 38
}
divides-operands-test() {
printf '%s\n' "${FUNCNAME[0]}"
source ./calculator
divide 40 2
assert test $? = 20
}
multiplies-operands-test() {
printf '%s\n' "${FUNCNAME[0]}"
source ./calculator
multiply 40 2
assert test $? = 80
}
# Call all *-test functions.
any_failed=0
for test in $(compgen -A function); do
if [[ "$test" != *-test ]]; then
continue
fi
$test
# Sum up exit codes.
any_failed=$((any_failed + $?))
done
if [[ "$any_failed" -eq 0 ]]; then
printf '\n%s The build was %bsuccessful%b\n' '🍺' '\e[1;32m' '\e[0m'
exit 0
else
printf '\n%s The build has %bfailed%b\n' '💩' '\e[1;31m' '\e[0m'
exit 1
fi