#!/usr/bin/make

all: check

test-packages:
	$(MAKE) -C packages

check: test-packages
	# Between the two invocations of the test files (one with python and
	# the second using python-coverage), we remove the content of
	# __pycache__ to address the following bug:
	# https://bugs.launchpad.net/ubuntu/bionic/+source/unattended-upgrades/+bug/1974223
	set -e; \
	find . -name 'test_*.py' | \
	while read file; do \
	    if [ -x $$file ]; then \
		echo "Running $$file with python3"; \
	    	python3 $$file 2>&1; \
		rm -rf __pycache__ ; \
		echo "Running $$file with python3-coverage"; \
		python3 -m coverage run -a $$file 2>&1; \
	    fi \
	done

clean:
	$(MAKE) -C packages clean
	rm -rf ./aptroot/var/cache/
	rm -rf ./aptroot/var/lib/apt
	rm -rf ./aptroot/var/run
	find .. -type d -name __pycache__ | xargs rm -rf

coverage-html:
	echo "output in htmlcov/
	python3 -m coverage html
