############################################################
# Makefile for the regression tests that are run on travis
############################################################
# $(TRAVIS_BUILD_DIR) is /home/travis/build/ibpsa/modelica-ibpsa
# Set it to top-level directory of the IBPSA library if not set. (This is used for local testing.)
TRAVIS_BUILD_DIR ?= $(shell dirname \
  $(shell dirname \
  $(shell dirname \
  $(shell dirname \
  $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))))))
ROOT = $(TRAVIS_BUILD_DIR)

test-documentation:
	(cd $(ROOT)/IBPSA; ../bin/runUnitTests.py --validate-html-only)
	(cd $(ROOT)/IBPSA/Resources/src/fluid/heatpumps/calibration/doc; make regressiontest)

test-experiment-setup:
	(cd $(ROOT)/IBPSA; ../bin/runUnitTests.py --validate-experiment-setup)

test-autogenerated-files:
	@echo "*********************************************************"
	@echo "*** Check for package.order to be up to date"
	(cd  $(ROOT)/IBPSA; \
	  python -c 'import buildingspy.development.refactor as r; \
	  r.write_package_order(".", recursive=True)'; \
	  git diff --exit-code . )

test-bestest:
	@echo "*** Check if BESTEST results are up to date"
	(cd  $(ROOT)/IBPSA && \
	  rm -rf Resources/Data/BoundaryConditions/Validation/BESTEST/results && \
	  python3 Resources/Data/BoundaryConditions/Validation/BESTEST/generateResults.py -c )
	git status --porcelain $(ROOT)/IBPSA/Resources/Data/BoundaryConditions/Validation/BESTEST
	git diff --exit-code $(ROOT)/IBPSA/Resources/Data/BoundaryConditions/Validation/BESTEST

test-verify-files:
	(cd $(ROOT)/IBPSA && ../bin/verifyFiles.py)

test-dymola:
	(cd $(ROOT)/IBPSA && \
	  export PYTHONPATH=$(TRAVIS_BUILD_DIR)/IBPSA/Resources/Python-Sources && \
	  python3 ../bin/runUnitTests.py --batch --single-package $(PACKAGE) --tool dymola)

test-openmodelica:
	(cd $(ROOT)/IBPSA && \
	  export PYTHONPATH=$(TRAVIS_BUILD_DIR)/IBPSA/Resources/Python-Sources && \
	  python3 ../bin/runUnitTests.py --batch --single-package $(PACKAGE) --tool openmodelica --skip-verification)
