Skip to content

Commit

Permalink
backend/sdoc: print deprecation warnings when REFS/RELATIONS field is…
Browse files Browse the repository at this point in the history
… not the last among all fields
  • Loading branch information
stanislaw committed Oct 20, 2023
1 parent 727fe7e commit 56c9f21
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 9 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.44a16"
__version__ = "0.0.44a17"


environment = SDocRuntimeEnvironment(__file__)
18 changes: 18 additions & 0 deletions strictdoc/backend/sdoc/models/requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ def __init__( # pylint: disable=too-many-arguments
ordered_fields_lookup.setdefault(field.field_name, []).append(field)

if RequirementFieldName.REFS in ordered_fields_lookup:
refs_field: RequirementField = ordered_fields_lookup[
RequirementFieldName.REFS
][0]
if fields.index(refs_field) != (len(fields) - 1):
print( # noqa: T201
"warning: RELATIONS (previously REFS) requirement field "
"should be the last field, after all other fields. "
'See the section "Relations" in the user guide for '
"more details. "
"Correct requirement example:\n"
"[REQUIREMENT]\n"
"UID: REQ-2\n"
"STATEMENT: When Z, the system X shall do Y.\n"
"RELATIONS:\n"
"- TYPE: Parent\n"
" VALUE: REQ-1"
)

references_opt: Optional[List[Reference]] = ordered_fields_lookup[
RequirementFieldName.REFS
][0].field_value_references
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TITLE: Requirement #2 title
STATEMENT: >>>
Requirement #2 statement.
<<<
REFS:
RELATIONS:
- TYPE: Parent
VALUE: REQ-001
ROLE: Refines
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ TITLE: Requirement #2 title
STATEMENT: >>>
Requirement #2 statement.
<<<
REFS:
RELATIONS:
- TYPE: Parent
VALUE: REQ-001
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TITLE: Requirement #2 title
STATEMENT: >>>
Requirement #2 statement.
<<<
REFS:
RELATIONS:
- TYPE: Parent
VALUE: REQ-001
ROLE: Refines
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TITLE: Requirement title #2
STATEMENT: >>>
Requirement statement #2.
<<<
REFS:
RELATIONS:
- TYPE: Child
VALUE: REQ-001
ROLE: Refines
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ TITLE: Requirement title #2
STATEMENT: >>>
Requirement statement #2.
<<<
REFS:
RELATIONS:
- TYPE: Parent
VALUE: REQ-001
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TITLE: Requirement title #2
STATEMENT: >>>
Requirement statement #2.
<<<
REFS:
RELATIONS:
- TYPE: Parent
VALUE: REQ-001
ROLE: Refines
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TITLE: Requirement title #1
STATEMENT: >>>
Requirement statement #1.
<<<
REFS:
RELATIONS:
- TYPE: Parent
VALUE: REQ-002
- TYPE: Parent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tests.end2end.server import SDocTestServer


class Test_UC07_G1_T02_AddThreeLinks(E2ECase):
class Test(E2ECase):
def test(self):
test_setup = End2EndTestSetup(path_to_test_file=__file__)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[DOCUMENT]
TITLE: Hello world doc

[REQUIREMENT]
UID: REQ-1
STATEMENT: Shall do 1.

[REQUIREMENT]
UID: REQ-2
REFS:
- TYPE: Parent
VALUE: REQ-1
STATEMENT: Shall do 1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
RUN: %strictdoc export %S --output-dir Output | filecheck %s --dump-input=fail

CHECK: warning: RELATIONS (previously REFS) requirement field should be the last field, after all other fields. See the section "Relations" in the user guide for more details. Correct requirement example:
CHECK: Published: Hello world doc

RUN: %cat %S/Output/html/index.html | filecheck %s --dump-input=fail --check-prefix CHECK-HTML
CHECK-HTML: Hello world doc
CHECK-HTML: input.sdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[DOCUMENT]
TITLE: Hello world doc

[REQUIREMENT]
UID: REQ-1
STATEMENT: Shall do 1.

[REQUIREMENT]
UID: REQ-2
STATEMENT: Shall do 1.
REFS:
- TYPE: Parent
VALUE: REQ-1

[REQUIREMENT]
UID: REQ-3
STATEMENT: Shall do 1.
RELATIONS:
- TYPE: Parent
VALUE: REQ-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
RUN: %strictdoc export %S --output-dir Output | filecheck %s --dump-input=fail

CHECK-NOT: warning: RELATIONS (previously REFS) requirement field should be the last field
CHECK: Published: Hello world doc

RUN: %cat %S/Output/html/index.html | filecheck %s --dump-input=fail --check-prefix CHECK-HTML
CHECK-HTML: Hello world doc
CHECK-HTML: input.sdoc

0 comments on commit 56c9f21

Please sign in to comment.