/
test_helper
38 lines (30 loc) · 913 Bytes
/
test_helper
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
orig_cwd="$PWD"
#
# Test helpers
#-----------------------------------------------------------------------------
# Strip color codes from a string
strip_colors() {
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
}
# Print space separated tab completion options
tab_completions(){ echo "${COMPREPLY[@]}"; }
# Silence git commands
silentGitCommands() {
git() { /usr/bin/env git "$@" > /dev/null 2>&1; }
}
# Cancel silent git commands
verboseGitCommands() {
unset -f git
}
# Asserts
#-----------------------------------------------------------------------------
# assert $1 contains $2
assertIncludes() {
result=1; if echo "$1" | grep -Pq "$2"; then result=0; fi
assertTrue "'$1' should have contained '$2'" $result
}
# assert $1 does not contain $2
assertNotIncludes() {
result=1; if echo "$1" | grep -Pq "$2"; then result=0; fi
assertFalse "'$1' should not have contained '$2'" $result
}