@@ -54,6 +54,7 @@ def parse_test_cases(
5454 output_files = [] # type: List[Tuple[str, str]] # path and contents for output files
5555 tcout = [] # type: List[str] # Regular output errors
5656 tcout2 = {} # type: Dict[int, List[str]] # Output errors for incremental, runs 2+
57+ deleted_paths = {} # type: Dict[int, Set[str]] # from run number of paths
5758 stale_modules = {} # type: Dict[int, Set[str]] # from run number to module names
5859 rechecked_modules = {} # type: Dict[ int, Set[str]] # from run number module names
5960 while i < len (p ) and p [i ].id != 'case' :
@@ -99,6 +100,16 @@ def parse_test_cases(
99100 rechecked_modules [passnum ] = set ()
100101 else :
101102 rechecked_modules [passnum ] = {item .strip () for item in arg .split (',' )}
103+ elif p [i ].id == 'delete' :
104+ # File to delete during a multi-step test case
105+ arg = p [i ].arg
106+ assert arg is not None
107+ m = re .match (r'(.*)\.([0-9]+)$' , arg )
108+ assert m , 'Invalid delete section: {}' .format (arg )
109+ num = int (m .group (2 ))
110+ assert num >= 2 , "Can't delete during step {}" .format (num )
111+ full = join (base_path , m .group (1 ))
112+ deleted_paths .setdefault (num , set ()).add (full )
102113 elif p [i ].id == 'out' or p [i ].id == 'out1' :
103114 tcout = p [i ].data
104115 if native_sep and os .path .sep == '\\ ' :
@@ -142,7 +153,7 @@ def parse_test_cases(
142153 tc = DataDrivenTestCase (p [i0 ].arg , input , tcout , tcout2 , path ,
143154 p [i0 ].line , lastline , perform ,
144155 files , output_files , stale_modules ,
145- rechecked_modules , native_sep )
156+ rechecked_modules , deleted_paths , native_sep )
146157 out .append (tc )
147158 if not ok :
148159 raise ValueError (
@@ -180,6 +191,7 @@ def __init__(self,
180191 output_files : List [Tuple [str , str ]],
181192 expected_stale_modules : Dict [int , Set [str ]],
182193 expected_rechecked_modules : Dict [int , Set [str ]],
194+ deleted_paths : Dict [int , Set [str ]],
183195 native_sep : bool = False ,
184196 ) -> None :
185197 super ().__init__ (name )
@@ -194,24 +206,30 @@ def __init__(self,
194206 self .output_files = output_files
195207 self .expected_stale_modules = expected_stale_modules
196208 self .expected_rechecked_modules = expected_rechecked_modules
209+ self .deleted_paths = deleted_paths
197210 self .native_sep = native_sep
198211
199212 def set_up (self ) -> None :
200213 super ().set_up ()
201214 encountered_files = set ()
202215 self .clean_up = []
216+ all_deleted = [] # type: List[str]
217+ for paths in self .deleted_paths .values ():
218+ all_deleted += paths
203219 for path , content in self .files :
204220 dir = os .path .dirname (path )
205221 for d in self .add_dirs (dir ):
206222 self .clean_up .append ((True , d ))
207223 with open (path , 'w' ) as f :
208224 f .write (content )
209- self .clean_up .append ((False , path ))
225+ if path not in all_deleted :
226+ # TODO: Don't assume that deleted files don't get reintroduced.
227+ self .clean_up .append ((False , path ))
210228 encountered_files .add (path )
211229 if re .search (r'\.[2-9]$' , path ):
212230 # Make sure new files introduced in the second and later runs are accounted for
213231 renamed_path = path [:- 2 ]
214- if renamed_path not in encountered_files :
232+ if renamed_path not in encountered_files and renamed_path not in all_deleted :
215233 encountered_files .add (renamed_path )
216234 self .clean_up .append ((False , renamed_path ))
217235 for path , _ in self .output_files :
0 commit comments