# cargo-extract-test
A Cargo subcommand to extract, compile and run a single test function in isolation.
## ๐ Purpose
cargo-extract-test allows you to:
Extract a specific test function from your project.
Compile and run it in isolation using cargo test --test.
Quickly debug or isolate failing tests without compiling and running the entire test suite.
## โ๏ธ Installation
Option 1: Local Installation
## ๐งช Usage
To extract and run a specific test function:
```bash
cargo extract-test <test_function_name> [-- <cargo test args>]
```
For example:
```bash
cargo extract-test my_test_function -- --nocapture
```
This command:
Extracts my_test_function into a temporary test file.
Runs it using cargo test --test __temp_test, passing any additional arguments.
## ๐ How It Works
The tool searches your project's source and test directories for the specified test function.
It copies the test function and any necessary use statements into a temporary file.
It compiles and runs the test in isolation, providing immediate feedback.
## ๐ฆ Dependencies
walkdir: For recursively searching directories.
## ๐งช Example
Given a test function:
```rust
#[cfg(test)]
mod tests {
#[test]
fn my_test_function() {
assert_eq!(2 + 2, 4);
}
}
```
## Running:
```bash
cargo extract-test my_test_function -- --nocapture
```
Will extract and run my_test_function in isolation.
## ๐ License
This project is licensed under the MIT License.