#!/bin/bash

set -e

outdir=${ADT_ARTIFACTS:-/tmp}/ocaml-dune-tests
echo "* Using $outdir"
mkdir -p ${outdir}
cp -a . ${outdir}
cd ${outdir}

# Many tests depend on the "spawn" library which is not packaged in
# Debian at the moment; remove them for now.
rm -rf test/expect-tests
rm -rf test/blackbox-tests/test-cases
rm -rf otherlibs/stdune/test
rm -rf otherlibs/chrome-trace/test
rm -rf src/fiber/test

# Other tests assume a native architecture
if ! command -v ocamlopt > /dev/null; then
    rm -rf otherlibs/dune-site/test
fi

# Flaky tests (to be investigated)
rm -rf otherlibs/dune-site/test # failed on amd64
rm -rf otherlibs/dune-rpc-lwt/examples/rpc_client/test # failed on riscv64
rm -rf otherlibs/dune-rpc-lwt/test # failed on s390x

echo "* Run tests"
dune runtest 2>&1
