#!/bin/bash

set -e

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

# Tests with unsatisfied assumptions
rm -rf test/blackbox-tests/test-cases
rm -rf test/expect-tests/vcs

# Other failing tests
rm -rf src/lev/test
rm -rf src/fiber/test
rm -rf otherlibs/dyn/test
rm -rf otherlibs/dune-glob/test
rm -rf otherlibs/chrome-trace/test
rm -rf otherlibs/ocamlc-loc/test

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

# Many expect-tests fail, but common and test_scheduler are needed for the rest
mkdir test-libs
mv test/expect-tests/{common,test_scheduler} test-libs
rm -rf test/expect-tests

# 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
rm -rf otherlibs/stdune/test # failed on i386

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