@@ -43,15 +43,30 @@ class FineGrainedSuite(DataSuite):
43
43
optional_out = True
44
44
45
45
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
+
46
58
main_src = '\n ' .join (testcase .input )
47
59
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 )
50
63
a = []
51
64
if messages :
52
65
a .extend (normalize_messages (messages ))
53
66
54
- fine_grained_manager = FineGrainedBuildManager (manager , graph )
67
+ fine_grained_manager = None
68
+ if not cache :
69
+ fine_grained_manager = FineGrainedBuildManager (manager , graph )
55
70
56
71
steps = testcase .find_steps ()
57
72
all_triggered = []
@@ -70,6 +85,15 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
70
85
modules = [(module , path )
71
86
for module , path in sources_override
72
87
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
+
73
97
new_messages = fine_grained_manager .update (modules )
74
98
all_triggered .append (fine_grained_manager .triggered )
75
99
new_messages = normalize_messages (new_messages )
@@ -80,10 +104,11 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
80
104
# Normalize paths in test output (for Windows).
81
105
a = [line .replace ('\\ ' , '/' ) for line in a ]
82
106
107
+ modestr = "in cache mode " if cache else ""
83
108
assert_string_arrays_equal (
84
109
testcase .output , a ,
85
- 'Invalid output ({}, line {})' .format (testcase . file ,
86
- testcase .line ))
110
+ 'Invalid output {} ({}, line {})' .format (
111
+ modestr , testcase . file , testcase .line ))
87
112
88
113
if testcase .triggered :
89
114
assert_string_arrays_equal (
@@ -95,14 +120,18 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
95
120
def build (self ,
96
121
source : str ,
97
122
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 ]:
101
126
# This handles things like '# flags: --foo'.
102
127
options = parse_options (source , testcase , incremental_step = 1 )
103
128
options .incremental = True
104
129
options .use_builtins_fixtures = True
105
130
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
+
106
135
main_path = os .path .join (test_temp_dir , 'main' )
107
136
with open (main_path , 'w' ) as f :
108
137
f .write (source )
0 commit comments