forked from BobBuildTool/bob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-lib.sh
118 lines (98 loc) · 1.95 KB
/
test-lib.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# This file holds common test functions and is sourced by run-tests.sh or the
# black box tests directly. It is not intended to be executed directly.
# Check if already sourced
if [[ "$(type -t run_bob)" == function ]] ; then
return
fi
if [[ -d "pym/bob" ]] ; then
BOB_ROOT="${PWD}"
elif [[ -d "../../pym/bob" ]] ; then
BOB_ROOT="${PWD}/../.."
else
echo "From where are you calling me?" >&2
exit 1
fi
export PYTHONPATH="${BOB_ROOT}/pym"
set -o errtrace
trap 'err=$?; echo "ERROR: Command ${BASH_COMMAND} failed with code $err" >&2; exit $err' ERR
cleanup()
{
rm -rf work dev .bob-*
}
# Run bob in testing environment. Adds the "package calculation check" (pkgck)
# and "no global defaults" debug switches.
run_bob()
{
${RUN_PYTHON3} "$BOB_ROOT/bob" --debug=pkgck,ngd "$@"
}
# Run bob only with the "no global defaults" debug switch. Used for black box
# regression tests of the package calculation algorithm.
run_bob_plain()
{
${RUN_PYTHON3} "$BOB_ROOT/bob" --debug=ngd "$@"
}
exec_blackbox_test()
{
cleanup
run_bob dev root
RES=$(run_bob query-path -f '{dist}' --develop root)
diff -Nurp $RES output
run_bob build root
RES=$(run_bob query-path -f '{dist}' --release root)
diff -Nurp $RES output
run_bob clean
}
expect_fail()
{
"$@" 2>&1 || if [[ $? -ne 1 ]] ; then
echo "Unexpected return code: $*" >&2
return 1
else
return 0
fi
echo "Expected command to fail: $*" >&2
return 1
}
expect_output()
{
local EXP="$1"
local RES="$( "${@:2}" )"
if [[ "$RES" != "$EXP" ]] ; then
echo "Unexpected output: '$RES'" >&2
echo "Expected: '$EXP'" >&2
echo "Command: ${@:2}" >&2
return 1
fi
return 0
}
expect_exist()
{
local i
for i in "$@" ; do
if [[ ! -e "$i" ]] ; then
echo "Missing expected file: $i" >&2
return 1
fi
done
return 0
}
expect_not_exist()
{
local i
for i in "$@" ; do
if [[ -e "$i" ]] ; then
echo "Unexpected file: $i" >&2
return 1
fi
done
return 0
}
skip()
{
exit 240
}
die()
{
echo "$@"
exit 1
}