#!/bin/sh -e

this=weight
indir=debian/tests
outdir=${ADT_ARTIFACTS:-/tmp}/${this}
mkdir -p ${outdir}

ppx='visitors.ppx,visitors.runtime'
cp ${indir}/${this}.ml ${outdir}
cd ${outdir}
echo "* Compile to bytecode."
ocamlbuild -use-ocamlfind -pkgs ${ppx} weight.byte
echo "* Run bytecode"
[ $(./weight.byte) -eq '16' ]

if [ -x /usr/bin/ocamlopt ]
then
    echo "* Compile to native code"
    ocamlbuild -use-ocamlfind -pkgs ${ppx} weight.native;
    echo "* Run native code"
    [ $(./weight.native) -eq '16' ]
fi
