#!/bin/bash

set -euxo pipefail

CCLIB_VERSION=`dpkg-query --showformat='${Version}' --show cclib | sed "s/-.*//; s/~//"`
CCLIB_TAG=v${CCLIB_VERSION}

echo "Downloading repository of regression files..."
mkdir -p data
pushd data
git -c http.sslVerify=false clone -n --filter=tree:0 https://github.com/cclib/cclib.git
pushd cclib
git sparse-checkout set --no-cone data
git -c http.sslVerify=false checkout ${CCLIB_TAG} || git -c http.sslVerify=false checkout
mv data/* ..
popd
git -c http.sslVerify=false clone --filter=tree:0 https://github.com/cclib/cclib-data.git regression
pushd regression
git -c http.sslVerify=false checkout ${CCLIB_TAG} || git -c http.sslVerify=false checkout
popd
popd

echo "Running tests..."
python3 -m pytest -v --capture=no test -k "not (test_method or bridge or io or parser or psi4 or pyscf or pyquante)"
python3 -m pytest -v --capture=no test/regression.py
python3 -m pytest -v -s test/regression_io.py

python3 -m test.test_utils
python3 -m test.test_data --terse
python3 -m test.regression --traceback
python3 -m test.regression_io
