#!/usr/bin/env bash

# Perform sanity tests on the modules.
# To keep retrying a failing test, you can set the following environment variables.
# This is mainly intended for CI use.
#   TEST_RETRIES=<num> - Number of times to try the test. Default: 1
#   TEST_RETRY_DELAY=<num> - Number of seconds to wait between failing test runs. Default: 300 (5min)

set -eu
set -o pipefail

SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# shellcheck disable=1091
source "$SCRIPT_DIRECTORY/constants.sh"
# shellcheck disable=1091
source "$SCRIPT_DIRECTORY/util.sh"

TEST_RETRIES="${TEST_RETRIES:-1}"
TEST_RETRY_DELAY="${TEST_RETRY_DELAY:-300}"

# As we only support py36+, pyupgrade is set to remove the py27 boilerplate. Don't check for that as we don't need it
retry "$TEST_RETRIES" "$TEST_RETRY_DELAY" tox -e sanity -- \
    --docker --color -v \
    --python "$PYTHON_VERSION" \
    --skip-test metaclass-boilerplate --skip-test future-import-boilerplate
