@@ -462,6 +462,41 @@ fn new_ignored_file() -> anyhow::Result<()> {
462462 Ok ( ( ) )
463463}
464464
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+
465500#[ test]
466501fn changed_file ( ) -> anyhow:: Result < ( ) > {
467502 let foo_source = "print('Hello, world!')" ;
@@ -1075,6 +1110,7 @@ fn hard_links_in_project() -> anyhow::Result<()> {
10751110
10761111 assert_eq ! ( source_text( case. db( ) , foo) . as_str( ) , "print('Version 1')" ) ;
10771112 assert_eq ! ( source_text( case. db( ) , bar) . as_str( ) , "print('Version 1')" ) ;
1113+ assert_eq ! ( case. collect_project_files( ) , & [ bar, foo] ) ;
10781114
10791115 // Write to the hard link target.
10801116 update_file ( foo_path, "print('Version 2')" ) . context ( "Failed to update foo.py" ) ?;
@@ -1268,6 +1304,8 @@ mod unix {
12681304 Some ( & * baz_project)
12691305 ) ;
12701306
1307+ assert_eq ! ( case. collect_project_files( ) , & [ baz. file( ) ] ) ;
1308+
12711309 let baz_original = case. root_path ( ) . join ( "bar/baz.py" ) ;
12721310
12731311 // Write to the symlink target.
@@ -1283,6 +1321,8 @@ mod unix {
12831321 "def baz(): print('Version 2')"
12841322 ) ;
12851323
1324+ assert_eq ! ( case. collect_project_files( ) , & [ baz. file( ) ] ) ;
1325+
12861326 // Write to the symlink source.
12871327 update_file ( baz_project, "def baz(): print('Version 3')" )
12881328 . context ( "Failed to update bar/baz.py" ) ?;
@@ -1295,6 +1335,7 @@ mod unix {
12951335 source_text( case. db( ) , baz. file( ) ) . as_str( ) ,
12961336 "def baz(): print('Version 3')"
12971337 ) ;
1338+ assert_eq ! ( case. collect_project_files( ) , & [ baz. file( ) ] ) ;
12981339
12991340 Ok ( ( ) )
13001341 }
@@ -1354,6 +1395,8 @@ mod unix {
13541395 ) ;
13551396 assert_eq ! ( baz. file( ) . path( case. db( ) ) . as_system_path( ) , Some ( & * bar_baz) ) ;
13561397
1398+ assert_eq ! ( case. collect_project_files( ) , & [ patched_bar_baz_file] ) ;
1399+
13571400 // Write to the symlink target.
13581401 update_file ( & patched_bar_baz, "def baz(): print('Version 2')" )
13591402 . context ( "Failed to update bar/baz.py" ) ?;
@@ -1389,6 +1432,7 @@ mod unix {
13891432 bar_baz_text = bar_baz_text. as_str( )
13901433 ) ;
13911434
1435+ assert_eq ! ( case. collect_project_files( ) , & [ patched_bar_baz_file] ) ;
13921436 Ok ( ( ) )
13931437 }
13941438
@@ -1469,6 +1513,8 @@ mod unix {
14691513 Some ( & * baz_original)
14701514 ) ;
14711515
1516+ assert_eq ! ( case. collect_project_files( ) , & [ ] ) ;
1517+
14721518 // Write to the symlink target.
14731519 update_file ( & baz_original, "def baz(): print('Version 2')" )
14741520 . context ( "Failed to update bar/baz.py" ) ?;
@@ -1494,6 +1540,8 @@ mod unix {
14941540 "def baz(): print('Version 2')"
14951541 ) ;
14961542
1543+ assert_eq ! ( case. collect_project_files( ) , & [ ] ) ;
1544+
14971545 Ok ( ( ) )
14981546 }
14991547}
0 commit comments