-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add --format flag and *ErrorsFormatter classes
- Loading branch information
Showing
5 changed files
with
146 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import json | ||
|
||
import pytest | ||
|
||
from norminette.file import File | ||
from norminette.lexer import Lexer | ||
from norminette.context import Context | ||
from norminette.registry import Registry | ||
from norminette.errors import JSONErrorsFormatter | ||
|
||
tests = [ | ||
{ | ||
"file": File("/nium/test.c", "int\tmain()\n{\n\treturn ;\n}\n"), | ||
"test": { | ||
"files": [ | ||
{ | ||
"path": "/nium/test.c", | ||
"status": "Error", | ||
"errors": [ | ||
{ | ||
"name": "INVALID_HEADER", | ||
"text": "Missing or invalid 42 header", | ||
"level": "Error", | ||
"highlights": [{"lineno": 1, "column": 1, "length": None, "hint": None}], | ||
}, | ||
{ | ||
"name": "NO_ARGS_VOID", | ||
"text": "Empty function argument requires void", | ||
"level": "Error", | ||
"highlights": [{"lineno": 1, "column": 10, "length": None, "hint": None}], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("file,test", [it.values() for it in tests]) | ||
def test_json_formatter_errored_file(file, test): | ||
lexer = Lexer(file) | ||
context = Context(file, lexer.get_tokens()) | ||
Registry().run(context) | ||
|
||
formatter = JSONErrorsFormatter(file) | ||
assert str(formatter) == json.dumps(test, separators=",:") |