#!/usr/bin/env bash
# This script executes the pytest within fwval_zcrutinizer.py to run zcrutinizer on the source code
# in the firmware/validation directory

# Check if virtualenv is installed
if ! command -v virtualenv &> /dev/null
then
    echo "Please install virtualenv before running"
    exit
fi

# Create the python virtual environment
echo "Creating virtual environment: fwval_zcrutinizer_env"
virtualenv -p python3.6 fwval_zcrutinizer_env

# Source the newly created environment
source fwval_zcrutinizer_env/bin/activate

# Install the package dependencies for the tests
python -m pip install zcrutinizer pytest

# Run the package tests
python -m pytest -v firmware/validation/py_packages/zcrutinizer/src/zcrutinizer/fwval_zcrutinizer.py

# Deactivate the environment and clean up the directory
deactivate
rm -R fwval_zcrutinizer_env
