tests: Add fuzz test

This commit is contained in:
James Westman 2022-04-18 17:34:13 -05:00
parent 4e2501c7d7
commit 9144ac67f0
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
5 changed files with 61 additions and 1 deletions

27
tests/fuzz.py Normal file
View file

@ -0,0 +1,27 @@
from pythonfuzz.main import PythonFuzz
from blueprintcompiler import tokenizer, parser, decompiler
from blueprintcompiler.completions import complete
from blueprintcompiler.errors import PrintableError, MultipleErrors, CompileError, CompilerBugError
from blueprintcompiler.tokenizer import Token, TokenType, tokenize
from blueprintcompiler import utils
@PythonFuzz
def fuzz(buf):
try:
blueprint = buf.decode("ascii")
tokens = tokenizer.tokenize(blueprint)
ast, errors, warnings = parser.parse(tokens)
if errors is None and len(ast.errors) == 0:
actual = ast.generate()
except CompilerBugError as e:
raise e
except PrintableError:
pass
except UnicodeDecodeError:
pass
if __name__ == "__main__":
fuzz()