1#! /bin/sh 2# 3# SPDX-License-Identifier: BSD-2-Clause 4# 5# Copyright (c) 2018-2021 Gavin D. Howard and contributors. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions are met: 9# 10# * Redistributions of source code must retain the above copyright notice, this 11# list of conditions and the following disclaimer. 12# 13# * Redistributions in binary form must reproduce the above copyright notice, 14# this list of conditions and the following disclaimer in the documentation 15# and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27# POSSIBILITY OF SUCH DAMAGE. 28# 29 30script="$0" 31 32testdir=$(dirname "$script") 33 34. "$testdir/../scripts/functions.sh" 35 36# usage: history.sh dir -a|idx 37 38# If Python does not exist, then just skip. 39py=$(command -v python3) 40err=$? 41 42if [ "$err" -ne 0 ]; then 43 44 py=$(command -v python) 45 err=$? 46 47 if [ "$err" -ne 0 ]; then 48 printf 'Could not find Python 3.\n' 49 printf 'Skipping %s history tests...\n' "$d" 50 exit 0 51 fi 52fi 53 54# d is "bc" or "dc" 55d="$1" 56shift 57 58# idx is either an index of the test to run or "-a". If it is "-a", then all 59# tests are run. 60idx="$1" 61shift 62 63# Set the test range correctly for all tests or one test. st is the start index. 64if [ "$idx" = "-a" ]; then 65 idx=$("$py" "$testdir/history.py" "$d" -a) 66 idx=$(printf '%s - 1\n' "$idx" | bc) 67 st=0 68else 69 st="$idx" 70fi 71 72# Run all of the tests. 73for i in $(seq "$st" "$idx"); do 74 75 for j in $(seq 1 3); do 76 77 printf 'Running %s history test %d...' "$d" "$i" 78 79 "$py" "$testdir/history.py" "$d" "$i" "$@" 80 err=$? 81 82 if [ "$err" -eq 0 ]; then 83 break 84 fi 85 86 done 87 88 checktest_retcode "$d" "$err" "$d history tests $i" 89 90 printf 'pass\n' 91 92done 93