Skip to content

Commit b7c7eb7

Browse files
committed
tests: kdoc: fix parse failure logging
Commit 0a1066f ("tests: kdoc: fix handling file removal") added extra logging to the test intending to help debug parsing failures. Unfortunately, the newly added "<parse fail>" log line is added to every warning which doesn't end in ':', regardless of whether or not the KdocWarning class handles parsing of the line. This appears to have happened due to the confusion of the way skip and extra work. What we really want to do is convert the text into a warning object, then check if it cleanly parsed. We could check for the 'Unknown' kind. However, in the interest of being precise should new kinds ever be added, expose a new 'parsed' field of the warning object. Its set to true if we got a clean regex parse, and false otherwise. Additionally refactor the conditional checks and add comments for clarity. In particular, set extra to None unconditionally first, then perform the merging check. This should improve the readability and intended flow of this logic. Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
1 parent c6748a0 commit b7c7eb7

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

tests/patch/kdoc/test.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class KdocWarning:
3131
line : Optional[int] = dataclasses.field(repr=True, compare=False)
3232
# The content of the warning (excluding kind, file, line)
3333
content : str = dataclasses.field(repr=True, compare=True)
34+
parsed : bool = dataclasses.field(repr=True, compare=True)
3435

3536
@classmethod
3637
def from_text(self, line, extra=None):
@@ -54,20 +55,22 @@ def from_text(self, line, extra=None):
5455

5556
m = parser.match(line)
5657
if m:
58+
parsed = True
5759
kind = m['kind']
5860
file = m['file']
5961
line = int(m['line'])
6062
content = m['content']
6163
if extra:
6264
content += '\n' + extra
6365
else:
66+
parsed = False
6467
kind = 'Unknown'
6568
file = None
6669
line = None
6770
content = message
6871

6972
return KdocWarning(message, kind=kind, file=file, line=line,
70-
content=content)
73+
content=content, parsed=parsed)
7174

7275
def __str__(self):
7376
return self.message
@@ -80,20 +83,28 @@ def parse_warnings(lines, logs) -> List[KdocWarning]:
8083

8184
# Walk through lines and convert to warning objects
8285
for i, line in enumerate(lines):
86+
# Skip lines already merged into previous warning
8387
if skip:
8488
skip = False
8589
continue
8690

91+
# Ignore blank lines
92+
if not line.strip():
93+
continue
94+
95+
# Check if we should merge the next line with this warning
96+
extra = None
8797
if line.endswith(':') and i + 1 < length:
8898
extra = lines[i + 1]
8999
skip = True
90-
elif not line.strip():
91-
continue
92-
else:
93-
logs += ["<parse fail>: " + line.strip()]
94-
extra = None
95100

96-
warnings.append(KdocWarning.from_text(line, extra))
101+
# Parse line into warning object
102+
warning = KdocWarning.from_text(line, extra);
103+
104+
if not warning.parsed:
105+
logs += [f'<parse fail>: {line.strip()}']
106+
107+
warnings.append(warning)
97108

98109
return warnings
99110

0 commit comments

Comments
 (0)