Skip to main content

Crate err_span_check

Crate err_span_check 

Source
Expand description

A test harness for checking and comparing compiler errors with a focus on error spans.

This crate is useful mainly for procedural macros, but can also be used in other contexts where compiler errors need to be verified.

It provides a way to verify that your macro underlines the correct part of the code with its errors, using in-file error annotations.

§Usage

  1. Add err_span_check to your dev-dependencies.
  2. Create a tests/fail directory in your project.
  3. Add .rs files with test cases in tests/fail.
  4. Create a test file (e.g. tests/test.rs) with the following content:
#[test]
fn compile_error_tests() {
    err_span_check::run_on_fail_dir();
}
  1. Run cargo test.

§Workflow

When running tests, err_span_check will automatically update your test files in tests/fail with the actual compiler errors. You inspect these changes using git diff and commit them if they are correct.

Note: All test cases in tests/fail must be at least staged in git.

See the README for more details.

Functions§

run_on_fail_dir
The entry point for this crate. Call this once inside of a test function.