#!/usr/bin/env bash

# a basic test that murphi2c produces valid C code

if [ -z "${AUTOPKGTEST_TMP}" ]; then
  printf 'AUTOPKGTEST_TMP not set; not running in autopkgtest?\n' >&2
  exit 1
fi

set -e
set -x

# move to temporary directory
mkdir -p ${AUTOPKGTEST_TMP}/murphi2c-source
cd ${AUTOPKGTEST_TMP}/murphi2c-source

# construct a simple model
cat - >model.m <<EOT
var
  x: boolean;

startstate begin
  x := true;
end;

rule begin
  x := !x;
end;
EOT

# generate C code for this model
murphi2c --output model.c model.m

# confirm we can compile it
${CC:-cc} -std=c11 -o /dev/null -c model.c
