Crate cargo_is_tested

source ·
Expand description

cargo-is-tested


cargo-is-tested is a way to check which of your items are tested in which aren’t, very configurable and with a scripting-friendly API ready to use with your Git hooks.

Also, is uses ✨ pretty colors ✨ for error reporting.

You can also read the book for a more user-friendly guide.

Example

To check if all functions are tested in the current directory.

$ cargo is-tested .
# Cargo.toml
# [...]

[dependencies]
is_tested = "0.1.1" # Check crates.io for the current version of the crate.

# [...]
// src/main.rs

#! is-tested emptiness
// Yes, it uses shebangs to enable testing and flags!

use is_tested::is_tested;

#[is_tested("test/myfunction_testing_path.rs")]
fn my_function() {
	// [...]
}

Then, it will check if test/myfunction_testing_path.rs exists, if it doesn’t, it will output an error.

If the file exists, the program checks all lints against your test, assuring the best quality possible.

Installation and usage

⚠️ Installation isn’t currently possible because the project isn’t published yet.

To get started using cargo-is-tested, install the binary.

$ cargo install cargo-is-tested

Now document yourself about all the lints you can apply to your tests.

More lints will be added with time.


Once you know the lints you want to apply, import the attribute is_tested, then choose a struct, function or any item that you want to test, and add to that item the attribute #[is_tested("<path to the test>.rs")]

The result should be something like:

#! is-tested strict

use is_tested::is_tested;

#[is_tested("tests/mystruct.rs")]
struct MyStruct<'a> {
	string: &'a str
}

Don’t worry, the attribute won’t change anything in your code, it’s just a marker for a later-parser to know that you’re testing the item.


It’s time to run the parser, it will read check that all tested items are tested, and with the correct code quality dicted using the lints.

// tests/mystruct.rs

use mycrate::MyStruct;

fn main() {
	// [...]
}
$ cargo is-tested .

This will check that all tests are well written. You can use flags to customize your experience, for example, use --structs to check that all structs have tests associated, or use --test to, if all tests are confirmed, run cargo test automatically.

Modules

Macros

Functions