blueprint-compiler/tests/fuzz.py
James Westman 06f54c8ff8
Use typelib instead of XML
For normal compilation, use .typelib files rather than .gir XML files.
This is much faster.

Rather than using libgirepository, which would try to actually load the
libraries, we use a custom parser.

The language server will still read XML because it needs to access
documentation, which is not in the typelib, but that's generally fine
because it's a long lived process and only has to do that once.
2022-06-25 00:15:20 -05:00

34 lines
1 KiB
Python

import os, sys
from pythonfuzz.main import PythonFuzz
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from blueprintcompiler import tokenizer, parser, decompiler, gir
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__":
# Make sure Gtk 4.0 is accessible, otherwise every test will fail on that
# and nothing interesting will be tested
gir.get_namespace("Gtk", "4.0")
fuzz()