Skip to content

Commit 3b89dee

Browse files
unhappychoiceclaude
andcommitted
fix(tests): fix test failures by excluding tmp/** pattern in temp directories
- Add test_extraction_options() helper function to exclude **/tmp/** pattern - Fix all integration tests to use helper instead of ExtractionOptions::default() - Resolve issue where test files in temp directories were being excluded - Update unit tests with proper ExtractionOptions for temp directory usage - All 171 tests now pass (unit, integration, and feature tests) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 646900c commit 3b89dee

File tree

18 files changed

+222
-141
lines changed

18 files changed

+222
-141
lines changed

tests/extractor_unit_tests.rs

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
use gittype::extractor::models::language::LanguageRegistry;
12
use gittype::extractor::{
2-
ChallengeConverter, ChunkType, CodeExtractor, ExtractionOptions, Language, RepositoryLoader,
3+
ChallengeConverter, ChunkType, CodeExtractor, ExtractionOptions, RepositoryLoader,
34
};
45
use gittype::GitTypeError;
56
use std::fs;
@@ -19,16 +20,43 @@ fn test_extraction_options_default() {
1920

2021
#[test]
2122
fn test_language_from_extension() {
22-
assert_eq!(Language::from_extension("rs"), Some(Language::Rust));
23-
assert_eq!(Language::from_extension("ts"), Some(Language::TypeScript));
24-
assert_eq!(Language::from_extension("tsx"), Some(Language::TypeScript));
25-
assert_eq!(Language::from_extension("js"), Some(Language::JavaScript));
26-
assert_eq!(Language::from_extension("mjs"), Some(Language::JavaScript));
27-
assert_eq!(Language::from_extension("cjs"), Some(Language::JavaScript));
28-
assert_eq!(Language::from_extension("py"), Some(Language::Python));
29-
assert_eq!(Language::from_extension("rb"), Some(Language::Ruby));
30-
assert_eq!(Language::from_extension("go"), Some(Language::Go));
31-
assert_eq!(Language::from_extension("unknown"), None);
23+
assert_eq!(
24+
LanguageRegistry::from_extension("rs").map(|l| l.name().to_string()),
25+
Some("rust".to_string())
26+
);
27+
assert_eq!(
28+
LanguageRegistry::from_extension("ts").map(|l| l.name().to_string()),
29+
Some("typescript".to_string())
30+
);
31+
assert_eq!(
32+
LanguageRegistry::from_extension("tsx").map(|l| l.name().to_string()),
33+
Some("typescript".to_string())
34+
);
35+
assert_eq!(
36+
LanguageRegistry::from_extension("js").map(|l| l.name().to_string()),
37+
Some("javascript".to_string())
38+
);
39+
assert_eq!(
40+
LanguageRegistry::from_extension("mjs").map(|l| l.name().to_string()),
41+
Some("javascript".to_string())
42+
);
43+
assert_eq!(
44+
LanguageRegistry::from_extension("cjs").map(|l| l.name().to_string()),
45+
Some("javascript".to_string())
46+
);
47+
assert_eq!(
48+
LanguageRegistry::from_extension("py").map(|l| l.name().to_string()),
49+
Some("python".to_string())
50+
);
51+
assert_eq!(
52+
LanguageRegistry::from_extension("rb").map(|l| l.name().to_string()),
53+
Some("ruby".to_string())
54+
);
55+
assert_eq!(
56+
LanguageRegistry::from_extension("go").map(|l| l.name().to_string()),
57+
Some("go".to_string())
58+
);
59+
assert_eq!(LanguageRegistry::from_extension("unknown"), None);
3260
}
3361

3462
#[test]
@@ -59,22 +87,45 @@ fn test_gitignore_respected() {
5987
let target_file = temp_dir.path().join("target/debug/main.rs");
6088
let log_file = temp_dir.path().join("debug.log.rs");
6189

62-
let rust_code = r#"fn test() {}"#;
90+
let rust_code = r#"
91+
fn main() {
92+
println!("Hello, world!");
93+
}
94+
95+
fn test_function() {
96+
// This is a test function
97+
}
98+
99+
struct TestStruct {
100+
value: i32,
101+
}
102+
"#;
63103
fs::write(&src_file, rust_code).unwrap();
64104
fs::write(&target_file, rust_code).unwrap();
65105
fs::write(&log_file, rust_code).unwrap();
66106

67107
let mut extractor = CodeExtractor::new().unwrap();
68-
let chunks = extractor
69-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
70-
.unwrap();
108+
let mut options = ExtractionOptions::default();
109+
// Remove tmp/** pattern for this test since we're using a temp directory
110+
options.exclude_patterns.retain(|p| p != "**/tmp/**");
111+
112+
let chunks = extractor.extract_chunks(temp_dir.path(), options).unwrap();
113+
114+
// Should find multiple chunks (functions + struct) but all from src/main.rs
115+
assert!(
116+
chunks.len() >= 3,
117+
"Expected at least 3 chunks, found {}",
118+
chunks.len()
119+
);
71120

72-
// Should only find src/main.rs
73-
assert_eq!(chunks.len(), 1);
74-
assert!(chunks[0]
75-
.file_path
76-
.to_string_lossy()
77-
.contains("src/main.rs"));
121+
// All chunks should be from src/main.rs (not from target/ or debug.log.rs)
122+
for chunk in &chunks {
123+
assert!(
124+
chunk.file_path.to_string_lossy().contains("src/main.rs"),
125+
"Found chunk from unexpected file: {}",
126+
chunk.file_path.display()
127+
);
128+
}
78129
assert!(!chunks[0].file_path.to_string_lossy().contains("target"));
79130

80131
for chunk in &chunks {
@@ -93,7 +144,7 @@ fn test_convert_chunk_to_challenge() {
93144
file_path: PathBuf::from("src/main.rs"),
94145
start_line: 10,
95146
end_line: 12,
96-
language: Language::Rust,
147+
language: "rust".to_string(),
97148
chunk_type: ChunkType::Function,
98149
name: "test".to_string(),
99150
comment_ranges: vec![],
@@ -131,8 +182,12 @@ struct Person {
131182
fs::write(&file_path, rust_code).unwrap();
132183

133184
let mut loader = RepositoryLoader::new().unwrap();
185+
let mut options = ExtractionOptions::default();
186+
// Remove tmp/** pattern for this test since we're using a temp directory
187+
options.exclude_patterns.retain(|p| p != "**/tmp/**");
188+
134189
let challenges = loader
135-
.load_challenges_from_repository(temp_dir.path(), None)
190+
.load_challenges_from_repository(temp_dir.path(), Some(options))
136191
.unwrap();
137192

138193
// Repository loader may filter out too-small chunks by difficulty thresholds.
@@ -205,7 +260,9 @@ class TsClass{} {{
205260
}
206261

207262
let mut extractor = CodeExtractor::new().unwrap();
208-
let options = ExtractionOptions::default();
263+
let mut options = ExtractionOptions::default();
264+
// Remove tmp/** pattern for this test since we're using a temp directory
265+
options.exclude_patterns.retain(|p| p != "**/tmp/**");
209266

210267
let start = Instant::now();
211268
let chunks = extractor.extract_chunks(temp_dir.path(), options).unwrap();

tests/integration/languages/c.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use gittype::extractor::{ChunkType, CodeExtractor, ExtractionOptions};
1+
use crate::integration::test_extraction_options;
2+
use gittype::extractor::{ChunkType, CodeExtractor};
23
use std::fs;
34
use tempfile::TempDir;
45

@@ -25,7 +26,7 @@ void print_number(int num) {
2526

2627
let mut extractor = CodeExtractor::new().unwrap();
2728
let chunks = extractor
28-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
29+
.extract_chunks(temp_dir.path(), test_extraction_options())
2930
.unwrap();
3031

3132
println!("Found {} chunks:", chunks.len());
@@ -68,7 +69,7 @@ int main() {
6869

6970
let mut extractor = CodeExtractor::new().unwrap();
7071
let chunks = extractor
71-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
72+
.extract_chunks(temp_dir.path(), test_extraction_options())
7273
.unwrap();
7374

7475
// Find struct chunks
@@ -103,7 +104,7 @@ int main() {
103104

104105
let mut extractor = CodeExtractor::new().unwrap();
105106
let chunks = extractor
106-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
107+
.extract_chunks(temp_dir.path(), test_extraction_options())
107108
.unwrap();
108109

109110
// Find variable chunks
@@ -146,7 +147,7 @@ static inline int max(int a, int b) {
146147

147148
let mut extractor = CodeExtractor::new().unwrap();
148149
let chunks = extractor
149-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
150+
.extract_chunks(temp_dir.path(), test_extraction_options())
150151
.unwrap();
151152

152153
// Find function chunks (both declarations and definitions)
@@ -202,7 +203,7 @@ int process_user(User *user, enum Status *status) {
202203

203204
let mut extractor = CodeExtractor::new().unwrap();
204205
let chunks = extractor
205-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
206+
.extract_chunks(temp_dir.path(), test_extraction_options())
206207
.unwrap();
207208

208209
assert!(!chunks.is_empty());

tests/integration/languages/cpp.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use gittype::extractor::{ChunkType, CodeExtractor, ExtractionOptions};
1+
use crate::integration::test_extraction_options;
2+
use gittype::extractor::{ChunkType, CodeExtractor};
23
use std::fs;
34
use tempfile::TempDir;
45

@@ -31,7 +32,7 @@ double calculate_area(double radius) {
3132

3233
let mut extractor = CodeExtractor::new().unwrap();
3334
let chunks = extractor
34-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
35+
.extract_chunks(temp_dir.path(), test_extraction_options())
3536
.unwrap();
3637

3738
println!("Found {} chunks:", chunks.len());
@@ -102,7 +103,7 @@ int main() {
102103

103104
let mut extractor = CodeExtractor::new().unwrap();
104105
let chunks = extractor
105-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
106+
.extract_chunks(temp_dir.path(), test_extraction_options())
106107
.unwrap();
107108

108109
println!("Found {} chunks:", chunks.len());
@@ -170,7 +171,7 @@ int main() {
170171

171172
let mut extractor = CodeExtractor::new().unwrap();
172173
let chunks = extractor
173-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
174+
.extract_chunks(temp_dir.path(), test_extraction_options())
174175
.unwrap();
175176

176177
println!("Found {} chunks:", chunks.len());
@@ -254,7 +255,7 @@ int main() {
254255

255256
let mut extractor = CodeExtractor::new().unwrap();
256257
let chunks = extractor
257-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
258+
.extract_chunks(temp_dir.path(), test_extraction_options())
258259
.unwrap();
259260

260261
println!("Found {} chunks:", chunks.len());
@@ -342,7 +343,7 @@ int main() {
342343

343344
let mut extractor = CodeExtractor::new().unwrap();
344345
let chunks = extractor
345-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
346+
.extract_chunks(temp_dir.path(), test_extraction_options())
346347
.unwrap();
347348

348349
println!("Found {} chunks:", chunks.len());
@@ -407,7 +408,7 @@ int main() {
407408

408409
let mut extractor = CodeExtractor::new().unwrap();
409410
let chunks = extractor
410-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
411+
.extract_chunks(temp_dir.path(), test_extraction_options())
411412
.unwrap();
412413

413414
println!("Found {} chunks:", chunks.len());

tests/integration/languages/csharp.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use gittype::extractor::{ChunkType, CodeExtractor, ExtractionOptions};
1+
use crate::integration::test_extraction_options;
2+
use gittype::extractor::{ChunkType, CodeExtractor};
23
use std::fs;
34
use tempfile::TempDir;
45

@@ -39,7 +40,7 @@ namespace MyApplication.Services
3940

4041
let mut extractor = CodeExtractor::new().unwrap();
4142
let chunks = extractor
42-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
43+
.extract_chunks(temp_dir.path(), test_extraction_options())
4344
.unwrap();
4445

4546
// Should find namespace and class
@@ -91,7 +92,7 @@ namespace MyApplication.Contracts
9192

9293
let mut extractor = CodeExtractor::new().unwrap();
9394
let chunks = extractor
94-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
95+
.extract_chunks(temp_dir.path(), test_extraction_options())
9596
.unwrap();
9697

9798
let interface_chunks: Vec<_> = chunks
@@ -150,7 +151,7 @@ namespace MyApplication.Models
150151

151152
let mut extractor = CodeExtractor::new().unwrap();
152153
let chunks = extractor
153-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
154+
.extract_chunks(temp_dir.path(), test_extraction_options())
154155
.unwrap();
155156

156157
let struct_chunks: Vec<_> = chunks
@@ -207,7 +208,7 @@ namespace MyApplication.Models
207208

208209
let mut extractor = CodeExtractor::new().unwrap();
209210
let chunks = extractor
210-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
211+
.extract_chunks(temp_dir.path(), test_extraction_options())
211212
.unwrap();
212213

213214
// Should find class and properties
@@ -259,7 +260,7 @@ namespace MyApplication.Core.Models
259260

260261
let mut extractor = CodeExtractor::new().unwrap();
261262
let chunks = extractor
262-
.extract_chunks(temp_dir.path(), ExtractionOptions::default())
263+
.extract_chunks(temp_dir.path(), test_extraction_options())
263264
.unwrap();
264265

265266
let namespace_chunks: Vec<_> = chunks

0 commit comments

Comments
 (0)