Skip to content

Commit ddbc815

Browse files
committed
Add test to check line numbers of the warnings
1 parent 0a976de commit ddbc815

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

tests/input/smushed_doc.robot

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
*** Test Cases ***
2+
My Smushed Test
3+
[Documentation] A Title on the same line.
4+
...
5+
... Some text here.
6+
... * a smushed list
7+
... Some other text.
8+
... **A smushed bold header**
9+
... Some more text.
10+
... - another smushed list
11+
... - another item
12+
...
13+
... **Another smushed bold header**
14+
... - item 1
15+
... - item 2
16+
... - item 3
17+
... Some text after the smushed list.
18+
...
19+
... **Good header**
20+
...
21+
... The end.
22+
No-op
23+

tests/test_formatting.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,28 @@ def test_stylecheck_with_custom_line_length():
334334
# If it returns 0, the test expects layout issues but none were found
335335
# This is acceptable as the formatter may handle it without reporting issues
336336
assert result_code in [0, 1]
337+
338+
339+
def test_line_numbers_in_warnings(caplog):
340+
"""Test that the style checker reports correct line numbers for smushed lists and bold headers."""
341+
file_name = "smushed_doc.robot"
342+
robot_file_original = INPUT_DIR / file_name
343+
if OUTPUT_DIR.exists():
344+
shutil.rmtree(OUTPUT_DIR)
345+
OUTPUT_DIR.mkdir()
346+
robot_file_to_fix = OUTPUT_DIR / file_name
347+
shutil.copy(robot_file_original, robot_file_to_fix)
348+
349+
sys.argv = ["robot2rst", "stylecheck", str(robot_file_to_fix), "--enable-bold-headers", "--fix"]
350+
351+
with caplog.at_level(logging.WARNING):
352+
robot2rst_main()
353+
354+
log_text = caplog.text
355+
assert (f"{robot_file_to_fix}:8: Smushed bold header detected: '**A smushed bold header**'. "
356+
"Added blank lines to ensure it is treated as a title.") in log_text
357+
assert (f"{robot_file_to_fix}:13: Smushed bold header detected: '**Another smushed bold header**'. "
358+
"Added blank lines to ensure it is treated as a title.") in log_text
359+
assert f"{robot_file_to_fix}:3: Fixed possible 'smushed' lists" in log_text
360+
assert f"{robot_file_to_fix}:6: Bullet list ends without a blank line; unexpected unindent." in log_text
361+
assert f"{robot_file_to_fix}:16: Bullet list ends without a blank line; unexpected unindent." in log_text

0 commit comments

Comments
 (0)