#!/bin/sh

set -e
set -x

SRC=$(pwd)
PYTHON3S=$(py3versions -vs)

# Run the suite against the installed python3-msgpack, not the source
# tree: "python -m pytest" from the source root would put the source
# directory on sys.path, shadowing the installed _cmsgpack C extension
# with the pure-Python fallback.
for i in ${PYTHON3S} ; do
	cd "${AUTOPKGTEST_TMP:-/tmp}"
	python$i -c "import msgpack; print('msgpack from:', msgpack.__file__)"
	# First pass: the C extension; fail loudly if it is not in use.
	python$i -c "import msgpack; assert msgpack.Unpacker.__module__ != 'msgpack.fallback', 'C extension not in use'"
	python$i -m pytest "$SRC/test" -v
	# Second pass: the pure-Python fallback, like upstream's tox
	# 'purepython' environment.
	MSGPACK_PUREPYTHON=1 python$i -m pytest "$SRC/test" -v
done
