#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2023 Marcel Telka
#

%patch% 01-test-sorted-list.patch
%patch% 02-test_int_pow.patch
%patch% 03-gmake.patch
%patch% 04-test-no-time.patch
%patch% 05-test_beta.patch

%include-3%
# Use well known path for Cython cache directory
COMPONENT_TEST_ENV += CYTHON_CACHE_DIR=$(@D)/.cython-cache-dir
# Testing installs packages using pip so direct it to private directory
COMPONENT_TEST_ENV += PYTHONUSERBASE=$(@D)/.python-user-base

# Cleanup remnants from previous test run (if any)
COMPONENT_PRE_TEST_ACTION += $(RM) -r $(@D)/.cython-cache-dir ;
COMPONENT_PRE_TEST_ACTION += $(RM) -r $(@D)/.python-user-base ;

# Normalize tmp dir name
COMPONENT_TEST_TRANSFORMS += "-e 's|\(TEST_TMP/cycache-test\).\{8\}\(/src\).\{8\}/|\1\2/|g'"
COMPONENT_TEST_TRANSFORMS += "-e 's|\(TEST_TMP/recythonize-test\).\{8\}\(/src\).\{8\}/|\1\2/|g'"
# Normalize pointer
COMPONENT_TEST_TRANSFORMS += "-e 's/\(Broken object at \)0x[a-f0-9]\{1,\}>/\1\$$(POINTER)>/g'"
# Remove line with private path
COMPONENT_TEST_TRANSFORMS += "-e '/^libgcov profiling error:/d'"
# Remove profiling info
COMPONENT_TEST_TRANSFORMS += "-e '/^Most expensive pipeline stages:/d'"
# Normalize random temporary file name
COMPONENT_TEST_TRANSFORMS += "-e 's|^\(/tmp/tmp\).\{8\}:|\1XXXXXXXX:|'"
# Normalize random file name
COMPONENT_TEST_TRANSFORMS += "-e 's/\(_cython_inline_\).\{40\}\.pyx/\1XXXXXXXX.pyx/'"

# tox.ini does not specify test requirements
TEST_REQUIREMENTS += test-requirements.txt