@@ -43,15 +43,30 @@ class FineGrainedSuite(DataSuite):
4343 optional_out = True
4444
4545 def run_case (self , testcase : DataDrivenTestCase ) -> None :
46+ self .run_case_inner (testcase , cache = False )
47+
48+ # Reset the test case and run it again with caching on
49+ testcase .teardown ()
50+ testcase .setup ()
51+ self .run_case_inner (testcase , cache = True )
52+
53+ def run_case_inner (self , testcase : DataDrivenTestCase , cache : bool ) -> None :
54+ # TODO: In caching mode we currently don't well support
55+ # starting from cached states with errors in them.
56+ if cache and testcase .output and testcase .output [0 ] != '==' : return
57+
4658 main_src = '\n ' .join (testcase .input )
4759 sources_override = self .parse_sources (main_src )
48- messages , manager , graph = self .build (main_src , testcase , sources_override )
49-
60+ print ("Testing with cache: " , cache )
61+ messages , manager , graph = self .build (main_src , testcase , sources_override ,
62+ build_cache = cache , enable_cache = cache )
5063 a = []
5164 if messages :
5265 a .extend (normalize_messages (messages ))
5366
54- fine_grained_manager = FineGrainedBuildManager (manager , graph )
67+ fine_grained_manager = None
68+ if not cache :
69+ fine_grained_manager = FineGrainedBuildManager (manager , graph )
5570
5671 steps = testcase .find_steps ()
5772 all_triggered = []
@@ -70,6 +85,15 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
7085 modules = [(module , path )
7186 for module , path in sources_override
7287 if any (m == module for m , _ in modules )]
88+
89+ # If this is the second iteration and we are using a
90+ # cache, now we need to set it up
91+ if fine_grained_manager is None :
92+ messages , manager , graph = self .build (main_src , testcase , sources_override ,
93+ build_cache = False , enable_cache = cache )
94+ manager .options .cache_dir = os .devnull # XXX: HACK
95+ fine_grained_manager = FineGrainedBuildManager (manager , graph )
96+
7397 new_messages = fine_grained_manager .update (modules )
7498 all_triggered .append (fine_grained_manager .triggered )
7599 new_messages = normalize_messages (new_messages )
@@ -80,10 +104,11 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
80104 # Normalize paths in test output (for Windows).
81105 a = [line .replace ('\\ ' , '/' ) for line in a ]
82106
107+ modestr = "in cache mode " if cache else ""
83108 assert_string_arrays_equal (
84109 testcase .output , a ,
85- 'Invalid output ({}, line {})' .format (testcase . file ,
86- testcase .line ))
110+ 'Invalid output {} ({}, line {})' .format (
111+ modestr , testcase . file , testcase .line ))
87112
88113 if testcase .triggered :
89114 assert_string_arrays_equal (
@@ -95,14 +120,18 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
95120 def build (self ,
96121 source : str ,
97122 testcase : DataDrivenTestCase ,
98- sources_override : Optional [List [Tuple [str , str ]]]) -> Tuple [ List [ str ] ,
99- BuildManager ,
100- Graph ]:
123+ sources_override : Optional [List [Tuple [str , str ]]],
124+ build_cache : bool ,
125+ enable_cache : bool ) -> Tuple [ List [ str ], BuildManager , Graph ]:
101126 # This handles things like '# flags: --foo'.
102127 options = parse_options (source , testcase , incremental_step = 1 )
103128 options .incremental = True
104129 options .use_builtins_fixtures = True
105130 options .show_traceback = True
131+ options .fine_grained_incremental = not build_cache
132+ options .use_fine_grained_cache = enable_cache and not build_cache
133+ options .cache_fine_grained = enable_cache
134+
106135 main_path = os .path .join (test_temp_dir , 'main' )
107136 with open (main_path , 'w' ) as f :
108137 f .write (source )
0 commit comments