2021-05-11 21:16:55 +03:00
|
|
|
# Leo Test Framework
|
|
|
|
|
2022-05-02 22:40:14 +03:00
|
|
|
This directory includes Leo code samples, which are parsed and used as tests by `test-framework`.
|
2021-05-11 21:16:55 +03:00
|
|
|
|
|
|
|
## Structure
|
|
|
|
|
2022-05-02 22:40:14 +03:00
|
|
|
Currently, the test framework covers only two areas: compiler and parser; tests for both destinations are placed in
|
|
|
|
matching folders. The third folder - expectations - contains results of test execution which are saved in git and then
|
2021-05-11 21:16:55 +03:00
|
|
|
compared to test output.
|
|
|
|
|
|
|
|
## Test Structure
|
|
|
|
|
2022-05-02 22:40:14 +03:00
|
|
|
Tests can be placed either in the `compiler/` or in the `parser/` directories. Each test is a Leo file with correct (or intentionally
|
|
|
|
incorrect) Leo code. What makes Leo file a test is a block comment at the top of the file:
|
2021-05-11 21:16:55 +03:00
|
|
|
|
|
|
|
```
|
|
|
|
/*
|
|
|
|
namespace: Parse
|
|
|
|
expectation: Pass
|
|
|
|
*/
|
|
|
|
|
|
|
|
circuit X {
|
|
|
|
x: u32,
|
|
|
|
y: u32,
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
This comment contains YAML structure with set of mandatory and optional fields.
|
|
|
|
|
|
|
|
## Test Expectations
|
|
|
|
|
2022-05-02 22:40:14 +03:00
|
|
|
After an initial run of the tests, test expectations will be autogenerated and placed under the `expectations/` directory.
|
|
|
|
They will contain the results of execution in detail (for example, in the compiler tests, they include number of constraints and
|
2021-05-11 21:16:55 +03:00
|
|
|
output registers).
|
|
|
|
|
2022-05-02 22:40:14 +03:00
|
|
|
During subsequent test runs, the results of each test are compared to the stored expectations, and if the stored expectations (say, number
|
|
|
|
of constraints in Pedersen Hash example) don't match actual results, an error will be thrown and the test won't pass. Of course,
|
2021-05-11 21:16:55 +03:00
|
|
|
there are two possible scenarios:
|
|
|
|
|
2022-05-02 22:40:14 +03:00
|
|
|
1. If the test has failed because the logic was changed intentionally, then expectations need to be deleted. New ones will be
|
|
|
|
generated instead. A PR should contain changes to expectations as well as to tests or code.
|
|
|
|
2. If the test should pass, then expectations should not be changed or removed.
|
2021-05-11 21:16:55 +03:00
|
|
|
|
|
|
|
## Test Configuration
|
|
|
|
|
|
|
|
Here is the list of all possible configuration options for compiler and parser tests.
|
|
|
|
|
|
|
|
#### namespace
|
|
|
|
|
|
|
|
```
|
|
|
|
- Mandatory: yes
|
|
|
|
- Namespace: all
|
2022-05-02 22:40:14 +03:00
|
|
|
- Values: Compile / Parse
|
2021-05-11 21:16:55 +03:00
|
|
|
```
|
|
|
|
|
2022-05-02 22:40:14 +03:00
|
|
|
Only two values are supported: `Parse` and `Compile`. The former is meant to be a parser test, the latter
|
|
|
|
is a full compiler test.
|
2021-05-11 21:16:55 +03:00
|
|
|
|
2022-05-02 22:40:14 +03:00
|
|
|
Besides the `Parse` value,
|
|
|
|
there are actually additional possible values for this field:
|
|
|
|
`ParseStatement`, `ParseExpression`, and `Token`.
|
2021-05-11 21:16:55 +03:00
|
|
|
Each one of them allows testing Leo parser on different levels - lexer tokens or just expressions/statements.
|
|
|
|
|
|
|
|
Compiler tests always include complete Leo programs.
|
|
|
|
|
|
|
|
### expectation
|
|
|
|
|
|
|
|
```
|
|
|
|
- Mandatory: yes
|
|
|
|
- Namespace: all
|
|
|
|
- Values: Pass / Fail
|
|
|
|
```
|
|
|
|
|
2022-05-02 22:40:14 +03:00
|
|
|
This setting indicates whether the tested code is supposed to succeed or to fail.
|
|
|
|
If the test was marked as `Pass` but it actually failed,
|
|
|
|
you'll know that something went wrong and the test or the compiler/parser needs fixing.
|
2021-05-11 21:16:55 +03:00
|
|
|
|
|
|
|
### input_file (Compile)
|
|
|
|
|
|
|
|
```
|
|
|
|
- Mandatory: no
|
|
|
|
- Namespace: Compile
|
|
|
|
- Values: <input file path>, ...
|
|
|
|
```
|
|
|
|
|
2022-05-02 22:40:14 +03:00
|
|
|
This setting allows using one or more input files for the Leo program.
|
|
|
|
The program will be run with every provided input.
|
2021-05-11 21:16:55 +03:00
|
|
|
See this example:
|
|
|
|
|
|
|
|
```
|
|
|
|
/*
|
|
|
|
namespace: Compile
|
|
|
|
expectation: Pass
|
2022-05-02 22:40:14 +03:00
|
|
|
input_file:
|
2021-05-11 21:16:55 +03:00
|
|
|
- inputs/a_0.in
|
|
|
|
- inputs/a_1.in
|
|
|
|
*/
|
|
|
|
|
|
|
|
function main(a: u32) {}
|
|
|
|
```
|