#!/bin/sh

set -e

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

cat <<EOF > hello_world.ml
let () =
  print_endline "Hello, world!";
  ignore (Luv.Loop.run () : bool)
EOF

cat <<EOF > dune-project
(lang dune 2.7)
EOF

cat <<EOF > dune
(executable
 (name hello_world)
 (libraries luv))
EOF

dune build

echo "build: OK"

dune exec ./hello_world.exe | grep -q "Hello, world!"

echo "run: OK"
