Skip to content

Commit 6bbdec3

Browse files
authored
test+doc: adds a test to check that the Makefile consists of help messages for all targets. (#214)
1 parent fcd1d24 commit 6bbdec3

File tree

5 files changed

+58
-16
lines changed

5 files changed

+58
-16
lines changed

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ package: substitute-debian
128128

129129
test: substitute-sources
130130
pytest test/unit -vv
131+
pytest test/misc -vv
131132
make clean-cache
132133

133134
autotest:
@@ -184,17 +185,22 @@ general-help:
184185
@echo
185186
@echo "Commands:"
186187
@echo " install Install on the local computer without using package manager;"
187-
@echo " uninstall Remove installed util from system;"
188-
@echo " man Create man file."
189-
@echo " Require argparse-manpage python library;"
188+
@echo " uninstall Removes the installed utility from the system;"
189+
@echo " reinstall Removes the installed utility from the system and then installs it again;"
190+
@echo " man Create man file. Require argparse-manpage python library;"
190191
@echo " pre-commit Runs all pre-commit hooks;"
191192
@echo " test Runs unit tests with pytest framework;"
192193
@echo " autotest Runs auto tests."
193194
@echo " Required installed '$(UTIL_NAME)' util and provided ACCESS_TOKEN;"
195+
@echo " substitute-sources Substitutes dynamic variables into source code files and generates final files;"
196+
@echo " substitute-debian Substitutes dynamic variables into debian files and generates final files;"
197+
@echo " substitute-docker Substitutes dynamic variables into docker files and generates final files;"
194198
@echo " package Build the debian package;"
195199
@echo " clean-cache Delete __pycache__ folders created by pytest framework;"
196200
@echo " clean Remove generated while installing and testing files in the source directory (contains clean-cache);"
197201
@echo " clean-all Remove all generated files such as created docker files, debian and sources (contains clean);"
202+
@echo " todo-list Displays what is good to do in the source code;"
203+
@echo " general-help Displays information about upper-level targets;"
198204
@echo " help Displays information about all available targets."
199205
@echo
200206

docker/docker.mk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
docker-help:
22
@echo "Docker:"
33
@echo " docker-run Runs docker container with installed util;"
4-
@echo " docker-image Build docker image;"
4+
@echo " docker-image Builds a docker image;"
55
@echo " ALL=[1|0] REBUILD=[1|0]"
6+
@echo " docker-base-image Builds a basic docker image from which to build other images;"
7+
@echo " docker-test-image Builds a docker image for running tests and building package;"
68
@echo " docker-test Runs unit tests with pytest framework in the docker container;"
79
@echo " docker-autotest Runs autotests in docker container;"
8-
@echo " docker-build-package Build the debian package in special docker image;"
10+
@echo " docker-build-package Builds the debian package in special docker image;"
911
@echo " docker-rmi ALL=[1|0] Delete created docker images;"
1012
@echo " docker-help Displays information about available docker targets."
1113
@echo

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"Babel==2.15.0",
88
"Cython~=3.0.8",
99
"setuptools~=75.8.0",
10+
"Jinja2~=3.1.2",
1011
)
1112
INSTALL_REQUIREMENTS: tuple[str, ...] = (
1213
"argcomplete~=2.0.0",

test/conftest.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/misc/test_makefile.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import re
2+
import subprocess
3+
from typing import Final
4+
5+
import pytest
6+
7+
TARGET_PATTERN = re.compile(r"^[a-zA-Z0-9-]*:\s*")
8+
MAKEFILE_NAME: Final = "Makefile"
9+
10+
11+
@pytest.fixture
12+
def makefile_targets() -> set[str]:
13+
result = subprocess.run(
14+
["make", "-qp"],
15+
encoding="utf-8",
16+
stdout=subprocess.PIPE,
17+
stderr=subprocess.PIPE,
18+
)
19+
targets = set()
20+
for line in result.stdout.splitlines():
21+
if not TARGET_PATTERN.search(line):
22+
continue
23+
target_name = line.split(":")[0]
24+
if target_name == MAKEFILE_NAME:
25+
continue
26+
targets.add(target_name)
27+
assert targets, "No targets found, maybe error occurred."
28+
return targets
29+
30+
31+
def test_makefile_consist_help_msgs_for_all_targets(makefile_targets: set[str]):
32+
make_help_stdout = subprocess.run(
33+
["make", "help"],
34+
encoding="utf-8",
35+
stdout=subprocess.PIPE,
36+
stderr=subprocess.PIPE,
37+
check=True,
38+
).stdout
39+
targets_without_help = {
40+
target for target in makefile_targets if target not in make_help_stdout
41+
}
42+
assert (
43+
not targets_without_help
44+
), f"Help message for the '{targets_without_help}' targets not found."

0 commit comments

Comments
 (0)