| 1 |
# test/module.mk |
| 2 |
# Part of ‘dput’, a Debian package upload toolkit. |
| 3 |
# |
| 4 |
# This is free software, and you are welcome to redistribute it under |
| 5 |
# certain conditions; see the end of this file for copyright |
| 6 |
# information, grant of license, and disclaimer of warranty. |
| 7 |
|
| 8 |
# Makefile rules for test suite. |
| 9 |
|
| 10 |
MAKE_TEST_MODULE_DIR := $(CURDIR)/test |
| 11 |
|
| 12 |
TEST_MODULES += $(shell find ${MAKE_TEST_MODULE_DIR}/ -name '*.py') |
| 13 |
|
| 14 |
PYTHON_UNITTEST = $(PYTHON) ${PYTHON_OPTS} -m unittest |
| 15 |
UNITTEST_NAMES ?= discover |
| 16 |
UNITTEST_OPTS ?= ${UNITTEST_NAMES} --buffer |
| 17 |
|
| 18 |
export COVERAGE_DIR = $(CURDIR)/.coverage |
| 19 |
coverage_html_report_dir = $(CURDIR)/htmlcov |
| 20 |
|
| 21 |
PYTHON_COVERAGE = $(PYTHON) ${PYTHON_OPTS} -m coverage |
| 22 |
# By starting from *all* Python modules and then filtering out *all* files |
| 23 |
# in the test suite, we report the coverage for any non-test modules. |
| 24 |
python_modules_for_coverage_report = $(filter-out \ |
| 25 |
${TEST_MODULES},${python_modules}) |
| 26 |
COVERAGE_RUN_OPTS ?= --branch |
| 27 |
COVERAGE_REPORT_OPTS ?= |
| 28 |
COVERAGE_TEXT_REPORT_OPTS ?= |
| 29 |
COVERAGE_HTML_REPORT_OPTS ?= |
| 30 |
|
| 31 |
|
| 32 |
.PHONY: test |
| 33 |
test: test-unittest test-manpages |
| 34 |
|
| 35 |
.PHONY: test-unittest |
| 36 |
test-unittest: |
| 37 |
$(PYTHON_UNITTEST) ${UNITTEST_OPTS} |
| 38 |
|
| 39 |
.PHONY: test-coverage |
| 40 |
test-coverage: test-coverage-run test-coverage-html test-coverage-report |
| 41 |
|
| 42 |
.PHONY: test-coverage-run |
| 43 |
test-coverage-run: coverage_opts = ${COVERAGE_RUN_OPTS} |
| 44 |
test-coverage-run: ${CODE_MODULES} |
| 45 |
$(PYTHON_COVERAGE) run ${coverage_opts} \ |
| 46 |
-m unittest ${UNITTEST_OPTS} |
| 47 |
|
| 48 |
${COVERAGE_DIR}: test-coverage-run |
| 49 |
|
| 50 |
GENERATED_FILES += ${COVERAGE_DIR} |
| 51 |
|
| 52 |
.PHONY: test-coverage-html |
| 53 |
test-coverage-html: coverage_opts = ${COVERAGE_REPORT_OPTS} ${COVERAGE_HTML_REPORT_OPTS} |
| 54 |
test-coverage-html: ${COVERAGE_DIR} |
| 55 |
$(PYTHON_COVERAGE) html ${coverage_opts} \ |
| 56 |
--directory ${coverage_html_report_dir}/ \ |
| 57 |
${python_modules_for_coverage_report} |
| 58 |
|
| 59 |
GENERATED_FILES += ${coverage_html_report_dir} |
| 60 |
|
| 61 |
.PHONY: test-coverage-report |
| 62 |
test-coverage-report: coverage_opts = ${COVERAGE_REPORT_OPTS} ${COVERAGE_TEXT_REPORT_OPTS} |
| 63 |
test-coverage-report: .coverage |
| 64 |
$(PYTHON_COVERAGE) report ${coverage_opts} \ |
| 65 |
${python_modules_for_coverage_report} |
| 66 |
|
| 67 |
|
| 68 |
.PHONY: test-manpages |
| 69 |
test-manpages: export LC_ALL = C.UTF-8 |
| 70 |
test-manpages: export MANROFFSEQ = |
| 71 |
test-manpages: export MANWIDTH = 80 |
| 72 |
test-manpages: export MANOPTS = --encoding=UTF-8 --troff-device=utf8 --ditroff |
| 73 |
test-manpages: ${manpage_paths} |
| 74 |
for manfile in $^ ; do \ |
| 75 |
printf "Rendering %s:" $$manfile ; \ |
| 76 |
man --local-file --warnings $$manfile > /dev/null ; \ |
| 77 |
printf " done.\n" ; \ |
| 78 |
done |
| 79 |
|
| 80 |
|
| 81 |
# Copyright © 2008–2026 Ben Finney <[email protected]> |
| 82 |
# |
| 83 |
# This is free software: you may copy, modify, and/or distribute this work |
| 84 |
# under the terms of the GNU General Public License as published by the |
| 85 |
# Free Software Foundation; version 3 of that license or any later version. |
| 86 |
# No warranty expressed or implied. See the file ‘LICENSE.GPL-3’ for details. |
| 87 |
|
| 88 |
|
| 89 |
# Local Variables: |
| 90 |
# coding: utf-8 |
| 91 |
# mode: makefile |
| 92 |
# End: |
| 93 |
# vim: fileencoding=utf-8 filetype=make : |