Skip to content

Commit 99e5442

Browse files
authored
test: corrects test which checks that makefile consist help for all targets. (#215)
1 parent 6bbdec3 commit 99e5442

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ general-help:
184184
@echo " make [targets] [arguments]"
185185
@echo
186186
@echo "Commands:"
187+
@echo " all Install on the local computer without using package manager;"
187188
@echo " install Install on the local computer without using package manager;"
188189
@echo " uninstall Removes the installed utility from the system;"
189190
@echo " reinstall Removes the installed utility from the system and then installs it again;"

test/misc/test_makefile.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
import pytest
66

7-
TARGET_PATTERN = re.compile(r"^[a-zA-Z0-9-]*:\s*")
7+
TARGET_PATTERN = re.compile(r"^(?P<target_name>[a-zA-Z0-9-]+):\s*")
8+
MAKEFILE_HELP_TARGET_PATTERN = re.compile(r"^ (?P<target_name>[a-zA-Z0-9-]+)\s+")
89
MAKEFILE_NAME: Final = "Makefile"
10+
MAKEFILE_HELP_TARGETS_IGNORE: Final = {"make"}
911

1012

1113
@pytest.fixture
@@ -18,9 +20,10 @@ def makefile_targets() -> set[str]:
1820
)
1921
targets = set()
2022
for line in result.stdout.splitlines():
21-
if not TARGET_PATTERN.search(line):
23+
target_match = TARGET_PATTERN.search(line)
24+
if not target_match:
2225
continue
23-
target_name = line.split(":")[0]
26+
target_name = target_match.group("target_name")
2427
if target_name == MAKEFILE_NAME:
2528
continue
2629
targets.add(target_name)
@@ -36,9 +39,20 @@ def test_makefile_consist_help_msgs_for_all_targets(makefile_targets: set[str]):
3639
stderr=subprocess.PIPE,
3740
check=True,
3841
).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."
42+
makefile_help_targets = []
43+
for line in make_help_stdout.splitlines():
44+
target_match = MAKEFILE_HELP_TARGET_PATTERN.search(line)
45+
if not target_match:
46+
continue
47+
makefile_help_targets.append(target_match.group("target_name"))
48+
unique_makefile_help_targets = set(makefile_help_targets)
49+
assert len(makefile_help_targets) == len(
50+
unique_makefile_help_targets
51+
), "Some targets' help messages repeats."
52+
unique_makefile_help_targets -= MAKEFILE_HELP_TARGETS_IGNORE
53+
targets_without_help_message = makefile_targets - unique_makefile_help_targets
54+
targets_which_only_in_the_makehelp = unique_makefile_help_targets - makefile_targets
55+
assert unique_makefile_help_targets == makefile_targets, (
56+
f"Help message for the '{targets_without_help_message}' targets not found. "
57+
f"Help message for the '{targets_which_only_in_the_makehelp}' targets found."
58+
)

0 commit comments

Comments
 (0)