#!/bin/sh
# Checks the installed ros2-term .deb under the system Python, with ROS sourced:
# both commands start, the app and Textual load from the bundle (even with apt's
# too-old python3-textual installed), and the tests pass against it.
# CI runs it after installing the .deb; it works locally too.
# ./debian/smoke-test [path to this checkout's test/]
set -eu
tests=$(cd "${1:-$(dirname "$0")/../test}" && pwd)
# ROS's setup.sh reads unset variables (AMENT_TRACE_SETUP_FILES, ...): no -u for it.
set +u
. "/opt/ros/${ROS_DISTRO:-jazzy}/setup.sh"
set -u
cd /tmp
ros2-term --help > /dev/null
ros2-log-view --help > /dev/null
export PYTHONPATH="/usr/lib/ros2-term:$PYTHONPATH"
/usr/bin/python3 - <<'PY'
import os, ros2_term, textual
for mod in (ros2_term, textual):
    where = os.path.dirname(mod.__file__)
    if not where.startswith("/usr/lib/ros2-term/"):
        raise SystemExit(f"{mod.__name__} imported from {where}, not the .deb's bundle")
print("textual", textual.__version__, "from the bundle")
PY
/usr/bin/python3 -m pytest -q -p no:cacheprovider "$tests"
echo "smoke test passed"
