Sean Dague | 5375329 | 2014-12-04 19:38:15 -0500 | [diff] [blame] | 1 | #!/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 |
| 16 | ERROR=0 |
Ian Wienand | 1cb809d | 2015-04-17 12:55:38 +1000 | [diff] [blame^] | 17 | PASS=0 |
Sean Dague | 5375329 | 2014-12-04 19:38:15 -0500 | [diff] [blame] | 18 | FAILED_FUNCS="" |
| 19 | |
Ian Wienand | 1cb809d | 2015-04-17 12:55:38 +1000 | [diff] [blame^] | 20 | function 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 | |
| 31 | function 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 Dague | 5375329 | 2014-12-04 19:38:15 -0500 | [diff] [blame] | 41 | function 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 Wienand | 1cb809d | 2015-04-17 12:55:38 +1000 | [diff] [blame^] | 49 | ERROR=$((ERROR+1)) |
Sean Dague | 5375329 | 2014-12-04 19:38:15 -0500 | [diff] [blame] | 50 | else |
Ian Wienand | 1cb809d | 2015-04-17 12:55:38 +1000 | [diff] [blame^] | 51 | PASS=$((PASS+1)) |
Sean Dague | 5375329 | 2014-12-04 19:38:15 -0500 | [diff] [blame] | 52 | echo "$function:L$lineno - ok" |
| 53 | fi |
| 54 | } |
| 55 | |
| 56 | function report_results { |
Ian Wienand | 1cb809d | 2015-04-17 12:55:38 +1000 | [diff] [blame^] | 57 | 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 Dague | 5375329 | 2014-12-04 19:38:15 -0500 | [diff] [blame] | 63 | exit 1 |
| 64 | fi |
| 65 | } |