From dc37fdb897453d47e6f923d83d2c507cb54d6d3d Mon Sep 17 00:00:00 2001 From: Philipp Wullstein-Kammler Date: Tue, 14 Jan 2025 18:26:05 +0100 Subject: [PATCH] Write FILE_OR_DIR requirement Write a requirement to specify the behavior of `lobster-json` if input files or directories are specified by the user. Add system tests for this requirement. --- ...ements.trlc => software_requirements.trlc} | 6 ++- lobster/tools/json/system_requirements.trlc | 40 +++++++++++++++++++ lobster/tools/requirements.rsl | 12 +++++- .../input/dir1/nested.json | 0 .../rbt-directory-input/input/file.json | 14 +++++++ 5 files changed, 68 insertions(+), 4 deletions(-) rename lobster/tools/json/{requirements.trlc => software_requirements.trlc} (71%) create mode 100644 lobster/tools/json/system_requirements.trlc create mode 100644 tests-system/lobster-json/rbt-directory-input/input/dir1/nested.json create mode 100644 tests-system/lobster-json/rbt-directory-input/input/file.json diff --git a/lobster/tools/json/requirements.trlc b/lobster/tools/json/software_requirements.trlc similarity index 71% rename from lobster/tools/json/requirements.trlc rename to lobster/tools/json/software_requirements.trlc index 0ee8b944..89140cb7 100644 --- a/lobster/tools/json/requirements.trlc +++ b/lobster/tools/json/software_requirements.trlc @@ -6,8 +6,10 @@ req.Software_Requirement Synthetic_Tag_Name { If the command line option --name-attribute is not given, then the tool shall create a synthetic tag name based on the path of the JSON input file and an item counter. - Note: The item counter does not need to be unique across files. - It shall be unique at least for each input file separately. + Notes: + - "Synthetic" means that, the name does not need to be related to the data. + - The item counter does not need to be unique across files. + But it shall be unique at least for each input file separately. ''' } diff --git a/lobster/tools/json/system_requirements.trlc b/lobster/tools/json/system_requirements.trlc new file mode 100644 index 00000000..751aff64 --- /dev/null +++ b/lobster/tools/json/system_requirements.trlc @@ -0,0 +1,40 @@ +package json_req +import req + +req.Definition JSON_Input_File { + description = ''' + Each file with the file name extension json is a valid input file. + ''' +} + +req.Definition File_Scanning { + description = ''' + The term "scanning an input file" means that the tool + 1. searches for JSON elements in it according to the configuration provided by + the user, + 2. and serializes these elements in LOBSTER interchange format to the desired + output. + + Note: + It is possible to write a system test to verify that the tool is scanning a file + in the following way: + 1. Define a set of valid input files containing valid elements. + 2. Run the tool. + 3. Verify that the resulting output contains (exactly) all of the input elements. + ''' +} + +req.Definition Directory_Scanning { + description = ''' + The term "scanning a directory" means that the tool scans each file inside that directory + according to [[File_Scanning]], if it is a JSON file according to [[JSON_Input_File]]. + ''' +} + +req.System_Requirement Directory_Input { + description = ''' + If a list element given through the command line option FILE_OR_DIR is a directory, + then that directory and recursively all subdirectories shall be scanned + according to [[Directory_Scanning]]. + ''' +} diff --git a/lobster/tools/requirements.rsl b/lobster/tools/requirements.rsl index db0c4230..ad8109fc 100644 --- a/lobster/tools/requirements.rsl +++ b/lobster/tools/requirements.rsl @@ -3,7 +3,7 @@ package req type System_Requirement { description ''' The content of the requirement. - A tool requirement describes the behaviour of a lobster tool from the point of view of the user. + A tool requirement describes the behavior of a lobster tool from the point of view of the user. It does not describe implementation details. ''' String } @@ -11,6 +11,14 @@ type System_Requirement { type Software_Requirement { description ''' The content of the requirement. - A software requirement describes the behaviour of a lobster tool. + A software requirement describes the behavior of a lobster tool. ''' String } + +type Definition { + description ''' + The text of the definition. + A definition shall be formulated such that it is reusable in multiple requirements, + to prevent the need of duplicating text. + ''' String +} \ No newline at end of file diff --git a/tests-system/lobster-json/rbt-directory-input/input/dir1/nested.json b/tests-system/lobster-json/rbt-directory-input/input/dir1/nested.json new file mode 100644 index 00000000..e69de29b diff --git a/tests-system/lobster-json/rbt-directory-input/input/file.json b/tests-system/lobster-json/rbt-directory-input/input/file.json new file mode 100644 index 00000000..e46173d8 --- /dev/null +++ b/tests-system/lobster-json/rbt-directory-input/input/file.json @@ -0,0 +1,14 @@ +{ + "test-name": "potato", + "potato" : { + "data": [ + { + "name" : "Test_1", + "tags" : ["example.req1"], + "inputs" : [1, 2], + "expect" : 3 + } + ], + "wibble": 42 + } +}