1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//! TDD Tests for TDG File Score Storage - Simplified RED Phase
//!
//! These tests verify that TDG should store file scores but currently doesn't
use tempfile::TempDir;
#[test]
#[ignore] // TDD RED phase - Feature not implemented yet (PMAT-COVERAGE-002)
// This test runs cargo run multiple times (16+ minutes)
// Remove #[ignore] when implementing TDG storage feature
fn test_tdg_stores_scores_after_analysis() {
// This test verifies that when we run TDG analysis on a file,
// the score should be stored for future reference
// Arrange
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let test_file = temp_dir.path().join("test.rs");
std::fs::write(&test_file, "fn main() { println!(\"Hello\"); }")
.expect("Failed to write test file");
// Act - Run TDG analysis (using the CLI for now)
let output = std::process::Command::new("cargo")
.args([
"run",
"--package",
"pmat",
"--bin",
"pmat",
"--",
"tdg",
test_file.to_str().unwrap(),
])
.output()
.expect("Failed to run TDG");
// The analysis should succeed
assert!(output.status.success(), "TDG analysis should succeed");
// Now check if the score was stored
let storage_output = std::process::Command::new("cargo")
.args([
"run",
"--package",
"pmat",
"--bin",
"pmat",
"--",
"tdg",
"storage",
"stats",
])
.output()
.expect("Failed to check storage");
let storage_str = String::from_utf8_lossy(&storage_output.stdout);
// Assert - This will FAIL in RED phase because scores aren't being stored
assert!(
!storage_str.contains("Total: 0 entries"),
"Storage should contain at least 1 entry after analysis, but found: {}",
storage_str
);
}
#[test]
#[ignore] // TDD RED phase - Part of storage feature suite (PMAT-COVERAGE-002)
// Remove #[ignore] when implementing TDG storage feature
fn test_tdg_storage_is_empty_initially() {
// This test should PASS - verifying our storage starts empty
let output = std::process::Command::new("cargo")
.args([
"run",
"--package",
"pmat",
"--bin",
"pmat",
"--",
"tdg",
"storage",
"stats",
])
.output()
.expect("Failed to check storage");
let storage_str = String::from_utf8_lossy(&output.stdout);
// This should pass - storage is currently empty
assert!(
storage_str.contains("Total: 0 entries"),
"Storage should be empty initially"
);
}
#[test]
#[ignore] // TDD RED phase - Feature not implemented yet (PMAT-COVERAGE-002)
// This test runs cargo run 4 times (very slow)
// Remove #[ignore] when implementing TDG storage feature
fn test_tdg_should_track_multiple_file_scores() {
// This test verifies that TDG should track scores for multiple files
// It will FAIL because storage isn't implemented
let temp_dir = TempDir::new().expect("Failed to create temp dir");
// Create and analyze 3 test files
for i in 0..3 {
let test_file = temp_dir.path().join(format!("test{}.rs", i));
let content = format!("fn test{}() {{ println!(\"{}\"); }}", i, i);
std::fs::write(&test_file, content).expect("Failed to write test file");
// Run TDG analysis
let output = std::process::Command::new("cargo")
.args([
"run",
"--package",
"pmat",
"--bin",
"pmat",
"--",
"tdg",
test_file.to_str().unwrap(),
])
.output()
.expect("Failed to run TDG");
assert!(
output.status.success(),
"TDG analysis should succeed for file {}",
i
);
}
// Check storage stats
let storage_output = std::process::Command::new("cargo")
.args([
"run",
"--package",
"pmat",
"--bin",
"pmat",
"--",
"tdg",
"storage",
"stats",
])
.output()
.expect("Failed to check storage");
let storage_str = String::from_utf8_lossy(&storage_output.stdout);
// Assert - This will FAIL because storage isn't working
assert!(
!storage_str.contains("Total: 0 entries"),
"Storage should contain 3 entries after analyzing 3 files, but found: {}",
storage_str
);
}
/// This test documents the expected behavior for TDG dogfooding
#[test]
#[ignore] // TDD RED phase - Documentation test that intentionally panics (PMAT-COVERAGE-002)
// This documents future requirements, not a current bug
// Remove #[ignore] when implementing TDG storage feature
fn test_tdg_dogfooding_requirement() {
// REQUIREMENT: TDG should dogfood its own quality metrics
// by storing and tracking scores for all analyzed files
// Current state: FAILING - scores are calculated but not stored
// Expected state: All TDG analyses should persist scores for:
// 1. Historical tracking
// 2. Trend analysis
// 3. Quality gate comparisons
// 4. Cache optimization
// This is a documentation test that always fails in RED phase
panic!("TDG dogfooding not implemented: File scores are not being stored");
}