15d074370SPatrick Williams#!/bin/bash
21285115cSWilliam A. Kennington III# Copyright 2021 Google LLC
31285115cSWilliam A. Kennington III#
41285115cSWilliam A. Kennington III# Licensed under the Apache License, Version 2.0 (the "License");
51285115cSWilliam A. Kennington III# you may not use this file except in compliance with the License.
61285115cSWilliam A. Kennington III# You may obtain a copy of the License at
71285115cSWilliam A. Kennington III#
81285115cSWilliam A. Kennington III#      http://www.apache.org/licenses/LICENSE-2.0
91285115cSWilliam A. Kennington III#
101285115cSWilliam A. Kennington III# Unless required by applicable law or agreed to in writing, software
111285115cSWilliam A. Kennington III# distributed under the License is distributed on an "AS IS" BASIS,
121285115cSWilliam A. Kennington III# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131285115cSWilliam A. Kennington III# See the License for the specific language governing permissions and
141285115cSWilliam A. Kennington III# limitations under the License.
151285115cSWilliam A. Kennington III
161285115cSWilliam A. Kennington III# Compares two strings and prints out an error message if they are not equal
17*59486679SPatrick Williamsfunction StrEq() {
181285115cSWilliam A. Kennington III    if [ "$1" != "$2" ]; then
191285115cSWilliam A. Kennington III        echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} Mismatched strings" >&2
201285115cSWilliam A. Kennington III        echo "  Expected: $2" >&2
211285115cSWilliam A. Kennington III        echo "  Got:      $1" >&2
221285115cSWilliam A. Kennington III        exit 1
231285115cSWilliam A. Kennington III    fi
241285115cSWilliam A. Kennington III}
251285115cSWilliam A. Kennington III
261285115cSWilliam A. Kennington IIITESTS=()
271285115cSWilliam A. Kennington III
281285115cSWilliam A. Kennington III# Runs tests and emits output specified by the Test Anything Protocol
291285115cSWilliam A. Kennington III# https://testanything.org/
30*59486679SPatrick Williamsfunction TestAnythingMain() {
311285115cSWilliam A. Kennington III    set -o nounset
321285115cSWilliam A. Kennington III    set -o errexit
331285115cSWilliam A. Kennington III    set -o pipefail
341285115cSWilliam A. Kennington III
351285115cSWilliam A. Kennington III    echo "TAP version 13"
361285115cSWilliam A. Kennington III    echo "1..${#TESTS[@]}"
371285115cSWilliam A. Kennington III
381285115cSWilliam A. Kennington III    local i
391285115cSWilliam A. Kennington III    for ((i=0; i <${#TESTS[@]}; ++i)); do
401285115cSWilliam A. Kennington III        local t="${TESTS[i]}"
411285115cSWilliam A. Kennington III        local tap_i=$((i + 1))
421285115cSWilliam A. Kennington III        if ! "$t"; then
431285115cSWilliam A. Kennington III            printf "not "
441285115cSWilliam A. Kennington III        fi
451285115cSWilliam A. Kennington III        printf "ok %d - %s\n" "$tap_i" "$t"
461285115cSWilliam A. Kennington III    done
471285115cSWilliam A. Kennington III}
48