Skip to content

Commit

Permalink
source coverage: fix case when source file last line is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislaw committed Sep 19, 2023
1 parent 3f83781 commit 0970b29
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion strictdoc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from strictdoc.core.environment import SDocRuntimeEnvironment

__version__ = "0.0.44a10"
__version__ = "0.0.44a11"


environment = SDocRuntimeEnvironment(__file__)
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_pygmented_source_lines(

# HACK:
# Otherwise, Pygments will skip the first line as if it does not exist.
# This behavior surprisingly affects on the first line if its empty.
# This behavior surprisingly has an effect on the first line if its empty.
hack_first_line: bool = False
if source_file_lines[0] == "\n":
source_file_lines[0] = " \n"
Expand Down Expand Up @@ -152,12 +152,14 @@ def get_pygmented_source_lines(
), "Expected marker to be in place."
# Pop ###, pop "\n"
pygmented_source_file_lines.pop()
pygmented_source_file_lines.pop()
if pygmented_source_file_lines[-1] == "":
pygmented_source_file_lines.pop()

assert len(pygmented_source_file_lines) == len(source_file_lines), (
f"Something went wrong when running Pygments against "
f"the source file: "
f"{len(pygmented_source_file_lines)} == {len(source_file_lines)}"
f"{len(pygmented_source_file_lines)} == {len(source_file_lines)}, "
f"{pygmented_source_file_lines} == {source_file_lines}."
)

for pragma in coverage_info.pragmas:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ CHECK-HTML: <a{{.*}}href="../_source_files/file.py.html#REQ-001">

RUN: %cat %S/Output/html/_source_files/file.py.html | filecheck %s --dump-input=fail --check-prefix CHECK-SOURCE-FILE
CHECK-SOURCE-FILE: <a{{.*}}href="../01_basic_req_to_file_link_full_path/input.html#1-REQ-001"{{.*}}>
CHECK-SOURCE-FILE: <span class="c1"># noqa: T201</span></pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def hello_world():
print("hello world") # noqa: T201
123123 # noqa: W292, B018
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[DOCUMENT]
TITLE: Hello world doc

[REQUIREMENT]
UID: REQ-001
REFS:
- TYPE: File
VALUE: file.py
TITLE: Requirement Title
STATEMENT: Requirement Statement
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
RUN: %strictdoc export %S --experimental-enable-file-traceability --output-dir Output | filecheck %s --dump-input=fail
CHECK: Published: Hello world doc

RUN: %check_exists --file "%S/Output/html/_source_files/file.py.html"

RUN: %cat %S/Output/html/19_no_newline_at_end_of_file/input.html | filecheck %s --dump-input=fail --check-prefix CHECK-HTML
CHECK-HTML: <a{{.*}}href="../_source_files/file.py.html#REQ-001">

RUN: %cat %S/Output/html/_source_files/file.py.html | filecheck %s --dump-input=fail --check-prefix CHECK-SOURCE-FILE
CHECK-SOURCE-FILE: <a{{.*}}href="../19_no_newline_at_end_of_file/input.html#1-REQ-001"{{.*}}>
CHECK-SOURCE-FILE: <pre class="highlight"><span class="mi">123123</span> <span class="c1"># noqa: W292, B018</span></pre>

0 comments on commit 0970b29

Please sign in to comment.