#!/bin/sh

set -e

# Run an example stolen from https://rise4fun.com/Boogie/McCarthy-91

TMPDIR=$(mktemp -d)
trap "rm -rf $TMPDIR" EXIT
cd $TMPDIR

cat <<EOF > test.bpl
procedure F(n: int) returns (r: int)
  ensures 100 < n ==> r == n - 10;  // This postcondition is easy to check by hand
  ensures n <= 100 ==> r == 91;     // Do you believe this one is true?
{
  if (100 < n) {
    r := n - 10;
  } else {
    call r := F(n + 11);
    call r := F(r);
  }
}
EOF

cat <<EOF > expected
Boogie program verifier finished with 1 verified, 0 errors
EOF

boogie test.bpl > boogie_output
tail -n1 boogie_output > result
diff result expected
