File tree Expand file tree Collapse file tree 3 files changed +43
-8
lines changed
src/sphinx_codelinks/analyse Expand file tree Collapse file tree 3 files changed +43
-8
lines changed Original file line number Diff line number Diff line change @@ -23,3 +23,4 @@ uv.lock
2323# coverage files
2424.coverage
2525coverage.xml
26+ invalid_objs.json
Original file line number Diff line number Diff line change @@ -198,14 +198,21 @@ def extract_oneline_need(
198198 if not src_comment .source_file :
199199 row_offset += 1
200200 continue
201- self .oneline_warnings .append (
202- AnalyseWarning (
203- str (src_comment .source_file .filepath ),
204- src_comment .node .start_point .row + row_offset + 1 ,
205- resolved .msg ,
206- MarkedContentType .need ,
207- resolved .sub_type .value ,
208- )
201+ lineno = src_comment .node .start_point .row + row_offset + 1
202+ warning = AnalyseWarning (
203+ str (src_comment .source_file .filepath ),
204+ lineno ,
205+ resolved .msg ,
206+ MarkedContentType .need ,
207+ resolved .sub_type .value ,
208+ )
209+ self .oneline_warnings .append (warning )
210+ logger .warning (
211+ "Oneline parser warning in %s:%d - %s: %s" ,
212+ src_comment .source_file .filepath ,
213+ lineno ,
214+ resolved .sub_type .value ,
215+ resolved .msg ,
209216 )
210217 row_offset += 1
211218 continue
Original file line number Diff line number Diff line change @@ -141,3 +141,30 @@ def test_analyse_oneline_needs(
141141 for src_file in src_analyse .src_files :
142142 cnt_comments += len (src_file .src_comments )
143143 assert cnt_comments == result ["num_comments" ]
144+
145+
146+ def test_oneline_parser_warning_is_logged (tmp_path , caplog ):
147+ """Test that oneline parser warnings are logged to the console."""
148+ src_dir = TEST_DIR / "data" / "oneline_comment_default"
149+ src_paths = [src_dir / "default_oneliners.c" ]
150+
151+ src_analyse_config = SourceAnalyseConfig (
152+ src_files = src_paths ,
153+ src_dir = src_dir ,
154+ get_need_id_refs = False ,
155+ get_oneline_needs = True ,
156+ get_rst = False ,
157+ oneline_comment_style = ONELINE_COMMENT_STYLE_DEFAULT ,
158+ )
159+
160+ with caplog .at_level ("WARNING" , logger = "sphinx_codelinks.analyse.analyse" ):
161+ src_analyse = SourceAnalyse (src_analyse_config )
162+ src_analyse .run ()
163+
164+ # Verify that warnings were collected
165+ assert len (src_analyse .oneline_warnings ) == 1
166+
167+ # Verify that the warning was logged
168+ assert len (caplog .records ) == 1
169+ assert "Oneline parser warning" in caplog .records [0 ].message
170+ assert "too_many_fields" in caplog .records [0 ].message
You can’t perform that action at this time.
0 commit comments