1#!/bin/bash 2# Copyright 2021 Google LLC 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16expect_streq() { 17 local r="${2-$(cat)}" 18 [ "$1" = "$r" ] && return 19 echo " Line ${BASH_LINENO[0]} '$1' != '$r'" >&2 20 test_err=1 21} 22 23expect_numeq() { 24 (( "$1" == "$2" )) && return 25 echo " Line ${BASH_LINENO[0]} '$1' != '$2'" >&2 26 test_err=1 27} 28 29expect_err() { 30 local expected=$1 31 shift 32 local rc=0 33 "$@" || rc="$?" 34 (( rc == expected )) && return 35 echo " Line ${BASH_LINENO[0]} Status '$rc' != '$expected'" >&2 36 test_err=1 37} 38 39fail() { 40 echo " Line ${BASH_LINENO[0]} Fail" >&2 41 test_err=1 42} 43 44main() { 45 local agg_err=0 46 for f in $(declare -F | grep 'declare -f test[A-Z_]' | awk '{print $3}'); do 47 echo "[$f] Running..." >&2 48 local test_err=0 49 if "$f" && (( test_err == 0 )); then 50 echo "[$f] Success" >&2 51 else 52 echo "[$f] Failed ($?)" >&2 53 agg_err=1 54 fi 55 done 56 return $agg_err 57} 58