-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_helper.sh
executable file
·67 lines (56 loc) · 1.13 KB
/
test_helper.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
#
# Defines assertions and other functions needed
# to run the tests.
#
flunk () {
echo "[$TEST_CASE:$lineno] $TEST_NAME
$1
" 1>&2
exit 1
}
assert_status_equal () {
expected=$1; actual=$2; lineno=$3
if [ $actual -ne $expected ]
then
flunk "expected exit status $expected but was $actual"
fi
}
assert_output_equal () {
expected=$(cat); actual=$1; lineno=$2
if [ "$actual" != "$expected" ]
then
echo "$expected" > "$0_$2_expected.txt"
echo "$actual" > "$0_$2_actual.txt"
flunk "unequal stdout:
$(diff "$0_$2_expected.txt" "$0_$2_actual.txt")"
rm "$0_$2_expected.txt" "$0_$2_actual.txt"
return 1
fi
}
assert_equal () {
assert_status_equal $1 $? $3 &&
assert_output_equal "$2" $3
}
run_test_case () {
if [ "$TEST_NAME" = "" ]
then
for test_name in $(grep -oE "^ *${NAME:-test_\w+} +\(\)" "$1" | tr -d " ()")
do
if TEST_NAME="$test_name" "$1"
then printf '.'
else printf 'F'
fi
done
else
"$TEST_NAME"
fi
}
#
# RVM-specific helpers
#
initialize_rvm () {
source "$rvm_path/scripts/rvm"
__rvm_cleanse_variables
__rvm_load_rvmrc
__rvm_initialize
}