dylint_testing
This crate provides convenient access to the compiletest_rs package for testing Dylint libraries.
Specifically, this crate provides the following three functions. Note: If your test has dependencies, you must use ui_test_example or ui_test_examples. See the question_mark_in_expression example in this repository.
-
ui_test- test a library on all source files in a directorynameis the name of a Dylint library to be tested. (Often, this is the same as the package name.)src_baseis a directory containing:- source files on which to test the library (
.rsfiles), and - the output those files should produce (
.stderrfiles).
- source files on which to test the library (
-
ui_test_example- test a library on one example targetnameis the name of a Dylint library to be tested.exampleis an example target on which to test the library.
-
ui_test_examples- test a library on all example targetsnameis the name of a Dylint library to be tested.
For most situations, you can add the following to your library's lib.rs file:
And include one or more .rs and .stderr files in a ui directory alongside your library's src directory. See the examples in this repository.
Updating .stderr files
If the standard error that results from running your .rs file differs from the contents of your .stderr file, compiletest_rs will produce a report like the following:
diff of stderr:
error: calling `set_var` in a test could affect the outcome of other tests
-/main.rs:8:5
|
LL | set_var;
= note: `-D nonreentrant-function-in-test` implied by `-D warnings`
-error: aborting due to previous error
+error: calling `set_var` in a test could affect the outcome of other tests
+ -/main.rs:23:9
+ |
+LL | set_var;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
The actual stderr differed from the expected stderr.
Actual stderr saved to ...
The meaning of each line is as follows:
- A line beginning with a plus (
+) is in the actual standard error, but not in your.stderrfile. - A line beginning with a minus (
-) is in your.stderrfile, but not in the actual standard error. - A line beginning with a space (
) is in both the actual standard error and your.stderrfile, and is provided for context. - All other lines (e.g.,
diff of stderr:) containcompiletest_rsmessages.
Note: In the actual standard error, a blank line usually follows the error: aborting due to N previous errors line. So a correct .stderr file will typically contain one blank line at the end.
In general, it is not too hard to update a .stderr file by hand. However, the compiletest_rs report should contain a line of the form Actual stderr saved to PATH. Copying PATH to your .stderr file should update it completely.
Additional documentation on compiletest_rs can be found in its repository.