Expand description
Testing infrastructure for debtmap using stillwater’s MockEnv.
This module provides testing utilities that enable fast, deterministic tests without real I/O operations. It includes:
DebtmapTestEnv: Mock environment implementingAnalysisEnvwith in-memory file system, coverage data, and cache- Assertion macros: Extended assertions for Result and Validation types
- Test helpers: Factory functions for creating test ASTs, configs, and coverage
- Property testing: Generators for proptest-based testing
§Why Use This Module?
Traditional tests using TempDir have several issues:
- Slow: File I/O adds 50-100ms per test
- Brittle: File system state can leak between tests
- Complex setup: Requires managing temp directories and cleanup
With DebtmapTestEnv, tests are:
- Fast: In-memory operations complete in microseconds
- Isolated: Each test gets fresh, independent state
- Simple: Fluent API for setting up test scenarios
§Quick Start
ⓘ
use debtmap::testkit::{DebtmapTestEnv, assert_result_ok};
use debtmap::env::AnalysisEnv;
#[test]
fn test_file_reading() {
let env = DebtmapTestEnv::new()
.with_file("test.rs", "fn main() {}");
let content = env.file_system().read_to_string("test.rs".as_ref());
let content = assert_result_ok!(content);
assert!(content.contains("fn main"));
}§Migration from TempDir
§Before (slow, ~50ms)
ⓘ
#[test]
fn test_analyze_file() {
let temp_dir = TempDir::new().unwrap();
let test_file = temp_dir.path().join("test.rs");
fs::write(&test_file, "fn main() {}").unwrap();
let result = analyze_file(&test_file).unwrap();
assert_eq!(result.functions.len(), 1);
}§After (fast, ~0.5ms)
ⓘ
use debtmap::testkit::{DebtmapTestEnv, assert_result_ok};
#[test]
fn test_analyze_file() {
let env = DebtmapTestEnv::new()
.with_file("test.rs", "fn main() {}");
let result = analyze_file_with_env("test.rs", &env);
let result = assert_result_ok!(result);
assert_eq!(result.functions.len(), 1);
}§Spec 200 Implementation
This module implements Specification 200: Testing Infrastructure with MockEnv. It completes the stillwater integration series (Specs 195-200).
Re-exports§
pub use helpers::create_complex_project;pub use helpers::create_coverage_data;pub use helpers::create_multi_function_ast;pub use helpers::create_nested_ast;pub use helpers::create_test_ast;pub use helpers::create_test_coverage;pub use helpers::create_test_project;pub use helpers::parse_test_code;pub use helpers::ConfigBuilder;pub use mock_env::DebtmapTestEnv;
Modules§
- assertions
- Assertion macros for testing debtmap operations.
- helpers
- Test helper functions for creating test data.
- mock_
env - Mock environment for testing debtmap analysis operations.