mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-07-07 01:29:26 -04:00
fuzz: Add option for more complete testing
Add a FUZZ_LEVEL environment variable that can be used to test the language server features under the fuzzer in addition to the compiler. It's not enabled by default, but can be useful to run locally.
This commit is contained in:
parent
fe8a629d4b
commit
61acfbda98
1 changed files with 19 additions and 5 deletions
|
@ -7,25 +7,28 @@ from blueprintcompiler.outputs.xml import XmlOutput
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
||||||
|
|
||||||
from blueprintcompiler import decompiler, gir, parser, tokenizer, utils
|
from blueprintcompiler import gir, parser, tokenizer
|
||||||
from blueprintcompiler.completions import complete
|
from blueprintcompiler.completions import complete
|
||||||
from blueprintcompiler.errors import (
|
from blueprintcompiler.errors import (
|
||||||
CompileError,
|
|
||||||
CompilerBugError,
|
CompilerBugError,
|
||||||
MultipleErrors,
|
|
||||||
PrintableError,
|
PrintableError,
|
||||||
)
|
)
|
||||||
from blueprintcompiler.tokenizer import Token, TokenType, tokenize
|
from blueprintcompiler.lsp import LanguageServer
|
||||||
|
|
||||||
|
fuzz_level = int(os.getenv("FUZZ_LEVEL") or "0")
|
||||||
|
|
||||||
|
|
||||||
@PythonFuzz
|
@PythonFuzz
|
||||||
def fuzz(buf):
|
def fuzz(buf: bytes):
|
||||||
try:
|
try:
|
||||||
blueprint = buf.decode("ascii")
|
blueprint = buf.decode("ascii")
|
||||||
|
|
||||||
tokens = tokenizer.tokenize(blueprint)
|
tokens = tokenizer.tokenize(blueprint)
|
||||||
ast, errors, warnings = parser.parse(tokens)
|
ast, errors, warnings = parser.parse(tokens)
|
||||||
|
|
||||||
|
if fuzz_level >= 1:
|
||||||
|
assert_ast_doesnt_crash(blueprint, tokens, ast)
|
||||||
|
|
||||||
xml = XmlOutput()
|
xml = XmlOutput()
|
||||||
if errors is None and ast is not None:
|
if errors is None and ast is not None:
|
||||||
xml.emit(ast)
|
xml.emit(ast)
|
||||||
|
@ -37,6 +40,17 @@ def fuzz(buf):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def assert_ast_doesnt_crash(text, tokens, ast):
|
||||||
|
lsp = LanguageServer()
|
||||||
|
for i in range(len(text) + 1):
|
||||||
|
ast.get_docs(i)
|
||||||
|
for i in range(len(text) + 1):
|
||||||
|
list(complete(lsp, ast, tokens, i))
|
||||||
|
for i in range(len(text) + 1):
|
||||||
|
ast.get_reference(i)
|
||||||
|
ast.get_document_symbols()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Make sure Gtk 4.0 is accessible, otherwise every test will fail on that
|
# Make sure Gtk 4.0 is accessible, otherwise every test will fail on that
|
||||||
# and nothing interesting will be tested
|
# and nothing interesting will be tested
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue