44
55import 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+" )
89MAKEFILE_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