#!/bin/sh
set -eu

source_dir=$(pwd)
waf=${WAF:-/usr/bin/waf}
work_dir=$(mktemp -d "${AUTOPKGTEST_TMP:-${TMPDIR:-/tmp}}/waf-upstream.XXXXXX")
trap 'rm -rf "$work_dir"' EXIT HUP INT TERM
export PYTHONDONTWRITEBYTECODE=1
unset WAFDIR

for python in $(py3versions -s); do
    # This extension must load after the removal of the pipes module.
    (
        cd "$work_dir"
        "$python" - <<'PY'
import shlex
from waflib.extras.genpybind import join_args

args = ['genpybind', 'a file.hpp', "single'quote", '$(unexpanded)', '']
assert shlex.split(join_args(args)) == args
PY
    )
    for suite in general utils preproc post; do
        echo "Testing $suite with $python"
        project_dir="$work_dir/$python-$suite"
        cp -R "$source_dir/tests/$suite" "$project_dir"
        (
            cd "$project_dir"
            "$python" "$waf" configure build --color=no -j2
        )
    done
done
