#!/bin/bash
#
# Script to run tests on Travis-CI.
#
# This file is generated by l2tdevtools update-dependencies.py, any dependency
# related changes should be made in dependencies.ini.

# Exit on error.
set -e;

if test "${TARGET}" = "jenkins";
then
	./config/jenkins/linux/run_end_to_end_tests.sh "travis";

elif test "${TARGET}" = "pylint";
then
	pylint --version
	pylint --rcfile=.pylintrc setup.py dftimewolf tests

elif test "${TRAVIS_OS_NAME}" = "osx";
then
	PYTHONPATH=/Library/Python/2.7/site-packages/ /usr/bin/python ./run_tests.py;

	python ./setup.py build

	python ./setup.py sdist

	python ./setup.py bdist

	if test -f tests/end-to-end.py;
	then
		PYTHONPATH=. python ./tests/end-to-end.py --debug -c config/end-to-end.ini;
	fi

elif test -n "${FEDORA_VERSION}";
then
	CONTAINER_NAME="fedora${FEDORA_VERSION}";

	docker exec "${CONTAINER_NAME}" sh -c "git clone https://github.com/log2timeline/dftimewolf.git";

	if test ${TRAVIS_PYTHON_VERSION} = "2.7";
	then
		docker exec "${CONTAINER_NAME}" sh -c "cd dftimewolf && python2 run_tests.py";
	else
		docker exec "${CONTAINER_NAME}" sh -c "cd dftimewolf && python3 run_tests.py";
	fi

elif test "${TRAVIS_OS_NAME}" = "linux";
then
	if test -n "${TOXENV}";
	then
		tox --sitepackages ${TOXENV};

	else
		coverage erase

		coverage run --source=dftimewolf --omit="*_test*,*__init__*,*test_lib*" ./run_tests.py

		python ./setup.py build

		python ./setup.py sdist

		python ./setup.py bdist

		TMPDIR="${PWD}/tmp";
		TMPSITEPACKAGES="${TMPDIR}/lib/python${TRAVIS_PYTHON_VERSION}/site-packages";

		mkdir -p ${TMPSITEPACKAGES};

		PYTHONPATH=${TMPSITEPACKAGES} python ./setup.py install --prefix=${TMPDIR};

		if test -f tests/end-to-end.py;
		then
			PYTHONPATH=. python ./tests/end-to-end.py --debug -c config/end-to-end.ini;
		fi
	fi
fi
