#!/bin/sh

set -e

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

cat <<EOF > test.ml
print_string "Hello world!\n";;
EOF

cat <<EOF > test.obuild
name: test_project
version: 0.0.1
description:
  This is my test project
  .
  This is a long description describing properly what the project does.
licence: MIT
authors: Andy Li <andy@onthewings.net>
obuild-ver: 1
homepage: https://blog.onthewings.net/

executable test
  main-is: test.ml
EOF

obuild configure --disable-executable-native --enable-executable-bytecode
obuild build

echo "build: OK"

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

echo "run: OK"
