# Use bash shell with pipefail option enabled so that the return status of a
# piped command is the value of the last (rightmost) commnand to exit with a
# non-zero status. This lets us pipe output into tee but still exit on test
# failures.
SHELL = /bin/bash
.SHELLFLAGS = -o pipefail -c

all: test

# wait for the device to be available before beginning the test
# A temporary volume is mounted at /build when 'make test' is executing.
# The following steps copy across useful output to this volume which can
# then be extracted to form the CI summary for the test procedure.
test:
	retry --max=15 -- tango_admin --ping-device mid_csp_cbf/sub_elt/subarray_01
	retry --max=15 -- tango_admin --ping-device mid_csp_cbf/sub_elt/subarray_02
	retry --max=15 -- tango_admin --ping-device mid_csp/elt/master
	retry --max=15 -- tango_admin --ping-device mid_csp/elt/subarray_01
	retry --max=15 -- tango_admin --ping-device mid_csp/elt/subarray_02
	cd /app &&  pytest tests| tee integration-test.stdout 
	mkdir -p build/reports && \
	if [ -d build ]; then \
                mv /app/integration-test.stdout ./build/csp-lmc-mid-setup-test.stdout; \
                mv /app/htmlcov ./build/csp-lmc-mid_htmlcov; \
                cp /app/coverage.xml ./build/coverage-csp-lmc-mid.xml; \
                cp /app/build/reports/csp-lmc-mid-unit-tests.xml ./build/reports; \
	fi;

	#cd /build && coverage combine csp-lmc-mid_coverage  csp-lmc-common_coverage && coverage xml
	#cd /build && mv coverage.xml ./reports/code-coverage.xml

.PHONY: all test
