kimun 0.20.0

Code metrics tool — health score, complexity, duplication, hotspots, ownership
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
use std::fs;
use std::path::Path;

use tempfile::tempdir;

use super::*;

/// Shorthand for the empty walk root used in unit tests where
/// paths are bare filenames (not rooted in a real directory).
const ROOT: &str = "";

// ── ExcludeFilter::new ─────────────────────────────────────────────────

#[test]
fn exclude_filter_empty() {
    let f = ExcludeFilter::new(&[], &[], &[], &[]);
    assert!(!f.excludes_dir("vendor"));
    assert!(!f.excludes_file(Path::new("foo.rs"), Path::new(ROOT)));
    assert!(f.is_empty());
}

#[test]
fn exclude_filter_is_empty() {
    let f = ExcludeFilter::new(&[], &["js".to_string()], &[], &[]);
    assert!(!f.is_empty());
    let f = ExcludeFilter::new(&[], &[], &["vendor".to_string()], &[]);
    assert!(!f.is_empty());
    let f = ExcludeFilter::new(&[], &[], &[], &["*.js".to_string()]);
    assert!(!f.is_empty());
    let f = ExcludeFilter::new(&["rs".to_string()], &[], &[], &[]);
    assert!(!f.is_empty());
}

// ── Include-ext (allowlist mode) ─────────────────────────────────────

#[test]
fn include_ext_only_matching_pass() {
    let f = ExcludeFilter::new(&["rs".to_string()], &[], &[], &[]);
    assert!(
        !f.excludes_file(Path::new("main.rs"), Path::new(ROOT)),
        "rs files should pass"
    );
    assert!(
        f.excludes_file(Path::new("app.js"), Path::new(ROOT)),
        "js files should be excluded"
    );
    assert!(
        f.excludes_file(Path::new("style.css"), Path::new(ROOT)),
        "css files should be excluded"
    );
}

#[test]
fn include_ext_case_insensitive() {
    let f = ExcludeFilter::new(&["RS".to_string()], &[], &[], &[]);
    assert!(!f.excludes_file(Path::new("main.rs"), Path::new(ROOT)));
    assert!(!f.excludes_file(Path::new("lib.RS"), Path::new(ROOT)));
    assert!(f.excludes_file(Path::new("app.js"), Path::new(ROOT)));
}

#[test]
fn include_ext_multiple() {
    let f = ExcludeFilter::new(&["rs".to_string(), "toml".to_string()], &[], &[], &[]);
    assert!(!f.excludes_file(Path::new("main.rs"), Path::new(ROOT)));
    assert!(!f.excludes_file(Path::new("Cargo.toml"), Path::new(ROOT)));
    assert!(f.excludes_file(Path::new("app.js"), Path::new(ROOT)));
}

#[test]
fn include_ext_excludes_extensionless_files() {
    let f = ExcludeFilter::new(&["rs".to_string()], &[], &[], &[]);
    assert!(
        f.excludes_file(Path::new("Makefile"), Path::new(ROOT)),
        "files without extension excluded when include list is set"
    );
}

#[test]
fn include_ext_integration() {
    let dir = tempdir().unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();
    fs::write(dir.path().join("lib.js"), "export {};").unwrap();
    fs::write(dir.path().join("style.css"), "body {}").unwrap();

    let filter = ExcludeFilter::new(&["rs".to_string()], &[], &[], &[]);
    let files = source_files(dir.path(), false, &filter);

    assert_eq!(files.len(), 1, "only rs files should pass");
    assert_eq!(files[0].0.file_name().unwrap().to_str().unwrap(), "main.rs");
}

#[test]
fn exclude_filter_extension_normalises_dot_and_case() {
    // ".JS", "JS", "js", ".js" should all match foo.js
    for raw in [".JS", "JS", "js", ".js"] {
        let f = ExcludeFilter::new(&[], &[raw.to_string()], &[], &[]);
        assert!(
            f.excludes_file(Path::new("foo.js"), Path::new(ROOT)),
            "'{raw}' should exclude foo.js"
        );
        assert!(
            f.excludes_file(Path::new("bar.JS"), Path::new(ROOT)),
            "'{raw}' should exclude bar.JS (case-insensitive extension)"
        );
        assert!(
            !f.excludes_file(Path::new("foo.rs"), Path::new(ROOT)),
            "should not exclude foo.rs"
        );
    }
}

#[test]
fn exclude_filter_multiple_extensions() {
    let exts = vec!["js".to_string(), "ts".to_string()];
    let f = ExcludeFilter::new(&[], &exts, &[], &[]);
    assert!(f.excludes_file(Path::new("app.js"), Path::new(ROOT)));
    assert!(f.excludes_file(Path::new("app.ts"), Path::new(ROOT)));
    assert!(!f.excludes_file(Path::new("app.rs"), Path::new(ROOT)));
}

#[test]
fn exclude_filter_no_extension_file_not_excluded() {
    let f = ExcludeFilter::new(&[], &["rs".to_string()], &[], &[]);
    // Files without an extension should never be excluded by an ext filter
    assert!(!f.excludes_file(Path::new("Makefile"), Path::new(ROOT)));
    assert!(!f.excludes_file(Path::new("Dockerfile"), Path::new(ROOT)));
}

#[test]
fn exclude_filter_dir_exact_match() {
    let f = ExcludeFilter::new(&[], &[], &["vendor".to_string(), "dist".to_string()], &[]);
    assert!(f.excludes_dir("vendor"));
    assert!(f.excludes_dir("dist"));
    assert!(!f.excludes_dir("src"));
    assert!(!f.excludes_dir("Vendor")); // case-sensitive
}

#[test]
fn exclude_filter_compound_extension() {
    // "foo.min.js" has extension "js", not "min.js"
    // Excluding "js" should match; excluding "min.js" should not
    let f = ExcludeFilter::new(&[], &["js".to_string()], &[], &[]);
    assert!(
        f.excludes_file(Path::new("app.min.js"), Path::new(ROOT)),
        "foo.min.js has extension 'js' and should be excluded"
    );

    let f2 = ExcludeFilter::new(&[], &["min.js".to_string()], &[], &[]);
    assert!(
        !f2.excludes_file(Path::new("app.min.js"), Path::new(ROOT)),
        "compound 'min.js' is not a real extension and should not match"
    );
}

#[test]
fn exclude_filter_empty_string_extension_ignored() {
    // Passing an empty string or just "." should not create a match-all rule
    let f = ExcludeFilter::new(&[], &["".to_string(), ".".to_string()], &[], &[]);
    // Neither dirs nor extensions should match anything
    assert!(!f.excludes_dir("anything"));
    assert!(!f.excludes_file(Path::new("foo.rs"), Path::new(ROOT)));
}

#[test]
fn exclude_filter_combined_ext_and_dir() {
    let f = ExcludeFilter::new(
        &[],
        &["js".to_string(), "css".to_string()],
        &["vendor".to_string(), "dist".to_string()],
        &[],
    );
    // Extensions
    assert!(f.excludes_file(Path::new("app.js"), Path::new(ROOT)));
    assert!(f.excludes_file(Path::new("style.css"), Path::new(ROOT)));
    assert!(!f.excludes_file(Path::new("main.rs"), Path::new(ROOT)));
    // Directories
    assert!(f.excludes_dir("vendor"));
    assert!(f.excludes_dir("dist"));
    assert!(!f.excludes_dir("src"));
}

// ── Glob pattern matching ───────────────────────────────────────────────

#[test]
fn exclude_filter_glob_matches_filename() {
    let f = ExcludeFilter::new(&[], &[], &[], &["*.min.js".to_string()]);
    assert!(
        f.excludes_file(Path::new("app.min.js"), Path::new(ROOT)),
        "*.min.js should match app.min.js"
    );
    assert!(
        !f.excludes_file(Path::new("app.js"), Path::new(ROOT)),
        "*.min.js should not match app.js"
    );
}

#[test]
fn exclude_filter_glob_matches_path_pattern() {
    let f = ExcludeFilter::new(&[], &[], &[], &["vendor/**".to_string()]);
    assert!(
        f.excludes_file(Path::new("vendor/dep.rs"), Path::new(ROOT)),
        "vendor/** should match vendor/dep.rs"
    );
    assert!(
        f.excludes_file(Path::new("vendor/sub/dep.rs"), Path::new(ROOT)),
        "vendor/** should match nested vendor/sub/dep.rs"
    );
    assert!(
        !f.excludes_file(Path::new("src/main.rs"), Path::new(ROOT)),
        "vendor/** should not match src/main.rs"
    );
}

#[test]
fn exclude_filter_glob_multiple_patterns() {
    let f = ExcludeFilter::new(
        &[],
        &[],
        &[],
        &["*.min.js".to_string(), "*.bundle.js".to_string()],
    );
    assert!(f.excludes_file(Path::new("app.min.js"), Path::new(ROOT)));
    assert!(f.excludes_file(Path::new("main.bundle.js"), Path::new(ROOT)));
    assert!(!f.excludes_file(Path::new("app.js"), Path::new(ROOT)));
}

#[test]
fn exclude_filter_glob_combined_with_ext_and_dir() {
    let f = ExcludeFilter::new(
        &[],
        &["css".to_string()],
        &["dist".to_string()],
        &["*.min.js".to_string()],
    );
    assert!(
        f.excludes_file(Path::new("style.css"), Path::new(ROOT)),
        "ext filter"
    );
    assert!(f.excludes_dir("dist"), "dir filter");
    assert!(
        f.excludes_file(Path::new("app.min.js"), Path::new(ROOT)),
        "glob filter"
    );
    assert!(
        !f.excludes_file(Path::new("app.js"), Path::new(ROOT)),
        "not matched by any"
    );
}

#[test]
fn exclude_filter_invalid_glob_skipped() {
    // An invalid glob pattern should not cause a panic, just be skipped
    let f = ExcludeFilter::new(&[], &[], &[], &["[invalid".to_string()]);
    // Should still work for other checks
    assert!(!f.excludes_file(Path::new("foo.rs"), Path::new(ROOT)));
}

#[test]
fn exclude_filter_empty_glob_is_noop() {
    let f = ExcludeFilter::new(&[], &[], &[], &[]);
    assert!(!f.excludes_file(Path::new("anything.rs"), Path::new(ROOT)));
}

// ── Glob: absolute-path correctness ─────────────────────────────────────

#[test]
fn exclude_filter_glob_with_absolute_path() {
    let f = ExcludeFilter::new(&[], &[], &[], &["vendor/**".to_string()]);
    let root = Path::new("/home/user/project");
    assert!(
        f.excludes_file(Path::new("/home/user/project/vendor/foo.rs"), root),
        "vendor/** should match when path is absolute"
    );
    assert!(
        !f.excludes_file(Path::new("/home/user/project/src/main.rs"), root),
        "should not match non-vendor files"
    );
}

#[test]
fn exclude_filter_glob_with_tempdir() {
    let dir = tempdir().unwrap();
    let vendor = dir.path().join("vendor");
    fs::create_dir(&vendor).unwrap();
    fs::write(vendor.join("dep.rs"), "// generated").unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();

    let f = ExcludeFilter::new(&[], &[], &[], &["vendor/**".to_string()]);

    // tempdir paths are absolute — verify glob still works
    let vendor_file = vendor.join("dep.rs");
    assert!(
        f.excludes_file(&vendor_file, dir.path()),
        "vendor/** should match with absolute tempdir path"
    );
    assert!(
        !f.excludes_file(&dir.path().join("main.rs"), dir.path()),
        "should not match root files"
    );
}

// ── Integration: source_files respects ExcludeFilter ──────────────────

#[test]
fn source_files_excludes_extension() {
    let dir = tempdir().unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();
    fs::write(dir.path().join("lib.js"), "console.log('hi');").unwrap();

    let filter = ExcludeFilter::new(&[], &["js".to_string()], &[], &[]);
    let files = source_files(dir.path(), false, &filter);

    let names: Vec<_> = files
        .iter()
        .map(|(p, _)| p.file_name().unwrap().to_str().unwrap().to_string())
        .collect();

    assert!(
        names.contains(&"main.rs".to_string()),
        "main.rs should be included"
    );
    assert!(
        !names.contains(&"lib.js".to_string()),
        "lib.js should be excluded"
    );
}

#[test]
fn source_files_excludes_directory() {
    let dir = tempdir().unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();

    let vendor = dir.path().join("vendor");
    fs::create_dir(&vendor).unwrap();
    fs::write(vendor.join("dep.rs"), "// generated").unwrap();

    let filter = ExcludeFilter::new(&[], &[], &["vendor".to_string()], &[]);
    let files = source_files(dir.path(), false, &filter);

    // Only main.rs at root should appear; dep.rs inside vendor should not
    assert_eq!(files.len(), 1, "only root file should be found");
    assert_eq!(files[0].0.file_name().unwrap().to_str().unwrap(), "main.rs");
}

#[test]
fn source_files_no_filter_unchanged() {
    let dir = tempdir().unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();
    fs::write(dir.path().join("lib.js"), "export {};").unwrap();

    let filter = ExcludeFilter::default();
    let files = source_files(dir.path(), false, &filter);

    assert_eq!(files.len(), 2, "both files should appear with empty filter");
}

#[test]
fn source_files_excludes_by_glob() {
    let dir = tempdir().unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();
    fs::write(dir.path().join("app.min.js"), "var x=1;").unwrap();
    fs::write(dir.path().join("lib.js"), "export {};").unwrap();

    let filter = ExcludeFilter::new(&[], &[], &[], &["*.min.js".to_string()]);
    let files = source_files(dir.path(), false, &filter);

    let names: Vec<_> = files
        .iter()
        .map(|(p, _)| p.file_name().unwrap().to_str().unwrap().to_string())
        .collect();

    assert!(names.contains(&"main.rs".to_string()));
    assert!(names.contains(&"lib.js".to_string()));
    assert!(
        !names.contains(&"app.min.js".to_string()),
        "app.min.js should be excluded by glob"
    );
}

#[test]
fn source_files_glob_with_absolute_path() {
    let dir = tempdir().unwrap();
    let vendor = dir.path().join("vendor");
    fs::create_dir(&vendor).unwrap();
    fs::write(vendor.join("dep.rs"), "// generated").unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();

    // tempdir paths are absolute — this previously would have failed
    let filter = ExcludeFilter::new(&[], &[], &[], &["vendor/**".to_string()]);
    let files = source_files(dir.path(), false, &filter);

    assert_eq!(files.len(), 1, "only main.rs should be found");
    assert_eq!(files[0].0.file_name().unwrap().to_str().unwrap(), "main.rs");
}

// ── is_test_file ────────────────────────────────────────────────────────

#[test]
fn is_test_file_rust_test_suffix() {
    assert!(is_test_file(Path::new("counter_test.rs")));
    assert!(is_test_file(Path::new("mod_test.rs")));
    assert!(!is_test_file(Path::new("counter.rs")));
}

#[test]
fn is_test_file_go_test_suffix() {
    assert!(is_test_file(Path::new("counter_test.go")));
    assert!(!is_test_file(Path::new("counter.go")));
}

#[test]
fn is_test_file_python_prefix_and_suffix() {
    assert!(is_test_file(Path::new("test_foo.py")));
    assert!(is_test_file(Path::new("foo_test.py")));
    assert!(!is_test_file(Path::new("foo.py")));
}

#[test]
fn is_test_file_ruby_spec_suffix() {
    assert!(is_test_file(Path::new("foo_spec.rb")));
    assert!(is_test_file(Path::new("foo_test.rb")));
    assert!(!is_test_file(Path::new("foo.rb")));
}

#[test]
fn is_test_file_php_pascal_test() {
    assert!(is_test_file(Path::new("FooTest.php")));
    assert!(is_test_file(Path::new("foo_test.php")));
    assert!(!is_test_file(Path::new("Foo.php")));
}

#[test]
fn is_test_file_javascript_double_ext() {
    assert!(is_test_file(Path::new("foo.test.js")));
    assert!(is_test_file(Path::new("foo.spec.js")));
    assert!(is_test_file(Path::new("foo.test.ts")));
    assert!(is_test_file(Path::new("foo.spec.tsx")));
    assert!(!is_test_file(Path::new("foo.js")));
}

#[test]
fn is_test_file_java_test_suffix() {
    assert!(is_test_file(Path::new("FooTest.java")));
    assert!(is_test_file(Path::new("FooTests.java")));
    assert!(!is_test_file(Path::new("Foo.java")));
}

#[test]
fn is_test_file_kotlin_test_suffix() {
    assert!(is_test_file(Path::new("FooTest.kt")));
    assert!(!is_test_file(Path::new("Foo.kt")));
}

#[test]
fn is_test_file_csharp_test_suffix() {
    assert!(is_test_file(Path::new("FooTest.cs")));
    assert!(is_test_file(Path::new("FooTests.cs")));
    assert!(!is_test_file(Path::new("Foo.cs")));
}

#[test]
fn is_test_file_swift_test_suffix() {
    assert!(is_test_file(Path::new("FooTest.swift")));
    assert!(is_test_file(Path::new("FooTests.swift")));
    assert!(!is_test_file(Path::new("Foo.swift")));
}

#[test]
fn is_test_file_scala_spec_suffix() {
    assert!(is_test_file(Path::new("FooSpec.scala")));
    assert!(is_test_file(Path::new("FooTest.scala")));
    assert!(!is_test_file(Path::new("Foo.scala")));
}

#[test]
fn is_test_file_c_unittest_suffix() {
    assert!(is_test_file(Path::new("foo_unittest.c")));
    assert!(is_test_file(Path::new("foo_test.c")));
    assert!(is_test_file(Path::new("test_foo.c")));
    assert!(!is_test_file(Path::new("foo.c")));
}

#[test]
fn is_test_file_cpp_unittest_suffix() {
    assert!(is_test_file(Path::new("foo_unittest.cpp")));
    assert!(is_test_file(Path::new("foo_test.cpp")));
    assert!(is_test_file(Path::new("FooTest.cpp")));
    assert!(is_test_file(Path::new("test_foo.cpp")));
    assert!(!is_test_file(Path::new("foo.cpp")));
}

#[test]
fn is_test_file_haskell_spec_suffix() {
    assert!(is_test_file(Path::new("FooSpec.hs")));
    assert!(is_test_file(Path::new("FooTest.hs")));
    assert!(!is_test_file(Path::new("Foo.hs")));
}

#[test]
fn is_test_file_dart_test_suffix() {
    assert!(is_test_file(Path::new("foo_test.dart")));
    assert!(!is_test_file(Path::new("foo.dart")));
}

#[test]
fn is_test_file_no_extension_returns_false() {
    assert!(!is_test_file(Path::new("Makefile")));
    assert!(!is_test_file(Path::new("Dockerfile")));
}

#[test]
fn is_test_file_unknown_extension_returns_false() {
    assert!(!is_test_file(Path::new("foo_test.xyz")));
}

// ── collect_analysis ────────────────────────────────────────────────────

#[test]
fn collect_analysis_ok_some_results() {
    let dir = tempdir().unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();
    fs::write(dir.path().join("lib.rs"), "pub fn foo() {}").unwrap();

    let filter = ExcludeFilter::default();
    let results: Vec<String> = collect_analysis(dir.path(), false, &filter, |path, spec| {
        Ok(Some(format!("{} ({})", path.display(), spec.name)))
    });

    assert_eq!(results.len(), 2);
}

#[test]
fn collect_analysis_ok_none_skips() {
    let dir = tempdir().unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();

    let filter = ExcludeFilter::default();
    let results: Vec<String> =
        collect_analysis(dir.path(), false, &filter, |_path, _spec| Ok(None));

    assert!(results.is_empty(), "Ok(None) should be skipped");
}

#[test]
fn collect_analysis_err_skips_with_warning() {
    let dir = tempdir().unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();

    let filter = ExcludeFilter::default();
    let results: Vec<String> = collect_analysis(dir.path(), false, &filter, |_path, _spec| {
        Err("simulated error".into())
    });

    // Errors are logged to stderr and skipped, so results should be empty
    assert!(results.is_empty(), "Err should be skipped");
}

// ── print_excluded_files ────────────────────────────────────────────────

#[test]
fn print_excluded_files_no_exclusions() {
    let dir = tempdir().unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();
    let filter = ExcludeFilter::default();
    // Should not crash even with no exclusions
    print_excluded_files(dir.path(), false, &filter).unwrap();
}

#[test]
fn print_excluded_files_with_extension_exclusion() {
    let dir = tempdir().unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();
    fs::write(dir.path().join("lib.js"), "export {};").unwrap();
    let filter = ExcludeFilter::new(&[], &["js".to_string()], &[], &[]);
    print_excluded_files(dir.path(), false, &filter).unwrap();
}

#[test]
fn print_excluded_files_with_dir_exclusion() {
    let dir = tempdir().unwrap();
    let vendor = dir.path().join("vendor");
    fs::create_dir(&vendor).unwrap();
    fs::write(vendor.join("dep.rs"), "// generated").unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();
    let filter = ExcludeFilter::new(&[], &[], &["vendor".to_string()], &[]);
    print_excluded_files(dir.path(), false, &filter).unwrap();
}

#[test]
fn print_excluded_files_with_test_exclusion() {
    let dir = tempdir().unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();
    fs::write(dir.path().join("main_test.rs"), "#[test] fn t() {}").unwrap();
    let filter = ExcludeFilter::default();
    print_excluded_files(dir.path(), true, &filter).unwrap();
}

#[test]
fn print_excluded_files_with_test_dir_exclusion() {
    let dir = tempdir().unwrap();
    let tests_dir = dir.path().join("tests");
    fs::create_dir(&tests_dir).unwrap();
    fs::write(tests_dir.join("integration.rs"), "fn test() {}").unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();
    let filter = ExcludeFilter::default();
    print_excluded_files(dir.path(), true, &filter).unwrap();
}

#[test]
fn print_excluded_files_with_glob_exclusion() {
    let dir = tempdir().unwrap();
    fs::write(dir.path().join("app.min.js"), "var x=1;").unwrap();
    fs::write(dir.path().join("main.rs"), "fn main() {}").unwrap();
    let filter = ExcludeFilter::new(&[], &[], &[], &["*.min.js".to_string()]);
    print_excluded_files(dir.path(), false, &filter).unwrap();
}

// ── try_detect_shebang ─────────────────────────────────────────────────

#[test]
fn try_detect_shebang_python() {
    let dir = tempdir().unwrap();
    let script = dir.path().join("script");
    fs::write(&script, "#!/usr/bin/env python3\nprint('hi')\n").unwrap();
    let spec = try_detect_shebang(&script);
    assert!(spec.is_some(), "should detect Python from shebang");
    assert_eq!(spec.unwrap().name, "Python");
}

#[test]
fn try_detect_shebang_no_shebang_returns_none() {
    let dir = tempdir().unwrap();
    let file = dir.path().join("file");
    fs::write(&file, "just text, no shebang").unwrap();
    let spec = try_detect_shebang(&file);
    assert!(spec.is_none(), "file without shebang should return None");
}

#[test]
fn try_detect_shebang_nonexistent_file_returns_none() {
    let spec = try_detect_shebang(Path::new("/nonexistent/path/file"));
    assert!(spec.is_none(), "nonexistent file should return None");
}