@@ -11,10 +11,10 @@ use tempfile::{TempDir, tempdir};
11
11
fn create_temp_file ( dir : & Path , name : & str , content : & str ) {
12
12
let file_path = dir. join ( name) ;
13
13
let parent_dir = file_path. parent ( ) . unwrap ( ) ;
14
- fs:: create_dir_all ( parent_dir) . expect ( & format ! ( "Failed to create directory: {:?}" , parent_dir) ) ;
14
+ fs:: create_dir_all ( parent_dir) . unwrap_or_else ( |_| panic ! ( "Failed to create directory: {:?}" , parent_dir) ) ;
15
15
let mut file =
16
- File :: create ( & file_path) . expect ( & format ! ( "Failed to create temp file: {:?}" , file_path) ) ;
17
- writeln ! ( file, "{}" , content) . expect ( & format ! ( "Failed to write to temp file: {:?}" , file_path) ) ;
16
+ File :: create ( & file_path) . unwrap_or_else ( |_| panic ! ( "Failed to create temp file: {:?}" , file_path) ) ;
17
+ writeln ! ( file, "{}" , content) . unwrap_or_else ( |_| panic ! ( "Failed to write to temp file: {:?}" , file_path) ) ;
18
18
}
19
19
static TEST_DIR : Lazy < TempDir > = Lazy :: new ( || {
20
20
let dir = tempdir ( ) . expect ( "Failed to create a temp directory" ) ;
@@ -61,20 +61,20 @@ mod tests {
61
61
#[ test]
62
62
fn test_no_include_no_exclude_path ( ) {
63
63
let path = Path :: new ( "src/main.rs" ) ;
64
- let include_patterns = build_globset ( & vec ! [ ] ) ;
65
- let exclude_patterns = build_globset ( & vec ! [ ] ) ;
64
+ let include_patterns = build_globset ( & [ ] ) ;
65
+ let exclude_patterns = build_globset ( & [ ] ) ;
66
66
// ~~~ Must be included ~~~
67
67
assert ! ( should_include_file(
68
- & path,
68
+ path,
69
69
& include_patterns,
70
70
& exclude_patterns,
71
71
) ) ;
72
72
}
73
73
#[ test]
74
74
fn test_no_include_no_exclude_empty ( ) {
75
75
let base_path = TEST_DIR . path ( ) ;
76
- let include_patterns = build_globset ( & vec ! [ ] ) ;
77
- let exclude_patterns = build_globset ( & vec ! [ ] ) ;
76
+ let include_patterns = build_globset ( & [ ] ) ;
77
+ let exclude_patterns = build_globset ( & [ ] ) ;
78
78
// ~~~ Must be included ~~~
79
79
for file in [
80
80
"lowercase/foo.py" ,
@@ -103,10 +103,10 @@ mod tests {
103
103
#[ test]
104
104
fn test_no_include_exclude_path ( ) {
105
105
let path = Path :: new ( "src/main.rs" ) ;
106
- let include_patterns = build_globset ( & vec ! [ ] ) ;
107
- let exclude_patterns = build_globset ( & vec ! [ "*.rs" . to_string( ) ] ) ;
106
+ let include_patterns = build_globset ( & [ ] ) ;
107
+ let exclude_patterns = build_globset ( & [ "*.rs" . to_string ( ) ] ) ;
108
108
assert ! ( !should_include_file(
109
- & path,
109
+ path,
110
110
& include_patterns,
111
111
& exclude_patterns,
112
112
) ) ;
@@ -115,8 +115,8 @@ mod tests {
115
115
/// Added for globset
116
116
fn test_no_include_exclude_by_filename ( ) {
117
117
let base_path = TEST_DIR . path ( ) ;
118
- let include_patterns = build_globset ( & vec ! [ ] ) ;
119
- let exclude_patterns = build_globset ( & vec ! [ "default_template.hbs" . to_string( ) ] ) ;
118
+ let include_patterns = build_globset ( & [ ] ) ;
119
+ let exclude_patterns = build_globset ( & [ "default_template.hbs" . to_string ( ) ] ) ;
120
120
// ~~~ Must be excluded ~~~
121
121
let excluded_path = base_path. join ( "src/default_template.hbs" ) ;
122
122
assert ! ( !should_include_file(
@@ -128,8 +128,8 @@ mod tests {
128
128
#[ test]
129
129
fn test_no_include_exclude_path_patterns ( ) {
130
130
let base_path = TEST_DIR . path ( ) ;
131
- let include_patterns = build_globset ( & vec ! [ ] ) ;
132
- let exclude_patterns = build_globset ( & vec ! [ "lowercase/{*.txt,*.py}" . to_string( ) ] ) ;
131
+ let include_patterns = build_globset ( & [ ] ) ;
132
+ let exclude_patterns = build_globset ( & [ "lowercase/{*.txt,*.py}" . to_string ( ) ] ) ;
133
133
// ~~~ Must be excluded ~~~
134
134
for file in [
135
135
"lowercase/qux.txt" ,
@@ -142,7 +142,7 @@ mod tests {
142
142
let path = base_path. join ( file) ;
143
143
let relative_path = path. strip_prefix ( base_path) . unwrap ( ) ;
144
144
assert ! ( !should_include_file(
145
- & relative_path,
145
+ relative_path,
146
146
& include_patterns,
147
147
& exclude_patterns,
148
148
) ) ;
@@ -160,7 +160,7 @@ mod tests {
160
160
let path = base_path. join ( file) ;
161
161
let relative_path = path. strip_prefix ( base_path) . unwrap ( ) ;
162
162
assert ! ( should_include_file(
163
- & relative_path,
163
+ relative_path,
164
164
& include_patterns,
165
165
& exclude_patterns,
166
166
) ) ;
@@ -169,8 +169,8 @@ mod tests {
169
169
#[ test]
170
170
fn test_no_include_exclude_patterns ( ) {
171
171
let base_path = TEST_DIR . path ( ) ;
172
- let include_patterns = build_globset ( & vec ! [ ] ) ;
173
- let exclude_patterns = build_globset ( & vec ! [ "*.txt" . to_string( ) ] ) ;
172
+ let include_patterns = build_globset ( & [ ] ) ;
173
+ let exclude_patterns = build_globset ( & [ "*.txt" . to_string ( ) ] ) ;
174
174
// ~~~ Must be excluded ~~~
175
175
for file in [
176
176
"lowercase/qux.txt" ,
@@ -208,9 +208,9 @@ mod tests {
208
208
#[ test]
209
209
fn test_no_include_exclude_files ( ) {
210
210
let base_path = TEST_DIR . path ( ) ;
211
- let include_patterns = build_globset ( & vec ! [ ] ) ;
211
+ let include_patterns = build_globset ( & [ ] ) ;
212
212
let exclude_patterns =
213
- build_globset ( & vec ! [ "**/foo.py" . to_string( ) , "**/bar.py" . to_string( ) ] ) ;
213
+ build_globset ( & [ "**/foo.py" . to_string ( ) , "**/bar.py" . to_string ( ) ] ) ;
214
214
// ~~~ Must be excluded ~~~
215
215
for file in [ "lowercase/foo.py" , "lowercase/bar.py" ] {
216
216
let path = base_path. join ( file) ;
@@ -245,8 +245,8 @@ mod tests {
245
245
#[ test]
246
246
fn test_no_include_exclude_folders ( ) {
247
247
let base_path = TEST_DIR . path ( ) ;
248
- let include_patterns = build_globset ( & vec ! [ ] ) ;
249
- let exclude_patterns = build_globset ( & vec ! [ "**/lowercase/**" . to_string( ) ] ) ;
248
+ let include_patterns = build_globset ( & [ ] ) ;
249
+ let exclude_patterns = build_globset ( & [ "**/lowercase/**" . to_string ( ) ] ) ;
250
250
// ~~~ Must be excluded ~~~
251
251
for file in [ "lowercase/foo.py" , "lowercase/bar.py" , "lowercase/qux.txt" ] {
252
252
let path = base_path. join ( file) ;
@@ -274,8 +274,8 @@ mod tests {
274
274
#[ test]
275
275
fn test_include_no_exclude_patterns ( ) {
276
276
let base_path = TEST_DIR . path ( ) ;
277
- let include_patterns = build_globset ( & vec ! [ "*.py" . to_string( ) ] ) ;
278
- let exclude_patterns = build_globset ( & vec ! [ ] ) ;
277
+ let include_patterns = build_globset ( & [ "*.py" . to_string ( ) ] ) ;
278
+ let exclude_patterns = build_globset ( & [ ] ) ;
279
279
// ~~~ Must be included ~~~
280
280
for file in [
281
281
"lowercase/foo.py" ,
@@ -314,8 +314,8 @@ mod tests {
314
314
/// added for globset
315
315
fn test_include_no_exclude_by_filename ( ) {
316
316
let base_path = TEST_DIR . path ( ) ;
317
- let include_patterns = build_globset ( & vec ! [ "default_template.hbs" . to_string( ) ] ) ;
318
- let exclude_patterns = build_globset ( & vec ! [ ] ) ;
317
+ let include_patterns = build_globset ( & [ "default_template.hbs" . to_string ( ) ] ) ;
318
+ let exclude_patterns = build_globset ( & [ ] ) ;
319
319
// ~~~ Must be excluded ~~~
320
320
for file in [ "src/filter.rs" , "src/git.rs" , "src/lib.rs" , "src/token.rs" ] {
321
321
let path = base_path. join ( file) ;
@@ -337,8 +337,8 @@ mod tests {
337
337
fn test_include_no_exclude_by_path_pattern ( ) {
338
338
let base_path = TEST_DIR . path ( ) ;
339
339
// let include_patterns = vec!["lowercase/*.txt".to_string(), "lowercase/*.py".to_string()];
340
- let include_patterns = build_globset ( & vec ! [ "lowercase/{*.txt,*.py}" . to_string( ) ] ) ;
341
- let exclude_patterns = build_globset ( & vec ! [ ] ) ;
340
+ let include_patterns = build_globset ( & [ "lowercase/{*.txt,*.py}" . to_string ( ) ] ) ;
341
+ let exclude_patterns = build_globset ( & [ ] ) ;
342
342
// ~~~ Must be included ~~~
343
343
for file in [
344
344
"lowercase/qux.txt" ,
@@ -351,7 +351,7 @@ mod tests {
351
351
let path = base_path. join ( file) ;
352
352
let relative_path = path. strip_prefix ( base_path) . unwrap ( ) ;
353
353
assert ! ( should_include_file(
354
- & relative_path,
354
+ relative_path,
355
355
& include_patterns,
356
356
& exclude_patterns,
357
357
) ) ;
@@ -369,7 +369,7 @@ mod tests {
369
369
let path = base_path. join ( file) ;
370
370
let relative_path = path. strip_prefix ( base_path) . unwrap ( ) ;
371
371
assert ! ( !should_include_file(
372
- & relative_path,
372
+ relative_path,
373
373
& include_patterns,
374
374
& exclude_patterns,
375
375
) ) ;
@@ -378,8 +378,8 @@ mod tests {
378
378
#[ test]
379
379
fn test_include_no_exclude_folders ( ) {
380
380
let base_path = TEST_DIR . path ( ) ;
381
- let include_patterns = build_globset ( & vec ! [ "**/lowercase/**" . to_string( ) ] ) ;
382
- let exclude_patterns = build_globset ( & vec ! [ ] ) ;
381
+ let include_patterns = build_globset ( & [ "**/lowercase/**" . to_string ( ) ] ) ;
382
+ let exclude_patterns = build_globset ( & [ ] ) ;
383
383
// ~~~ Must be included ~~~
384
384
for file in [ "lowercase/foo.py" , "lowercase/bar.py" , "lowercase/qux.txt" ] {
385
385
let path = base_path. join ( file) ;
@@ -407,8 +407,8 @@ mod tests {
407
407
fn test_include_no_exclude_files ( ) {
408
408
let base_path = TEST_DIR . path ( ) ;
409
409
let include_patterns =
410
- build_globset ( & vec ! [ "**/foo.py" . to_string( ) , "**/bar.py" . to_string( ) ] ) ;
411
- let exclude_patterns = build_globset ( & vec ! [ ] ) ;
410
+ build_globset ( & [ "**/foo.py" . to_string ( ) , "**/bar.py" . to_string ( ) ] ) ;
411
+ let exclude_patterns = build_globset ( & [ ] ) ;
412
412
// ~~~ Must be included ~~~
413
413
for file in [ "lowercase/foo.py" , "lowercase/bar.py" ] {
414
414
let path = base_path. join ( file) ;
@@ -444,10 +444,11 @@ mod tests {
444
444
#[ test]
445
445
fn test_include_exclude_conflict_file ( ) {
446
446
let base_path = TEST_DIR . path ( ) ;
447
- let include_patterns = build_globset ( & vec ! [ "**/foo.py" . to_string( ) ] ) ;
448
- let exclude_patterns = build_globset ( & vec ! [ "**/foo.py" . to_string( ) ] ) ;
447
+ let include_patterns = build_globset ( & [ "**/foo.py" . to_string ( ) ] ) ;
448
+ let exclude_patterns = build_globset ( & [ "**/foo.py" . to_string ( ) ] ) ;
449
449
// ~~~ Must be excluded (exclude takes precedence) ~~~
450
- for file in [ "lowercase/foo.py" ] {
450
+ {
451
+ let file = "lowercase/foo.py" ;
451
452
let path = base_path. join ( file) ;
452
453
assert ! ( !should_include_file(
453
454
& path,
@@ -481,8 +482,8 @@ mod tests {
481
482
#[ test]
482
483
fn test_include_exclude_conflict_extension ( ) {
483
484
let base_path = TEST_DIR . path ( ) ;
484
- let include_patterns = build_globset ( & vec ! [ "*.py" . to_string( ) ] ) ;
485
- let exclude_patterns = build_globset ( & vec ! [ "*.py" . to_string( ) ] ) ;
485
+ let include_patterns = build_globset ( & [ "*.py" . to_string ( ) ] ) ;
486
+ let exclude_patterns = build_globset ( & [ "*.py" . to_string ( ) ] ) ;
486
487
// ~~~ Must be excluded (exclude takes precedence) ~~~
487
488
for file in [
488
489
"lowercase/foo.py" ,
@@ -520,8 +521,8 @@ mod tests {
520
521
#[ test]
521
522
fn test_include_exclude_conflict_folder ( ) {
522
523
let base_path = TEST_DIR . path ( ) ;
523
- let include_patterns = build_globset ( & vec ! [ "**/lowercase/**" . to_string( ) ] ) ;
524
- let exclude_patterns = build_globset ( & vec ! [ "**/lowercase/**" . to_string( ) ] ) ;
524
+ let include_patterns = build_globset ( & [ "**/lowercase/**" . to_string ( ) ] ) ;
525
+ let exclude_patterns = build_globset ( & [ "**/lowercase/**" . to_string ( ) ] ) ;
525
526
// ~~~ Must be excluded (exclude takes precedence) ~~~
526
527
for file in [
527
528
"lowercase/foo.py" ,
@@ -559,10 +560,11 @@ mod tests {
559
560
#[ test]
560
561
fn test_include_exclude_exclude_takes_precedence ( ) {
561
562
let base_path = TEST_DIR . path ( ) ;
562
- let include_patterns = build_globset ( & vec ! [ "**/*.py" . to_string( ) ] ) ;
563
- let exclude_patterns = build_globset ( & vec ! [ "**/uppercase/*" . to_string( ) ] ) ;
563
+ let include_patterns = build_globset ( & [ "**/*.py" . to_string ( ) ] ) ;
564
+ let exclude_patterns = build_globset ( & [ "**/uppercase/*" . to_string ( ) ] ) ;
564
565
// ~~~ Must be included (not excluded) ~~~
565
- for file in [ "lowercase/foo.py" ] {
566
+ {
567
+ let file = "lowercase/foo.py" ;
566
568
let path = base_path. join ( file) ;
567
569
assert ! ( should_include_file(
568
570
& path,
@@ -571,7 +573,8 @@ mod tests {
571
573
) ) ;
572
574
}
573
575
// ~~~ Must be excluded (exclude takes precedence) ~~~
574
- for file in [ "uppercase/FOO.py" ] {
576
+ {
577
+ let file = "uppercase/FOO.py" ;
575
578
let path = base_path. join ( file) ;
576
579
assert ! ( !should_include_file(
577
580
& path,
@@ -599,15 +602,15 @@ mod tests {
599
602
let base_path = TEST_DIR . path ( ) ;
600
603
// This pattern uses brace expansion to match foo.py, bar.py, and baz.py
601
604
// The issue was that the first item (foo.py) wasn't being considered
602
- let include_patterns = build_globset ( & vec ! [ "lowercase/{foo.py,bar.py,baz.py}" . to_string( ) ] ) ;
605
+ let include_patterns = build_globset ( & [ "lowercase/{foo.py,bar.py,baz.py}" . to_string ( ) ] ) ;
603
606
let exclude_patterns =
604
- build_globset ( & vec ! [ "lowercase/{qux.py,corge.py,grault.py}" . to_string( ) ] ) ;
607
+ build_globset ( & [ "lowercase/{qux.py,corge.py,grault.py}" . to_string ( ) ] ) ;
605
608
// ALL files in the brace expansion should be included
606
609
for file in [ "foo.py" , "bar.py" , "baz.py" ] {
607
610
let path = base_path. join ( "lowercase" ) . join ( file) ;
608
611
let relative_path = path. strip_prefix ( base_path) . unwrap ( ) ;
609
612
assert ! (
610
- should_include_file( & relative_path, & include_patterns, & exclude_patterns, ) ,
613
+ should_include_file( relative_path, & include_patterns, & exclude_patterns, ) ,
611
614
"Failed to include file: {}" ,
612
615
file
613
616
) ;
@@ -617,7 +620,7 @@ mod tests {
617
620
let path = base_path. join ( "lowercase" ) . join ( file) ;
618
621
let relative_path = path. strip_prefix ( base_path) . unwrap ( ) ;
619
622
assert ! (
620
- !should_include_file( & relative_path, & include_patterns, & exclude_patterns, ) ,
623
+ !should_include_file( relative_path, & include_patterns, & exclude_patterns, ) ,
621
624
"Incorrectly included non-matching file: {}" ,
622
625
file
623
626
) ;
@@ -628,11 +631,9 @@ mod tests {
628
631
fn test_brace_expansion_multiple_patterns ( ) {
629
632
let base_path = TEST_DIR . path ( ) ;
630
633
// Test with multiple patterns, each with brace expansion
631
- let include_patterns = build_globset ( & vec ! [
632
- "lowercase/{foo,bar,baz}.py" . to_string( ) ,
633
- "uppercase/{FOO,BAR,BAZ}.py" . to_string( ) ,
634
- ] ) ;
635
- let exclude_patterns = build_globset ( & vec ! [ ] ) ;
634
+ let include_patterns = build_globset ( & [ "lowercase/{foo,bar,baz}.py" . to_string ( ) ,
635
+ "uppercase/{FOO,BAR,BAZ}.py" . to_string ( ) ] ) ;
636
+ let exclude_patterns = build_globset ( & [ ] ) ;
636
637
// All files in the brace expansions should be included
637
638
for file in [
638
639
"lowercase/foo.py" ,
@@ -645,7 +646,7 @@ mod tests {
645
646
let path = base_path. join ( file) ;
646
647
let relative_path = path. strip_prefix ( base_path) . unwrap ( ) ;
647
648
assert ! (
648
- should_include_file( & relative_path, & include_patterns, & exclude_patterns, ) ,
649
+ should_include_file( relative_path, & include_patterns, & exclude_patterns, ) ,
649
650
"Failed to include file: {}" ,
650
651
file
651
652
) ;
@@ -663,7 +664,7 @@ mod tests {
663
664
let path = base_path. join ( file) ;
664
665
let relative_path = path. strip_prefix ( base_path) . unwrap ( ) ;
665
666
assert ! (
666
- !should_include_file( & relative_path, & include_patterns, & exclude_patterns, ) ,
667
+ !should_include_file( relative_path, & include_patterns, & exclude_patterns, ) ,
667
668
"Incorrectly included non-matching file: {}" ,
668
669
file
669
670
) ;
0 commit comments