leo/tests/README.md

60 lines
2.5 KiB
Markdown
Raw Normal View History

2021-05-11 21:16:55 +03:00
# Leo Test Framework
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
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
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"
2021-05-11 21:16:55 +03:00
*/
2022-09-30 20:48:47 +03:00
struct X {
2021-05-11 21:16:55 +03:00
x: u32,
y: u32,
}
```
This comment is a TOML document with some mandatory and optional fields.
2021-05-11 21:16:55 +03:00
## Test Expectations
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).
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:
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
There are several different values for the `namespace` test option.
2022-05-23 18:22:11 +03:00
Parser Directory namespaces:
2022-05-24 19:45:11 +03:00
- `Parse` - Test a file to check that it is a valid Leo program.
- `ParseExpression` - Test a file line by line to check that each line is a valid Leo expression.
- `ParseStatement` - Test a file consuming multiple lines till a blank line to check that it contains a valid Leo statement.
- `Serialize` - Test a file to check that it can be serialized to JSON.
- `Token` - Test a file line by line to check that it contains zero or more valid Leo parser tokens.
2021-05-11 21:16:55 +03:00
2022-05-23 18:22:11 +03:00
Compiler Directory namespaces:
2021-05-11 21:16:55 +03:00
2022-05-24 19:45:11 +03:00
- `Compiler` - Test a file to check that it is a valid Leo program, and it can be compiled without errors.
2023-09-29 18:13:49 +03:00
- `Execute` - Test a file to check that it is a valid Leo program, and it can be compiled and executed without errors.