#!/usr/bin/env bash
#
# Author: Lukas Bulwahn
#
# DESCRIPTION: mutant-testing for counterexample generators and automated tools
PRG="$(basename "$0")"
function usage() {
[ -n "$MUTABELLE_OUTPUT_PATH" ] || MUTABELLE_OUTPUT_PATH="None"
echo
echo "Usage: isabelle $PRG [OPTIONS] THEORY"
echo
echo " Options are:"
echo " -L LOGIC parent logic to use (default $MUTABELLE_LOGIC)"
echo " -T THEORY parent theory to use (default $MUTABELLE_IMPORT_THEORY)"
echo " -O DIR output directory for test data (default $MUTABELLE_OUTPUT_PATH)"
echo " -N NUMBER number of lemmas to choose randomly, if not given all lemmas are chosen"
echo " -M NUMBER number of mutants for each lemma (default $MUTABELLE_NUMBER_OF_MUTANTS)"
echo " -X NUMBER number of mutations in a mutant (default $MUTABELLE_NUMBER_OF_MUTATIONS)"
echo
echo " THEORY is the name of the theory of which all theorems should be"
echo " mutated and tested."
echo exit 1
}
## process command line
# options
MUTABELLE_IMPORTS=""
while getopts "L:T:O:N:M:X:" OPT
do case"$OPT"in
L)
MUTABELLE_LOGIC="$OPTARG"
;;
T)
MUTABELLE_IMPORTS="$MUTABELLE_IMPORTS \"$OPTARG\""
;;
O)
MUTABELLE_OUTPUT_PATH="$OPTARG"
;;
N)
NUMBER_OF_LEMMAS="$OPTARG"
;;
M)
MUTABELLE_NUMBER_OF_MUTANTS="$OPTARG"
;;
X)
MUTABELLE_NUMBER_OF_MUTATIONS="$OPTARG"
;; \?)
usage
;;
esac done
shift $(($OPTIND - 1))
if [ "$MUTABELLE_IMPORTS" = "" ] then
MUTABELLE_IMPORTS="$MUTABELLE_IMPORT_THEORY"
fi
[ "$#" -ne 1 ] && usage
MUTABELLE_TEST_THEORY="$1"
if [ -z "$MUTABELLE_OUTPUT_PATH" ]; then
MUTABELLE_OUTPUT_PATH="${ISABELLE_TMP_PREFIX}-mutabelle$$"
PURGE_OUTPUT="true"
fi
export MUTABELLE_OUTPUT_PATH
if [ "$NUMBER_OF_LEMMAS" != "" ]; then
MUTABELLE_FILTER="|> MutabelleExtra.take_random $NUMBER_OF_LEMMAS"
fi
## main
echo "Starting Mutabelle..."
# setup
mkdir -p "$MUTABELLE_OUTPUT_PATH"
echo "theory Mutabelle_Test imports $MUTABELLE_IMPORTS uses \"$MUTABELLE_HOME/mutabelle.ML\" \"$MUTABELLE_HOME/mutabelle_extra.ML\" begin