Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ uv.lock
# coverage files
.coverage
coverage.xml
invalid_objs.json
23 changes: 15 additions & 8 deletions src/sphinx_codelinks/analyse/analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,21 @@ def extract_oneline_need(
if not src_comment.source_file:
row_offset += 1
continue
self.oneline_warnings.append(
AnalyseWarning(
str(src_comment.source_file.filepath),
src_comment.node.start_point.row + row_offset + 1,
resolved.msg,
MarkedContentType.need,
resolved.sub_type.value,
)
lineno = src_comment.node.start_point.row + row_offset + 1
warning = AnalyseWarning(
str(src_comment.source_file.filepath),
lineno,
resolved.msg,
MarkedContentType.need,
resolved.sub_type.value,
)
self.oneline_warnings.append(warning)
logger.warning(
"Oneline parser warning in %s:%d - %s: %s",
src_comment.source_file.filepath,
lineno,
resolved.sub_type.value,
resolved.msg,
)
row_offset += 1
continue
Expand Down
42 changes: 42 additions & 0 deletions tests/test_analyse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# @Test suite for source code analysis and marker extraction, TEST_ANA_1, test, [IMPL_LNK_1, IMPL_ONE_1, IMPL_MRST_1]
import json
import logging
from pathlib import Path

import pytest
Expand Down Expand Up @@ -141,3 +142,44 @@ def test_analyse_oneline_needs(
for src_file in src_analyse.src_files:
cnt_comments += len(src_file.src_comments)
assert cnt_comments == result["num_comments"]


def test_oneline_parser_warning_is_logged(tmp_path, caplog):
"""Test that oneline parser warnings are logged to the console."""

src_dir = TEST_DIR / "data" / "oneline_comment_default"
src_paths = [src_dir / "default_oneliners.c"]

src_analyse_config = SourceAnalyseConfig(
src_files=src_paths,
src_dir=src_dir,
get_need_id_refs=False,
get_oneline_needs=True,
get_rst=False,
oneline_comment_style=ONELINE_COMMENT_STYLE_DEFAULT,
)

# Ensure the logger propagates to root so caplog can capture it
analyse_logger = logging.getLogger("sphinx_codelinks.analyse.analyse")
original_propagate = analyse_logger.propagate
analyse_logger.propagate = True

try:
with caplog.at_level(
logging.WARNING, logger="sphinx_codelinks.analyse.analyse"
):
src_analyse = SourceAnalyse(src_analyse_config)
src_analyse.run()

# Verify that warnings were collected
assert len(src_analyse.oneline_warnings) == 1

# Verify that the warning was logged
warning_records = [
r for r in caplog.records if "Oneline parser warning" in r.message
]
assert len(warning_records) >= 1
assert "too_many_fields" in warning_records[0].message
finally:
# Restore original propagate setting
analyse_logger.propagate = original_propagate