@@ -462,6 +462,41 @@ fn new_ignored_file() -> anyhow::Result<()> {
462
462
Ok ( ( ) )
463
463
}
464
464
465
+ #[ test]
466
+ fn new_non_project_file ( ) -> anyhow:: Result < ( ) > {
467
+ let mut case = setup_with_options ( [ ( "bar.py" , "" ) ] , |context| {
468
+ Some ( Options {
469
+ environment : Some ( EnvironmentOptions {
470
+ extra_paths : Some ( vec ! [ RelativePathBuf :: cli(
471
+ context. join_root_path( "site_packages" ) ,
472
+ ) ] ) ,
473
+ ..EnvironmentOptions :: default ( )
474
+ } ) ,
475
+ ..Options :: default ( )
476
+ } )
477
+ } ) ?;
478
+
479
+ let bar_path = case. project_path ( "bar.py" ) ;
480
+ let bar_file = case. system_file ( & bar_path) . unwrap ( ) ;
481
+
482
+ assert_eq ! ( & case. collect_project_files( ) , & [ bar_file] ) ;
483
+
484
+ // Add a file to site packages
485
+ let black_path = case. root_path ( ) . join ( "site_packages/black.py" ) ;
486
+ std:: fs:: write ( black_path. as_std_path ( ) , "print('Hello')" ) ?;
487
+
488
+ let changes = case. stop_watch ( event_for_file ( "black.py" ) ) ;
489
+
490
+ case. apply_changes ( changes) ;
491
+
492
+ assert ! ( case. system_file( & black_path) . is_ok( ) ) ;
493
+
494
+ // The file should not have been added to the project files
495
+ assert_eq ! ( & case. collect_project_files( ) , & [ bar_file] ) ;
496
+
497
+ Ok ( ( ) )
498
+ }
499
+
465
500
#[ test]
466
501
fn changed_file ( ) -> anyhow:: Result < ( ) > {
467
502
let foo_source = "print('Hello, world!')" ;
@@ -1075,6 +1110,7 @@ fn hard_links_in_project() -> anyhow::Result<()> {
1075
1110
1076
1111
assert_eq ! ( source_text( case. db( ) , foo) . as_str( ) , "print('Version 1')" ) ;
1077
1112
assert_eq ! ( source_text( case. db( ) , bar) . as_str( ) , "print('Version 1')" ) ;
1113
+ assert_eq ! ( case. collect_project_files( ) , & [ bar, foo] ) ;
1078
1114
1079
1115
// Write to the hard link target.
1080
1116
update_file ( foo_path, "print('Version 2')" ) . context ( "Failed to update foo.py" ) ?;
@@ -1354,6 +1390,8 @@ mod unix {
1354
1390
) ;
1355
1391
assert_eq ! ( baz. file( ) . path( case. db( ) ) . as_system_path( ) , Some ( & * bar_baz) ) ;
1356
1392
1393
+ assert_eq ! ( case. collect_project_files( ) , & [ patched_bar_baz_file] ) ;
1394
+
1357
1395
// Write to the symlink target.
1358
1396
update_file ( & patched_bar_baz, "def baz(): print('Version 2')" )
1359
1397
. context ( "Failed to update bar/baz.py" ) ?;
@@ -1389,6 +1427,7 @@ mod unix {
1389
1427
bar_baz_text = bar_baz_text. as_str( )
1390
1428
) ;
1391
1429
1430
+ assert_eq ! ( case. collect_project_files( ) , & [ patched_bar_baz_file] ) ;
1392
1431
Ok ( ( ) )
1393
1432
}
1394
1433
@@ -1469,6 +1508,8 @@ mod unix {
1469
1508
Some ( & * baz_original)
1470
1509
) ;
1471
1510
1511
+ assert_eq ! ( case. collect_project_files( ) , & [ ] ) ;
1512
+
1472
1513
// Write to the symlink target.
1473
1514
update_file ( & baz_original, "def baz(): print('Version 2')" )
1474
1515
. context ( "Failed to update bar/baz.py" ) ?;
@@ -1494,6 +1535,8 @@ mod unix {
1494
1535
"def baz(): print('Version 2')"
1495
1536
) ;
1496
1537
1538
+ assert_eq ! ( case. collect_project_files( ) , & [ ] ) ;
1539
+
1497
1540
Ok ( ( ) )
1498
1541
}
1499
1542
}
0 commit comments