#!/bin/bash
set -efu

arch=$(dpkg-architecture -qDEB_HOST_ARCH)

EXTRA_TEST_FLAGS=""

# some tests are expected to fail
# so list tests to skip in array variable SKIP_TEST_LIST
declare -a SKIP_TEST_LIST

if [ "$arch" = "i386" ]; then
    EXTRA_TEST_FLAGS="${EXTRA_TEST_FLAGS} -v"
    SKIP_TEST_LIST=(${SKIP_TEST_LIST[@]} test_multiprocess_COG[u4] test_ramachandran \
	test_clustering_three_ensembles_two_identical test_hbond_analysis)
fi

# many tests fail on big-endian systems
# see https://github.com/MDAnalysis/mdanalysis/issues/1829
if [ "$arch" = "s390x" ]; then
    EXTRA_TEST_FLAGS="${EXTRA_TEST_FLAGS} -v"
    SKIP_TEST_LIST=(${SKIP_TEST_LIST[@]} test_start_stop_step test_count_by_time \
        test_rmsd test_mass_weighted test_custom_weighted test_ref_mobile_mass_mismapped \
	test_time test_dt test_total_time test_iter test_last_frame test_frame_jump \
	test_next_gives_second_frame test_set_time test_write_istart \
	test_write_trajectory_atomgroup test_write_trajectory_universe test_Timestep_time \
	test_rename_aux test_namdbin ref_reader25 ref_reader_extra_args25)
fi

SKIP_TESTS=""
list_initialised=0
for t in "${SKIP_TEST_LIST[@]}"; do
    if [ ${list_initialised} = 0 ]; then
        SKIP_TESTS=$t
        list_initialised=1
    else
        SKIP_TESTS="${SKIP_TESTS} or $t"
    fi
done
if [ "x${SKIP_TESTS}" != "x" ]; then
    SKIP_TESTS="not ( ${SKIP_TESTS} )"
fi
echo "skipping tests with SKIP_TEST_LIST=${SKIP_TEST_LIST[@]}"

for py in `py3versions -s`; do
  PMG_TEST_FILES_DIR=/usr/share/doc/pymatgen-test-files/examples/files \
    MPLBACKEND=agg $py -mpytest ${EXTRA_TEST_FLAGS} -k "${SKIP_TESTS}"
done
