diff --git a/.gitignore b/.gitignore index d43ea55..882a904 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ src/__pycache__/ +tests/__pycache__/ _build/ +.hypothesis/ diff --git a/Makefile b/Makefile index 66e57db..64921d5 100644 --- a/Makefile +++ b/Makefile @@ -14,11 +14,14 @@ test ! -d _build || rm -r _build tidy: _build/.stamp_venv - source _build/venv/bin/activate && black src + source _build/venv/bin/activate && black src tests grip: _build/.stamp_venv source _build/venv/bin/activate && grip +test: _build/.stamp_venv + source _build/venv/bin/activate && pytest --timeout=30 --timeout_method=thread + venv_bash: _build/.stamp_venv source _build/venv/bin/activate && bash _build: diff --git a/requirements.txt b/requirements.txt index 2f33ed0..f6600ad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,5 @@ black grip +pytest +pytest-timeout +hypothesis diff --git a/src/interp.py b/src/interp.py index 08585f3..2f0c8a5 100644 --- a/src/interp.py +++ b/src/interp.py @@ -1,7 +1,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # Copyright 2021 Jookia -import ast_types +from src import ast_types import sys diff --git a/src/main.py b/src/main.py index f3eaea3..cb0e0c7 100755 --- a/src/main.py +++ b/src/main.py @@ -2,9 +2,9 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # Copyright 2021 Jookia -import log -import parse -import interp +from src import log +from src import parse +from src import interp import sys diff --git a/src/parse.py b/src/parse.py index e031faa..1af5010 100644 --- a/src/parse.py +++ b/src/parse.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # Copyright 2021 Jookia -import log -import ast_types +from src import log +from src import ast_types class ParseLocation: diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..37db15a --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +# Dummy file to help pytest find the src module diff --git a/tests/test_parse.py b/tests/test_parse.py new file mode 100644 index 0000000..22e1588 --- /dev/null +++ b/tests/test_parse.py @@ -0,0 +1,15 @@ +from hypothesis import given +from hypothesis.strategies import binary + +from src import parse + + +@given(binary(), binary()) +def test_parser_fuzz(code, filename): + try: + tokenizer = parse.Tokenizer(code, filename) + tokens = tokenizer.tokenize() + parser = parse.Parser(tokens) + parser.parse_file() + except parse.ParseError: + pass