-
Notifications
You must be signed in to change notification settings - Fork 3
/
test-utils.sh
executable file
·58 lines (49 loc) · 1.36 KB
/
test-utils.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
#!/usr/bin/env bash
set -euo pipefail
if [ -z "${SMALLTALK_CI_VM}" ] ; then
echo "Missing SMALLTALK_CI_VM, defaulting to ./pharo"
SMALLTALK_CI_VM=./pharo
fi
if [ -z "${SMALLTALK_CI_IMAGE}" ] ; then
echo "Missing SMALLTALK_CI_IMAGE, defaulting to Pharo.image"
SMALLTALK_CI_IMAGE=Pharo.image
fi
function executeWithArguments() {
rm -rf stdout stderr logs
LAST_ARGUMENTS=$*
"$SMALLTALK_CI_VM" "$SMALLTALK_CI_IMAGE" "$@" > out 2> err || true
[ -f stdout ] && mv stdout out || touch out
[ -f stderr ] && mv stderr err || touch err
}
function assertOutputIncludesMessage() {
local output=$1
local level=$2
local message=$3
if [ "$(grep -c "\[$level\] $message" "$output")" -eq 0 ]; then
echo "Expected std$1 to have: [$level] '$message' when invoked with $LAST_ARGUMENTS"
exit 1
fi
}
function assertInfo() {
assertOutputIncludesMessage out INFO "$1"
}
function assertWarning() {
assertOutputIncludesMessage err WARNING "$1"
}
function assertError() {
assertOutputIncludesMessage err ERROR "$1"
}
function assertOutputIncludesText() {
local text=$1
local output=$2
if [ "$(grep -c "$text" "$output")" -eq 0 ]; then
echo "Expected '$text' when invoked with $LAST_ARGUMENTS"
exit 1
fi
}
function assertStandardOutputIncludesText() {
assertOutputIncludesText "$1" out
}
function assertStandardErrorIncludesText() {
assertOutputIncludesText "$1" err
}