-
Notifications
You must be signed in to change notification settings - Fork 1
/
puppet_spec.sh
80 lines (66 loc) · 1.52 KB
/
puppet_spec.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
#!/bin/bash
#
# 2010-07-21 Jeff McCune <[email protected]>
# Cleaned up this script
EXIT_OK=0
EXIT_FAILURE=10
EXIT_NOT_APPLICABLE=11
# Error on unbound variable access
set -u
# JJM Set the TEST_DIR if it's not already set or passed as ARG 1
: ${TEST_DIR:=${1:-'./spec'}}
print_results() {
echo
cat $FAIL_LOG
echo
echo -n "$TOTAL tests, $FAILURES failures"
if [ "$PENDING" -ne 0 ] ; then
echo -n ", $PENDING pending"
fi
if [ "$SKIPPED" -ne 0 ] ; then
echo -n ", $SKIPPED skipped"
fi
echo
}
trap "print_results; exit" SIGINT
if ! [ -f local_setup.sh ] ; then
echo 'You must create a local_setup.sh so we know where to find puppet.
Example:
'
cat local_setup.example.sh
exit 2
fi
FAILURES=0
TOTAL=0
PENDING=0
SKIPPED=0
FAIL_LOG=/tmp/$$.failures.txt
touch $FAIL_LOG
for SPEC in $(find $TEST_DIR -name '*_spec.sh' | sort) ; do
if ! [ -x $SPEC ] ; then
echo -n p
((PENDING++))
continue
fi
result=$($SPEC 2>&1)
TEST_ERROR=$?
if [ $TEST_ERROR -eq $EXIT_OK ] ; then
echo -n .
else
# JJM Detect if script exited with code $EXIT_NOT_APPLICABLE
if [ $TEST_ERROR -eq $EXIT_NOT_APPLICABLE ] ; then
echo -n '~'
((SKIPPED++))
else
((FAILURES++))
echo "$FAILURES) $SPEC" >> $FAIL_LOG
echo $result >> $FAIL_LOG
echo >> $FAIL_LOG
echo -n F
fi
fi
((TOTAL++))
done
print_results
# JJM Exit with FAILURE status if the number of failures are not zero.
[ $FAILURES -eq 0 ] && exit $EXIT_OK || exit $EXIT_FAILURE