blob: 69f19b7daee07cf2c1665a005e6c6f174b304523 [file] [log] [blame]
Sean Dague53753292014-12-04 19:38:15 -05001#!/usr/bin/env bash
2
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15# we always start with no errors
16ERROR=0
Ian Wienand1cb809d2015-04-17 12:55:38 +100017PASS=0
Sean Dague53753292014-12-04 19:38:15 -050018FAILED_FUNCS=""
19
Ian Wienand1cb809d2015-04-17 12:55:38 +100020function passed {
21 local lineno=$(caller 0 | awk '{print $1}')
22 local function=$(caller 0 | awk '{print $2}')
23 local msg="$1"
24 if [ -z "$msg" ]; then
25 msg="OK"
26 fi
27 PASS=$((PASS+1))
28 echo $function:L$lineno $msg
29}
30
31function failed {
32 local lineno=$(caller 0 | awk '{print $1}')
33 local function=$(caller 0 | awk '{print $2}')
34 local msg="$1"
35 FAILED_FUNCS+="$function:L$lineno\n"
36 echo "ERROR: $function:L$lineno!"
37 echo " $msg"
38 ERROR=$((ERROR+1))
39}
40
Sean Dague53753292014-12-04 19:38:15 -050041function assert_equal {
42 local lineno=`caller 0 | awk '{print $1}'`
43 local function=`caller 0 | awk '{print $2}'`
44 local msg=$3
45 if [[ "$1" != "$2" ]]; then
46 FAILED_FUNCS+="$function:L$lineno\n"
47 echo "ERROR: $1 != $2 in $function:L$lineno!"
48 echo " $msg"
Ian Wienand1cb809d2015-04-17 12:55:38 +100049 ERROR=$((ERROR+1))
Sean Dague53753292014-12-04 19:38:15 -050050 else
Ian Wienand1cb809d2015-04-17 12:55:38 +100051 PASS=$((PASS+1))
Sean Dague53753292014-12-04 19:38:15 -050052 echo "$function:L$lineno - ok"
53 fi
54}
55
56function report_results {
Ian Wienand1cb809d2015-04-17 12:55:38 +100057 echo "$PASS Tests PASSED"
58 if [[ $ERROR -gt 1 ]]; then
59 echo
60 echo "The following $ERROR tests FAILED"
61 echo -e "$FAILED_FUNCS"
62 echo "---"
Sean Dague53753292014-12-04 19:38:15 -050063 exit 1
64 fi
65}