Skip to content

Commit 2b8248e

Browse files
committed
Add property-based tests for parser and type checker
Use `proptest` to assert that the parser and type checker never panic on arbitrary input, and that well-formed programs drawn from a small grammar parse and type check without errors. The regression file is checked in so the failing cases we've already found are rerun on each test run. The property tests uncovered three real bugs, which are also fixed here: - The lexer panicked on non-ASCII whitespace because it advanced by one byte rather than the character's UTF-8 length. - The lexer panicked on unrecognized non-ASCII characters for the same reason when constructing the "unrecognized syntax" diagnostic. - `parse_tuple_literal_or_parentheses` hit a forward-progress assertion on inputs like `(,{` where the inner expression parser emitted a diagnostic without consuming a token. It now breaks out of the loop instead.
1 parent d3f0dbb commit 2b8248e

File tree

7 files changed

+408
-18
lines changed

7 files changed

+408
-18
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
**Goal: Better REPL experience.**
33
**Goal: Offer actions when runtime errors occur.**
44

5+
## Parser
6+
7+
Fixed a panic in the lexer when the input contained non-ASCII
8+
whitespace or unrecognized non-ASCII characters.
9+
10+
Fixed an assertion failure in the parser when a tuple literal
11+
contained a token that could not start an expression (e.g. `(,{`).
12+
13+
## Testing
14+
15+
Added property-based tests (using `proptest`) for the parser and type
16+
checker. These assert that the parser and type checker never panic on
17+
arbitrary input, and that well-formed programs drawn from a small
18+
grammar parse and type check cleanly.
19+
520
## Checks
621

722
Added a warning when all code paths in a function return the same

Cargo.lock

Lines changed: 108 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ assert_cmd = "2.0.14"
4747
escargot = "0.5"
4848
goldentests = "1.1.1"
4949
predicates = "3"
50+
proptest = "1.5"
5051

5152
[profile.release]
5253
opt-level = "s"

proptest-regressions/parser.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Seeds for failure cases proptest has generated in the past. It is
2+
# automatically read and these particular cases re-run before any
3+
# novel cases are generated.
4+
#
5+
# It is recommended to check this file in to source control so that
6+
# everyone who runs the test benefits from these saved cases.
7+
cc 6e4163cef3b83d46ada9f7396d453a11a15d5db48b13c35acfcb81e705b195ca # shrinks to src = "({ let v_a = 0 0 } == 0)"
8+
cc 071174ad58463d80cc8a81f56ddc19058349221676b2affdfe5754af97271921 # shrinks to src = "fun v_a() { ({ let v_a = 0 0 } - 0) }"
9+
cc 66aae6bce59293271a3e28704a6cccba3dd46b4e2edf268d9e91189f0d999c19 # shrinks to src = "ල"
10+
cc 68d49a1eb4670e73cacec4ff1f8e80e43f6aaa08eb7763395d0a3f057d603d93 # shrinks to src = "0¡"
11+
cc 143c7d57c4fa73d032bc4a20b7eabe98c1be20f0f3e76df1cc3f9e4b9a8c1253 # shrinks to src = "\u{a0}"
12+
cc b1e6ee18e2705b42c49fdfa6e42c948a921eab25e9ef23682a6ac94079596205 # shrinks to src = "(,{"

0 commit comments

Comments
 (0)