#!/bin/bash
set -e

pkg=nim-docopt-dev

if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

cp -a /usr/share/doc/${pkg}/examples/* "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"

echo "Test 1"
nim c -p:/usr/share/nimble/regex -p:/usr/share/nimble/docopt -p:/usr/share/nimble/unicodedb -p:/usr/share/nimble/unicodeplus odd_even.nim
./odd_even 1 2 3 4
[ "$(./odd_even 1 2 3 4 | md5sum | awk '{print $1}')" = "188a41b16f5c1a20365cae5b19bb4a57" ] || exit  1
rm -f ./odd_even
echo "PASS"


echo "Test 2"
nim c -p:/usr/share/nimble/regex -p:/usr/share/nimble/docopt -p:/usr/share/nimble/unicodedb -p:/usr/share/nimble/unicodeplus cycle.nim
./cycle -n 5 50
[ "$(./cycle -n 5 50 | md5sum | awk '{print $1}')" = "c2df8305727838cb8ad140473cabc14f" ] || exit  1
rm -f ./cycle
echo "PASS"

echo "Test 3"
nim c -p:/usr/share/nimble/regex -p:/usr/share/nimble/docopt -p:/usr/share/nimble/unicodedb -p:/usr/share/nimble/unicodeplus counted.nim
./counted go go
[ "$(./counted go go | md5sum | awk '{print $1}')" = "35a955afc492cf95272525b52c63a9e2" ] || exit  1
rm -f ./counted
echo "PASS"

