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 16# Compares two strings and prints out an error message if they are not equal 17StrEq() { 18 if [ "$1" != "$2" ]; then 19 echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} Mismatched strings" >&2 20 echo " Expected: $2" >&2 21 echo " Got: $1" >&2 22 exit 1 23 fi 24} 25 26TESTS=() 27 28# Runs tests and emits output specified by the Test Anything Protocol 29# https://testanything.org/ 30TestAnythingMain() { 31 set -o nounset 32 set -o errexit 33 set -o pipefail 34 35 echo "TAP version 13" 36 echo "1..${#TESTS[@]}" 37 38 local i 39 for ((i=0; i <${#TESTS[@]}; ++i)); do 40 local t="${TESTS[i]}" 41 local tap_i=$((i + 1)) 42 if ! "$t"; then 43 printf "not " 44 fi 45 printf "ok %d - %s\n" "$tap_i" "$t" 46 done 47} 48