#!/bin/sh

set -e

testdir=$(mktemp -d)
trap "rm -rf ${testdir}" 0 INT QUIT ABRT PIPE TERM
cd ${testdir}

cat <<EOF > test.ml
open Rope
let r = Rope.of_string "Hello world!"
let _ = print_int (Rope.length r)
EOF

if [ -x '/usr/bin/ocamlopt' ]
then
    ocamlfind ocamlopt -o native-code-test -I `ocamlfind query rope` rope.cmxa test.ml

    echo "build: OK"

    [ -x native-code-test ]
    ./native-code-test 2> /dev/null | grep -q "12"

    echo "run: OK"
else
    echo "skip native-code test since ocamlopt is not available"
fi
