Grammar tests are data-driven instead of being specified explicitly. This document explains how to add a new grammar test.
Adding a grammar test¶
Create a new file with the extension
tests/resources/grammardirectory or any subdirectory. Give the file a descriptive name, since the file name becomes part of the test name.
By convention, the names of files that should not contain syntax errors should be prefixed with
good-and the names of files that should contain syntax errors with
bad-. This is irrelevant for the test runner, but it helps to keep the tests organized.
Skipping a test
If you want to skip a test, add the prefix
skip-to the file name.
If you want to assert that a file is parsed without a syntax error1, add the following comment to the file:
The two comments are mutually exclusive. You must have exactly one in a grammar test file.
By convention, the comment should be placed at the start of the file.
Add the Safe-DS code that you want to test to the file.
- Run the tests. The test runner will automatically pick up the new test.
We do not differentiate whether the error originated in the lexer (error code
lexing-error) or the actual parser (error code
parsing-error). Both are treated as syntax errors. ↩