| Crates.io | should-it-compile |
| lib.rs | should-it-compile |
| version | 0.1.1 |
| created_at | 2024-12-28 07:59:16.684413+00 |
| updated_at | 2024-12-28 08:01:18.243294+00 |
| description | Verifies that a code sample compiles or does not compile. |
| homepage | |
| repository | https://github.com/youngspe/should-it-compile.rs |
| max_upload_size | |
| id | 1496941 |
| size | 14,178 |
This crate provides the macros
should_compile! and
should_not_compile!, which convert the given function definitions to doctests.
These tests verify that the code does or does not compile, respectively.
use should_it_compile::{should_compile, should_not_compile};
should_compile! {
fn code_that_should_compile() {
// This cose should compile.
}
}
should_not_compile! {
fn code_that_should_not_compile() {
compile_error!("This cose should compile.");
}
}
use should_it_compile::should_compile;
should_compile! {}
should_compile! {
prefix! {
// This will be inserted before the contents of each function.
}
fn test1() {
// This code should compile.
}
// The compilability expectation can be overridden with an attribute:
#[should_not_compile]
fn test2() {
compile_error!("This code should not compile.");
}
// Tests can be grouped into modules:
mod mod1 {
prefix! {
// This will be inserted after any enclosing prefix
}
fn test3() {
// This code should compile.
}
suffix! {
// This will be inserted before any enclosing suffix
}
}
// The compilability expectation can be overridden for a submodule:
#[should_not_compile]
mod mod2 {
fn test4() {
compile_error!("This code should not compile.");
}
// The compilability expectation can be overridden inside a submodule:
#[should_compile]
fn test5() {
// This code should compile
}
}
suffix! {
// This will be inserted after the contents of each function.
}
}
The tests should be part of a standard cargo test run or a cargo test --doc run.