#!/bin/sh
# Copyright (C) 2026 David Nichols
# SPDX-License-Identifier: MIT
set -eu
export LC_ALL=C.UTF-8
unset QORE_MODULE_DIR QORE_MODULE_DIR_ONLY QORE_INCLUDE_DIR LD_LIBRARY_PATH LD_PRELOAD
export QORE_MODULE_DIR=$(/usr/bin/qore --module-path)
export QORE_MODULE_DIR_ONLY=1
mkdir "$AUTOPKGTEST_TMP/test" "$AUTOPKGTEST_TMP/examples"
cp test/*.qtest test/*.qm "$AUTOPKGTEST_TMP/test/"
cp -a test/data "$AUTOPKGTEST_TMP/test/"
cp examples/*.qtest examples/*.qr "$AUTOPKGTEST_TMP/examples/"
cp debian/tests/run-suites "$AUTOPKGTEST_TMP/"
cd "$AUTOPKGTEST_TMP"
module_dir=$(printf '%s\n' "$QORE_MODULE_DIR" | tr : '\n' | while IFS= read -r path; do
    if [ -f "$path/SftpServerDataProvider/SftpServerDataProvider.qmod" ]; then printf '%s\n' "$path"; break; fi
done)
test -n "$module_dir"
export QORE_SSH_TEST_MODULE_DIR="$module_dir"
export QORE_SSH_TEST_QMOD_DIR="$module_dir"
exec ./run-suites installed
