-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·82 lines (72 loc) · 2.24 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
#!/usr/bin/env bash
baseDir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
specDir="$baseDir/spec"
specSuite="$specDir/suite"
batsDir="$specDir/.bats"
batsBld="$batsDir/local"
batsExec="$batsBld/bin/bats"
# TODO turn this variable on once the tests are passing
# blocked by https://github.com/bats-core/bats-core/issues/509
declare -r is_issue_509_resolved=0
if (( is_issue_509_resolved )); then
declare -r bats_upstream_repo=https://github.com/bats-core/bats-core
else
declare -r bats_upstream_repo=https://github.com/sstephenson/bats.git
fi
# TODO cleanup/rm non-vendored branch of logic once the quick-hack-testing
# ability is no longer needed by issue 509 (see is_issue_509_resolved
# experiment).
declare -r use_vendored_bats=1
if (( use_vendored_bats )); then
if (( is_issue_509_resolved )); then
src_dir="$baseDir/vendor/bats-core"
else
src_dir="$baseDir/vendor/bats"
fi
else
src_dir="$batsDir/src"
fi
# Ensure bats unit testing framework is in place
[ ! -x "$batsExec" ] && {
exec 4>/dev/null
[[ "$@" =~ --tap ]] && safefd=4 || safefd=2
{
echo 'Could not find local bats installation, installing now...' >&$safefd
[ -d "$batsDir" ] && rmdir "$batsDir"
{
[ ! -d "$batsDir" ] || exit 3
if (( use_vendored_bats )); then
echo -e '\tutilizing locally vendored bats at '$src_dir'...' >&$safefd
else
echo -e '\tutilizing fresh upstream code from '$bats_upstream_repo'...' >&$safefd
git clone --quiet "$bats_upstream_repo" "$src_dir" &&
mkdir "$batsBld"
fi
"$src_dir/install.sh" "$batsBld" &&
[ -x "$batsExec" ]
} >&$safefd
[ -d "$batsDir" ] || {
echo 'Failed to automatically install bats test framework' >&2
exit 1
}
} || {
echo 'ERROR: Failed to find or install bats testing framework' >&2
exit 1
}
}
# Default to pointing at spec/suite/ if it doesn't look like there are file
# args intended for bats to read directly
bats_target="$specSuite"
for (( i = 1; i <= $#; ++i ));do
[ -r ${!i} ] && {
unset bats_target
break
}
done
# Execute all bats unit tests
SRCS="$baseDir/src" \
SPEC="$specDir" \
SPEC_SUITE="$specDir" \
SPEC_SUITE="$specDir/suite" \
SPEC_MOCKS="$specDir/mocks" \
"$batsExec" $@ $bats_target