#!/bin/bash

# ZUGBRUECKE
# Calling routines in Windows DLLs from Python scripts running on unixlike systems
# https://github.com/pleiszenburg/zugbruecke
#
#	scripts/wine-pytest: Running tests with py.test
#
#	Required to run on platform / side: [UNIX]
#
# 	Copyright (C) 2017-2018 Sebastian M. Ernst <ernst@pleiszenburg.de>
#
# <LICENSE_BLOCK>
# The contents of this file are subject to the GNU Lesser General Public License
# Version 2.1 ("LGPL" or "License"). You may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
# https://github.com/pleiszenburg/zugbruecke/blob/master/LICENSE
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
# specific language governing rights and limitations under the License.
# </LICENSE_BLOCK>

# Get parameters from zugbruecke configuration
arch=$(python3 -c 'from zugbruecke.core.config import echo_parameter; echo_parameter("arch")')
version=$(python3 -c 'from zugbruecke.core.config import echo_parameter; echo_parameter("version")')
zugbruecke_dir=$(python3 -c 'from zugbruecke.core.config import echo_parameter; echo_parameter("dir")')

# Process parameters
dir_py=$zugbruecke_dir/$arch-python$version
dir_wine=$zugbruecke_dir/$arch-wine

# Set environment variables
export WINEARCH="$arch"
export WINEPREFIX="$dir_wine"

# Silence Wine ...
export WINEDEBUG=-all

# Install pytest if it is not there ...
if [ ! -f $dir_py/Scripts/pytest.exe ]; then
	wine-pip install pytest
fi

# Fire up py.test under Wine, pass cmd line arguments
wine $dir_py/Scripts/pytest.exe "$@"
