#!/bin/sh

set -e

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

cat <<EOF > test.ml
open Base64
let r = Base64.str_decode (Base64.str_encode "Hello world!")
let _ = Printf.printf "%s" r
EOF

ocamlfind ocamlc -o byte-code-test -I `ocamlfind query extlib` extLib.cma test.ml

echo "build: OK"

[ -x byte-code-test ]
./byte-code-test 2> /dev/null | grep -q "Hello world!"

echo "run: OK"