|
3 | 3 | The integration tests test the compiler end-to-end, with one of the following goals: |
4 | 4 |
|
5 | 5 | 1. Observing a correct write to standard output |
6 | | -2. Observing a specific error code |
| 6 | +2. Observing a specific error message |
7 | 7 |
|
8 | | -For now, neither of these cases are possible. But, here is the plan for generating tests in the future: |
| 8 | +This is accomplished through two special kinds of comments in the source code. |
9 | 9 |
|
10 | | -1. Create the associated .poni file |
11 | | -2. Create a new entry in /build/build_tests.rs that describes the .poni file name |
12 | | -3. Create the expected test result |
13 | | - - This may involve one of the following as-of-yet undecided mechanisms: |
14 | | - 1. Create a comment in the .poni file, such as // Expected: "result" |
15 | | - 2. Create a #directive or similar in the .poni file describing the result |
16 | | - 3. Simply add the information to build_tests.rs directly (this is likely the most straightforward, but makes the test scripts less directly useful). |
| 10 | +To test outputs, use `//!`. Each of these comments denotes exactly one line expected in the output. Additionally, the expected text is always trimmed. This means you can test lines of output like so: |
17 | 11 |
|
18 | | -Finally, in order to do error codes, the following mechanism is used: |
| 12 | +```poniescript |
| 13 | +fun init() { |
| 14 | + print("hello"); //! hello |
| 15 | + print("world"); //! world |
| 16 | +} |
| 17 | +``` |
19 | 18 |
|
20 | | -1. Each error that we add to the compiler is given a UUID, created with `uuidgen -r`. |
21 | | -2. The test simply expects an error with a given UUID. (Perhaps as well with a location, but this is less certain as those may be unstable). |
| 19 | +Notice that we do not have to explicitly list the newline anywhere. Also notice that we do nonetheless *expect* there to be a newline. |
22 | 20 |
|
23 | | -It should be the case that the UUIDs never collide, due to the relatively small number of errors in the compiler. Note importantly that the code for an error should generally not change. If it does, of course, the affected tests will have to be fixed. |
| 21 | +To test error messages, use `//?`. Each of these denotes exactly one expected error message. So, for example, |
| 22 | +```poniescript |
| 23 | +//? Expected ')' after parenthesized expression, got ';' |
| 24 | +//? Expected 'var', 'const', 'class', or 'fun', got '<EOF>' |
| 25 | +var x = 2 * (3 + 4; |
| 26 | +``` |
24 | 27 |
|
25 | | -## Other checks |
| 28 | +Note that these are exact error messages. So in this example, although we're really trying to test the ')' error message, we must also include a second error message for the missing keyword. If the parser is ever updated to not report that second error, we will want to remove it from this test. |
| 29 | + |
| 30 | +This does mean that the error tests are much more fragile than the exepcted output tests. In particular, the expected output tests should keep working barring a change in actual language semantics, while the error tests will break just due to a change in error reporting (and this can be in the parser, the typechecker, etc). So, the intended path of development is that, whenever an error message is changed, simply update the relevant tests at that time. |
| 31 | + |
| 32 | +## Future work |
26 | 33 |
|
27 | 34 | Some other test conditions we could consider including in the future include: |
28 | 35 |
|
|
0 commit comments