forked from hyperledger/fabric-private-chaincode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_utils.sh
85 lines (72 loc) · 1.65 KB
/
common_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
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
# Copyright 2020 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
if [[ -z "$TERM" ]] || [[ "$TERM" == 'dumb' ]]; then
# to avoid 'tput: No value for $TERM and no -T specified' errors ..
cred=
cgrn=
cblu=
cmag=
cwht=
cbld=
bred=
bgrn=
bblu=
bwht=
crst=
else
cred=$(tput setaf 1)
cgrn=$(tput setaf 2)
cblu=$(tput setaf 4)
cmag=$(tput setaf 5)
cwht=$(tput setaf 7)
cbld=$(tput bold)
bred=$(tput setab 1)
bgrn=$(tput setab 2)
bblu=$(tput setab 4)
bwht=$(tput setab 7)
crst=$(tput sgr0)
fi
function recho () {
echo "${cbld}${cred}"$@"${crst}" >&2
}
function becho () {
echo "${cbld}${cblu}"$@"${crst}" >&2
}
function gecho () {
echo "${cbld}${cgrn}"$@"${crst}" >&2
}
# Common reporting functions: say, yell & die
#-----------------------------------------
# they all write to stderr. if you want normal progres for stdout, just use echo
function say () {
echo "$(basename $0): $*" >&2;
}
function yell () {
becho "$(basename $0): $*" >&2;
}
function die() {
recho "$(basename $0): $*" >&2
exit 111
}
function para() {
echo -e "\n"
}
# Common functions to run commands
#-----------------------------------------
try() {
"$@" || die "test failed: $*"
}
try_fail() {
recho "failure expected next"
(! "$@") || die "rev-test failed: $*"
}
# Variant of try which stores commands stdout and stderr (or only stdout) in variable RESPONSE
try_r() {
say "$@"
export RESPONSE=$("$@" 2>&1) RESPONSE_TYPE="out+err" || die "test failed: $*"
}
try_out_r() {
say "$@"
export RESPONSE=$("$@") RESPONSE_TYPE="out" || die "test failed: $*"
}