Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System tests for lobster-json #189

Merged
merged 1 commit into from
Feb 4, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ test_install_monolithic
.coverage*
*.lobster
*.html
.idea
47 changes: 47 additions & 0 deletions lobster/tools/json/input_files.trlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package json_req
import req

req.System_Requirement Parse_Input_File {
description = '''
IF a list element given through the command line option "FILE_OR_DIR" is not a file nor a directory,
THEN the tool shall exit with a non-zero return code.
'''
}

req.System_Requirement_Aspect Parse_Input_File_JSON_Extension {
description = '''
OTHERWISE,
if the file extension is not "json" (case-insensitive),
THEN the tool shall print a warning.
Note - The file still will be parsed.
'''
}

req.System_Requirement_Aspect Parse_Input_File_Valid_JSON {
description = '''
OTHERWISE,
if the file content is invalid JSON,
THEN the tool shall exit with a non-zero return code.
'''
}

req.System_Requirement_Aspect Parse_Input_File_Input_Items {
description = '''
OTHERWISE the input data
SHALL be written in the LOBSTER interchange format
'''
// TODO: This requirement needs more details.
}

req.System_Requirement_Aspect Parse_Input_File_To_Stdout {
description = '''
to the file given in the command line option "out",
IF that option is given and is not an empty string,
'''
}

req.System_Requirement_Aspect Parse_Input_File_To_File {
description = '''
OTHERWISE to STDOUT.
'''
}
22 changes: 0 additions & 22 deletions lobster/tools/json/software_requirements.trlc

This file was deleted.

25 changes: 25 additions & 0 deletions lobster/tools/json/synthetic_name.trlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package json_req
import req

req.System_Requirement Name_Attribute_Given {
description = '''
In addition to [[Parse_Input_File]],
IF the command line option "name-attribute" is given and not an empty string,
THEN the tool
SHALL obtain the value from the input item at that key,
and use the obtained value as tag in the serialized LOBSTER item.
'''
}

req.System_Requirement_Aspect Name_Attribute_Missing {
description = '''
OTHERWISE, the tool
SHALL create a synthetic tag name based on the path of the JSON input file and an item counter.

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 input files,
but it shall be unique at least for each input file separately.
- No further specification is made about how to combine the path and the item counter.
'''
}
40 changes: 0 additions & 40 deletions lobster/tools/json/system_requirements.trlc

This file was deleted.

4 changes: 4 additions & 0 deletions lobster/tools/lobster-trlc.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
req.System_Requirement {
description = description
}

req.System_Requirement_Aspect {
description = description
}
13 changes: 13 additions & 0 deletions lobster/tools/requirements.rsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ type System_Requirement {
''' String
}

type System_Requirement_Aspect extends System_Requirement {
/* This type describes an aspect of a system requirement.
The aspect itself is not testable. It is only testable in the context of a requirement.
For example, an aspect may give details about a certain input, but it does not describe
the related output.
Nevertheless, system tests shall be linked to aspects, and each aspect shall be covered
by system tests. These tests must always take the requirement into account, which uses
the aspect.
Using this type helps to make long requirements easier to read, and it is easier to
develop tests for them.
*/
}

type Software_Requirement {
description '''
The content of the requirement.
Expand Down
3 changes: 1 addition & 2 deletions tests-system/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
!**/expected-output/*
!**/input/*
!**/expected-output/*
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The goal of this test is to check if a warning message is printed when the input
file has a non json extension.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"data": [
{
"tag": "json data.invalidjson:data.invalidjson.1",
"location": {
"kind": "file",
"file": "data.invalidjson",
"line": null,
"column": null
},
"name": "data.invalidjson:data.invalidjson.1",
"messages": [],
"just_up": [],
"just_down": [],
"just_global": [],
"framework": "JSON",
"kind": "Test Vector",
"status": null
}
],
"generator": "lobster-json",
"schema": "lobster-act-trace",
"version": 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<cmdline>: lobster warning: not a .json file
lobster-json: wrote 1 items to output.lobster
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--single
--tag-attribute=something
--out=output.lobster
data.invalidjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"items": {
"data": [
{
"name": "Take this item!"
}
]
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The goal of this test is to check if a warning message is printed when one of the input
files has a non-json extension, where another file has got a json extension.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"data": [
{
"tag": "json data.invalidjson:data.invalidjson.1",
"location": {
"kind": "file",
"file": "data.invalidjson",
"line": null,
"column": null
},
"name": "data.invalidjson:data.invalidjson.1",
"messages": [],
"just_up": [],
"just_down": [],
"just_global": [],
"framework": "JSON",
"kind": "Test Vector",
"status": null
},
{
"tag": "json valid.json:valid.1",
"location": {
"kind": "file",
"file": "valid.json",
"line": null,
"column": null
},
"name": "valid.json:valid.1",
"messages": [],
"just_up": [],
"just_down": [],
"just_global": [],
"framework": "JSON",
"kind": "Test Vector",
"status": null
}
],
"generator": "lobster-json",
"schema": "lobster-act-trace",
"version": 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<cmdline>: lobster warning: not a .json file
lobster-json: wrote 2 items to output.lobster
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--single
--tag-attribute=something
--out=output.lobster
data.invalidjson
valid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"items": {
"data": [
{
"name": "Take this item!"
},
{
"name": "unclear"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"items": {
"data": [
{
"name": "This file has a valid json extension"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The goal of this test is to check if an error message gets printed
if the input file to the lobster-json tool does not exist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<cmdline>: lobster error: file/does/not_exists.json is not a file or directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--single
--tag-attribute=something
--out=output.lobster
file/does/not_exists.json
Loading