#!/bin/sh

set -e

indir=${PWD}/debian/tests/c
outdir=${TMPDIR-/tmp}

if [ ! -f ${HOME}/.whyrc ]; then why-config  > /dev/null 2>&1; fi

cd ${outdir}

for infile in ${indir}/minimum.c
do
    base=$(basename $infile)
    # we copy the input file into the tmpdir since jessie insists on
    # creating "project" files in the directory of the input file :-(
    cp ${infile} .
    framacoutfile=${base%.c}.frc
    echo "Testing frama-c + jessie + alt-ergo on $base" >&2
    successpattern="why/${base%.c}_why.why           : .. (2/0/0/0/0)"
    frama-c -jessie -jessie-atp=alt-ergo ${base} > ${framacoutfile}
    if ! $(grep -q "${successpattern}" ${framacoutfile}); then
    	cat ${framacoutfile}
    	exit 1
    fi
done
