1*1285115cSWilliam A. Kennington III# Copyright 2021 Google LLC
2*1285115cSWilliam A. Kennington III#
3*1285115cSWilliam A. Kennington III# Licensed under the Apache License, Version 2.0 (the "License");
4*1285115cSWilliam A. Kennington III# you may not use this file except in compliance with the License.
5*1285115cSWilliam A. Kennington III# You may obtain a copy of the License at
6*1285115cSWilliam A. Kennington III#
7*1285115cSWilliam A. Kennington III#      http://www.apache.org/licenses/LICENSE-2.0
8*1285115cSWilliam A. Kennington III#
9*1285115cSWilliam A. Kennington III# Unless required by applicable law or agreed to in writing, software
10*1285115cSWilliam A. Kennington III# distributed under the License is distributed on an "AS IS" BASIS,
11*1285115cSWilliam A. Kennington III# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*1285115cSWilliam A. Kennington III# See the License for the specific language governing permissions and
13*1285115cSWilliam A. Kennington III# limitations under the License.
14*1285115cSWilliam A. Kennington III
15*1285115cSWilliam A. Kennington III# Compares two strings and prints out an error message if they are not equal
16*1285115cSWilliam A. Kennington IIIStrEq() {
17*1285115cSWilliam A. Kennington III  if [ "$1" != "$2" ]; then
18*1285115cSWilliam A. Kennington III    echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} Mismatched strings" >&2
19*1285115cSWilliam A. Kennington III    echo "  Expected: $2" >&2
20*1285115cSWilliam A. Kennington III    echo "  Got:      $1" >&2
21*1285115cSWilliam A. Kennington III    exit 1
22*1285115cSWilliam A. Kennington III  fi
23*1285115cSWilliam A. Kennington III}
24*1285115cSWilliam A. Kennington III
25*1285115cSWilliam A. Kennington IIITESTS=()
26*1285115cSWilliam A. Kennington III
27*1285115cSWilliam A. Kennington III# Runs tests and emits output specified by the Test Anything Protocol
28*1285115cSWilliam A. Kennington III# https://testanything.org/
29*1285115cSWilliam A. Kennington IIITestAnythingMain() {
30*1285115cSWilliam A. Kennington III  set -o nounset
31*1285115cSWilliam A. Kennington III  set -o errexit
32*1285115cSWilliam A. Kennington III  set -o pipefail
33*1285115cSWilliam A. Kennington III
34*1285115cSWilliam A. Kennington III  echo "TAP version 13"
35*1285115cSWilliam A. Kennington III  echo "1..${#TESTS[@]}"
36*1285115cSWilliam A. Kennington III
37*1285115cSWilliam A. Kennington III  local i
38*1285115cSWilliam A. Kennington III  for ((i=0; i <${#TESTS[@]}; ++i)); do
39*1285115cSWilliam A. Kennington III    local t="${TESTS[i]}"
40*1285115cSWilliam A. Kennington III    local tap_i=$((i + 1))
41*1285115cSWilliam A. Kennington III    if ! "$t"; then
42*1285115cSWilliam A. Kennington III      printf "not "
43*1285115cSWilliam A. Kennington III    fi
44*1285115cSWilliam A. Kennington III    printf "ok %d - %s\n" "$tap_i" "$t"
45*1285115cSWilliam A. Kennington III  done
46*1285115cSWilliam A. Kennington III}
47