#!/usr/bin/env bash

mkdir -p bin

call_python() {
	python3 $@
}

good() {
	echo -e "\033[92m${1}\033[0m"
}

bad() {
	echo -e "\033[91m\033[7m${1}\033[0m"
}

warn() {
	echo -e "\033[93m${1}\033[0m"
}

run() {
	call_python $@
	code=$?
	if [ ${code} -ne 0 ]
	then
		bad "Error in test '${1}'. Exiting..."
		exit ${code}
	fi
}

run_tests() {
	# Test prep (generate log files)
	warn "Undergoing test preparations"
	run ./tests/write.py ./bin/w1.lnm
	run ./tests/write_many.py ./bin/w2.lnm 100
	echo

	# Unit tests
	warn "Beginning unit tests"
	run ./tests/unit_parserargs.py
	echo

	good "Finished! Exiting with code 0..."
}

run_tests