forked from dydra/http-api-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·118 lines (106 loc) · 3.06 KB
/
run.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
#! /bin/bash
# run http api tests :
#
# incorporate the standard function and environment definitions and then run
# a group of test scripts -- either as specified by shell arguments, or
# hard-wired as the default.
#
# environment :
# STORE_URL : host http url
# STORE_ACCOUNT : account name
# STORE_REPOSITORY : individual repository
# STORE_TOKEN : the authentication token
set -e
if [[ "$STATUS_OK" == "" ]] ; then
source ./define.sh
fi
VERBOSE=""
while [[ "$#" > 0 ]] ; do
case "$1" in
-v) VERBOSE=-v; CURL="$CURL -v"; shift;;
*) break ;;
esac
done
STORE_ERRORS="0"
SCRIPT_PATTERN='*.sh'
SCRIPT_ROOT='.'
if [[ "$#" == "0" ]] ; then
echo "test: "`pwd`
SCRIPTS=`find . -mindepth 2 -name "${SCRIPT_PATTERN}"`
elif [[ "$#" == "1" ]] ; then
echo "test: $1"
SCRIPTS=`find $1 -name "${SCRIPT_PATTERN}"`
else
SCRIPTS=$@
fi
## echo $SCRIPTS
## osx lacks truncate
cat /dev/null > failed.txt
# iterate over all '.sh' scripts in the current wd tree, run each, record if it succeeds
# report and total failures.
#
# nb. the outer binding scope includes the loop for the "for in do" form,
# but not the "while read do" due to the pipe
# find ./*/ -name '*.sh*' | while read file; do
# this limits the test complement to the number of arguments the shell permits
# echo "STORE_URL : '${STORE_URL}'"
# echo "STORE_ACCOUNT : '${STORE_ACCOUNT}'"
# echo "STORE_REPOSITORY : '${STORE_REPOSITORY}'"
# echo "CURL : '${CURL}'"
# echo "SPARQL_URL : '${SPARQL_URL}'"
# echo "GRAPH_STORE_URL : '${GRAPH_STORE_URL}'"
EXPECTED_FAILURES=""
UNEXPECTED_FAILURES=""
WD_PREFIX=`pwd`/
set +e # allow failure in order to record it
for script_pathname in $SCRIPTS
do
script_pathname=`echo -n "${script_pathname}" | sed 's.//./.g'`
if [[ "/" == "${script_pathname:0:1}" ]]
then
script_pathname=${script_pathname#$WD_PREFIX}
fi
if [[ "./" == "${script_pathname:0:2}" ]]
then
script_pathname="${script_pathname:2}"
fi
echo -n " ${script_pathname} : ";
script_filename=`basename $script_pathname`
script_directory=`dirname $script_pathname`
script_tag=`basename $script_directory`"/${script_filename}"
egrep -v '^#' known-to-fail.txt | fgrep -q "${script_pathname}"
if [ $? -eq 0 ]
then
EXPECTED=" KNOWN TO FAIL"; EXPECTED_FAILURES="${EXPECTED_FAILURES} ${script_tag}";
ENTRY="${script_pathname} : ${EXPECTED}"
echo "${ENTRY}" >> failed.txt
echo "${EXPECTED}"
else
( cd $script_directory;
bash -e -u $script_filename;
)
if [[ $? == "0" ]]
then
echo " ok"
else
EXPECTED=" FAILED"; UNEXPECTED_FAILURES="${UNEXPECTED_FAILURES} ${script_tag}"
(( STORE_ERRORS = $STORE_ERRORS + 1))
ENTRY="${script_pathname} : ${EXPECTED}"
echo "${ENTRY}" >> failed.txt
echo "${EXPECTED}"
fi
fi
done
if [[ "${STORE_ERRORS}" != "0" ]]
then
echo "${STORE_ERRORS} errors"
if [[ "${UNEXPECTED_FAILURES}" != "" ]]
then
echo "new: ${UNEXPECTED_FAILURES}"
fi
fi
if [[ "${EXPECTED_FAILURES}" != "" ]]
then
echo "expected failures: ${EXPECTED_FAILURES}"
fi
exit ${STORE_ERRORS}