Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion strictdoc/backend/sdoc_source_code/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
;

Req[noskipws]:
uid = /(?!scope=)[A-Za-z][A-Za-z0-9\\-]+/
uid = /(?!scope=)[A-Za-z][A-Za-z0-9\\-\\_]+/
;

SingleLineString[noskipws]:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[DOCUMENT]
TITLE: Example: Traceability between requirements and source files

[REQUIREMENT]
UID: REQ-001
TITLE: Requirement to source reference
STATEMENT: This requirement references the whole file from requirements.
RELATIONS:
- TYPE: File
VALUE: file.st

[REQUIREMENT]
UID: REQ-002
TITLE: Source to requirement range reference
STATEMENT: This requirement references a range in the file.

[REQUIREMENT]
UID: REQ-003
TITLE: Requirement to source range reference
STATEMENT: This requirement references a range in the file from the requirement.
RELATIONS:
- TYPE: File
VALUE: file.st
LINE_RANGE: 2, 4

[REQUIREMENT]
UID: SF_REQ-001
TITLE: Custom requirement prefix range reference
STATEMENT: This requirement has a custom prefix, and is referenced in the file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @relation(SF_REQ-001, scope=file)
FUNCTION_BLOCK FB_Test
VAR_INPUT
i_xA: BOOL;
i_xB: BOOL;
END_VAR
VAR_OUTPUT
o_xX: BOOL;
END_VAR

// --- BEGIN IMPLEMENTATION ---
// @relation(REQ-002, scope=range_start)
IF i_xA AND i_xB THEN
o_xX := TRUE;
ELSE
o_xX := FALSE;
END_IF
// @relation(REQ-002, scope=range_end)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]

features = [
"REQUIREMENT_TO_SOURCE_TRACEABILITY",
]

include_source_paths = [
"file.st",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# This test verifies that the Structured Text (PLCs) format is properly recognized
# by StrictDoc. In addition, based on a user report, this test verifies that the
# markers with mixed slashes and underscored are recognized correctly, e.g., SF_REQ-001.
#
# Original issue: https://github.com/strictdoc-project/strictdoc/discussions/2568.
#
# @relation(SDOC-SRS-142, scope=file)
#

RUN: %strictdoc export %S --output-dir %T | filecheck %s --dump-input=fail
CHECK: Published: Example: Traceability between requirements and source files

RUN: %check_exists --file "%T/html/_source_files/file.st.html"

RUN: %cat %T/html/%THIS_TEST_FOLDER/example.html | filecheck %s --dump-input=fail --check-prefix CHECK-HTML
CHECK-HTML: <a{{.*}}href="../_source_files/file.st.html#REQ-001#1#18">
CHECK-HTML: <a{{.*}}href="../_source_files/file.st.html#REQ-002#12#18">
CHECK-HTML: <a{{.*}}href="../_source_files/file.st.html#REQ-003#2#4">
CHECK-HTML: <a{{.*}}href="../_source_files/file.st.html#SF_REQ-001#1#18">

RUN: %cat %T/html/_source_files/file.st.html | filecheck %s --dump-input=fail --check-prefix CHECK-SOURCE-FILE

# Verify that the Text lexer is selected for this file as Pygments does not
# support the ST syntax at the moment.
CHECK-SOURCE-FILE: /* Lexer: Text only */
# Verify that the link that points back to requirement is displayed correctly.
CHECK-SOURCE-FILE: href="../66_st_structured_text_user_report/example.html#REQ-001"
# Verify that the range link is displayed correctly.
CHECK-SOURCE-FILE: href="../_source_files/file.st.html#REQ-001#1#18"
CHECK-SOURCE-FILE: href="../_source_files/file.st.html#SF_REQ-001#1#18"
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,31 @@ def test_002_two_range_markers():
assert marker_4.ng_range_line_begin == 6


def test_003_marker_with_dashes_and_underscores():
"""
Verifies that SF_REQ-001 markers can be parsed (identifiers with mixed _ and -).

Bug report: https://github.com/strictdoc-project/strictdoc/discussions/2568.
"""

source_input = """\
# @relation(SF_REQ-001, scope=file)
CONTENT 1
CONTENT 2
CONTENT 3
""".lstrip()

reader = SourceFileTraceabilityReader()

document = reader.read(source_input)
markers = document.markers
assert markers[0].reqs == ["SF_REQ-001"]
assert markers[0].is_begin()
assert markers[0].ng_source_line_begin == 1
assert markers[0].ng_range_line_begin == 1
assert markers[0].ng_range_line_end == 4


def test_005_no_markers():
source_input = """
def hello_world_2():
Expand Down