@@ -4,17 +4,24 @@ use moon_env_var::GlobalEnvBag;
44use moon_task:: Target ;
55use moon_test_utils2:: { WorkspaceGraph , WorkspaceMocker } ;
66use rustc_hash:: { FxHashMap , FxHashSet } ;
7- use starbase_sandbox:: create_sandbox;
7+ use starbase_sandbox:: { Sandbox , create_sandbox} ;
88
9- async fn build_graph ( fixture : & str ) -> WorkspaceGraph {
9+ async fn build_graph_with_sandbox ( fixture : & str ) -> ( WorkspaceGraph , Sandbox ) {
1010 let sandbox = create_sandbox ( fixture) ;
1111
12- WorkspaceMocker :: new ( sandbox. path ( ) )
13- . with_default_projects ( )
14- . with_global_envs ( )
15- . with_inherited_tasks ( )
16- . mock_workspace_graph ( )
17- . await
12+ (
13+ WorkspaceMocker :: new ( sandbox. path ( ) )
14+ . with_default_projects ( )
15+ . with_global_envs ( )
16+ . with_inherited_tasks ( )
17+ . mock_workspace_graph ( )
18+ . await ,
19+ sandbox,
20+ )
21+ }
22+
23+ async fn build_graph ( fixture : & str ) -> WorkspaceGraph {
24+ build_graph_with_sandbox ( fixture) . await . 0
1825}
1926
2027mod affected_projects {
@@ -454,6 +461,44 @@ mod affected_tasks {
454461 ) ;
455462 }
456463
464+ #[ tokio:: test]
465+ async fn affected_by_file_if_content_matches ( ) {
466+ let ( workspace_graph, sandbox) = build_graph_with_sandbox ( "tasks" ) . await ;
467+ sandbox. create_file ( "base/file.txt" , "bar" ) ;
468+
469+ let touched_files = FxHashSet :: from_iter ( [ "base/file.txt" . into ( ) ] ) ;
470+
471+ let mut tracker = AffectedTracker :: new ( workspace_graph. into ( ) , touched_files) ;
472+ tracker
473+ . track_tasks_by_target ( & [ Target :: parse ( "base:by-file-match" ) . unwrap ( ) ] )
474+ . unwrap ( ) ;
475+ let affected = tracker. build ( ) ;
476+
477+ assert_eq ! (
478+ affected. tasks,
479+ FxHashMap :: from_iter( [ (
480+ Target :: parse( "base:by-file-match" ) . unwrap( ) ,
481+ create_state_from_file( "base/file.txt" )
482+ ) ] )
483+ ) ;
484+ }
485+
486+ #[ tokio:: test]
487+ async fn not_affected_by_file_if_content_doesnt_match ( ) {
488+ let ( workspace_graph, sandbox) = build_graph_with_sandbox ( "tasks" ) . await ;
489+ sandbox. create_file ( "base/file.txt" , "foo" ) ;
490+
491+ let touched_files = FxHashSet :: from_iter ( [ "base/file.txt" . into ( ) ] ) ;
492+
493+ let mut tracker = AffectedTracker :: new ( workspace_graph. into ( ) , touched_files) ;
494+ tracker
495+ . track_tasks_by_target ( & [ Target :: parse ( "base:by-file-match" ) . unwrap ( ) ] )
496+ . unwrap ( ) ;
497+ let affected = tracker. build ( ) ;
498+
499+ assert ! ( affected. tasks. is_empty( ) ) ;
500+ }
501+
457502 #[ tokio:: test]
458503 async fn affected_by_glob ( ) {
459504 let workspace_graph = build_graph ( "tasks" ) . await ;
0 commit comments