From 91c90d3e308a84c5a9a253587f19a069fecdde8c Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 14 Aug 2020 18:40:59 +0200 Subject: validation: Add ${step/123} support --- rtemsspec/tests/spec-validation/tc.yml | 2 +- rtemsspec/tests/test_validation.py | 8 ++++---- rtemsspec/validation.py | 36 ++++++++++++++++++---------------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/rtemsspec/tests/spec-validation/tc.yml b/rtemsspec/tests/spec-validation/tc.yml index c6ff4862..3cd4bf85 100644 --- a/rtemsspec/tests/spec-validation/tc.yml +++ b/rtemsspec/tests/spec-validation/tc.yml @@ -8,7 +8,7 @@ test-actions: /* Test case action 0 code */ checks: - check: | - /* Test case action 0 check 0 code */ + /* Test case action 0 check 0 code: ${steps/123} */ description: | Test case action 0 check 0 description. links: [] diff --git a/rtemsspec/tests/test_validation.py b/rtemsspec/tests/test_validation.py index 708a0ea2..bb7d1da2 100644 --- a/rtemsspec/tests/test_validation.py +++ b/rtemsspec/tests/test_validation.py @@ -839,14 +839,14 @@ T_TEST_CASE( Tc ) { /* Test case prologue code */ - T_plan(2); + T_plan(125); /* Test case action 0 code */ - /* Test case action 0 check 0 code */ - /* Test case action 0 check 1 code; step 0 */ + /* Test case action 0 check 0 code: Accounts for 123 test plan steps */ + /* Test case action 0 check 1 code; step 123 */ /* Test case action 1 code */ - /* Test case action 1 check 0 code; step 1 */ + /* Test case action 1 check 0 code; step 124 */ /* Test case action 1 check 1 code */ /* Test case epilogue code */ diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py index 3a344745..17f4e8e4 100644 --- a/rtemsspec/validation.py +++ b/rtemsspec/validation.py @@ -27,6 +27,7 @@ import itertools import math import os +import re from typing import Any, Dict, List, NamedTuple, Optional, Tuple from rtemsspec.content import CContent, CInclude, enabled_by_to_exp, \ @@ -35,30 +36,27 @@ from rtemsspec.items import Item, ItemCache, ItemGetValueContext, ItemMapper ItemMap = Dict[str, Item] +_STEPS = re.compile(r"^steps/([0-9]+)$") + def _get_test_run(ctx: ItemGetValueContext) -> Any: return f"{to_camel_case(ctx.item.uid[1:]).replace(' ', '')}_Run" -class _CodeMapper(ItemMapper): +class _Mapper(ItemMapper): def __init__(self, item: Item): super().__init__(item) + self._step = 0 self.add_get_value("requirement/functional/action:/test-run", _get_test_run) self.add_get_value("test-case:/test-run", _get_test_run) - -class _TextMapper(ItemMapper): - def __init__(self, item: Item): - super().__init__(item) - self._step = 0 - @property def steps(self): """ The count of test steps. """ return self._step - def reset_step(self): + def reset(self): """ Resets the test step counter. """ self._step = 0 @@ -67,6 +65,11 @@ class _TextMapper(ItemMapper): step = self._step self._step = step + 1 return self._item, str(step) + match = _STEPS.search(identifier) + if match: + inc = int(match.group(1)) + self._step += inc + return self._item, f"Accounts for {inc} test plan steps" return super().map(identifier) @@ -79,8 +82,7 @@ class _TestItem: def __init__(self, item: Item): self._item = item self._ident = to_camel_case(item.uid[1:]) - self._code_mapper = _CodeMapper(item) - self._text_mapper = _TextMapper(item) + self._mapper = _Mapper(item) def __getitem__(self, key: str): return self._item[key] @@ -132,7 +134,7 @@ class _TestItem: def substitute_code(self, text: Optional[str]) -> str: """ Performs a variable substitution for code. """ - return self._code_mapper.substitute(text) + return self._mapper.substitute(text) def substitute_text(self, text: Optional[str], @@ -141,8 +143,8 @@ class _TestItem: Performs a variable substitution for text with an optional prefix. """ if prefix: - return self._text_mapper.substitute_with_prefix(text, prefix) - return self._text_mapper.substitute(text) + return self._mapper.substitute_with_prefix(text, prefix) + return self._mapper.substitute(text) def add_test_case_description( self, content: CContent, @@ -217,13 +219,13 @@ class _TestItem: test_case_to_suites: Dict[str, List["_TestItem"]]) -> None: """ Generates the content. """ self.add_test_case_description(content, test_case_to_suites) - self._text_mapper.reset_step() + self._mapper.reset() actions = self._generate_test_case_actions() fixture = self["test-fixture"] header = self["test-header"] if header: self.generate_header(base_directory, header) - if self._text_mapper.steps > 0 and not fixture: + if self._mapper.steps > 0 and not fixture: fixture = "T_empty_fixture" content.add(self.substitute_code(self["test-support"])) if header: @@ -252,8 +254,8 @@ class _TestItem: content.gap = False with content.function(ret, name, params, align=align): content.add(self.substitute_code(self["test-prologue"])) - if self._text_mapper.steps > 0: - content.add(f"T_plan({self._text_mapper.steps});") + if self._mapper.steps > 0: + content.add(f"T_plan({self._mapper.steps});") content.add(actions) content.add(self.substitute_code(self["test-epilogue"])) if header and fixture: -- cgit v1.2.3