@@ -126,8 +126,13 @@ function match_ir_test_case(case_str)
126126 error (" Too many sections in IR test case" )
127127 expect_error = startswith (description, " Error" )
128128 is_broken = startswith (description, " FIXME" )
129+ method_filter = begin
130+ mf = match (r" \[ method_filter: *(.*)\] " , description)
131+ isnothing (mf) ? nothing : strip (mf[1 ])
132+ end
129133 (; expect_error= expect_error, is_broken= is_broken,
130134 description= strip (description),
135+ method_filter= method_filter,
131136 input= strip (input), output= strip (output))
132137end
133138
@@ -152,49 +157,49 @@ function setup_ir_test_module(preamble)
152157 test_mod
153158end
154159
155- function format_ir_for_test (mod, description, input, expect_error = false , is_broken = false )
156- ex = parsestmt (SyntaxTree, input)
160+ function format_ir_for_test (mod, case )
161+ ex = parsestmt (SyntaxTree, case . input)
157162 try
158163 if kind (ex) == K " macrocall" && kind (ex[1 ]) == K " MacroName" && ex[1 ]. name_val == " @ast_"
159164 # Total hack, until @ast_ can be implemented in terms of new-style
160165 # macros.
161166 ex = JuliaLowering. eval (mod, Expr (ex))
162167 end
163168 x = JuliaLowering. lower (mod, ex)
164- if expect_error
165- error (" Expected a lowering error in test case \" $description \" " )
169+ if case . expect_error
170+ error (" Expected a lowering error in test case \" $(case . description) \" " )
166171 end
167- ir = strip (sprint (JuliaLowering. print_ir, x))
172+ ir = strip (sprint (JuliaLowering. print_ir, x, case . method_filter ))
168173 return replace (ir, string (mod)=> " TestMod" )
169174 catch exc
170175 if exc isa InterruptException
171176 rethrow ()
172- elseif expect_error && (exc isa LoweringError)
177+ elseif case . expect_error && (exc isa LoweringError)
173178 return sprint (io-> Base. showerror (io, exc, show_detail= false ))
174- elseif expect_error && (exc isa MacroExpansionError)
179+ elseif case . expect_error && (exc isa MacroExpansionError)
175180 return sprint (io-> Base. showerror (io, exc))
176- elseif is_broken
181+ elseif case . is_broken
177182 return sprint (io-> Base. showerror (io, exc))
178183 else
179- throw (" Error in test case \" $description \" " )
184+ throw (" Error in test case \" $(case . description) \" " )
180185 end
181186 end
182187end
183188
184189function test_ir_cases (filename:: AbstractString )
185190 preamble, cases = read_ir_test_cases (filename)
186191 test_mod = setup_ir_test_module (preamble)
187- for (expect_error, is_broken, description, input, ref) in cases
188- if is_broken
192+ for case in cases
193+ if case . is_broken
189194 continue
190195 end
191- output = format_ir_for_test (test_mod, description, input, expect_error )
192- @testset " $description " begin
193- if output != ref
196+ output = format_ir_for_test (test_mod, case )
197+ @testset " $(case . description) " begin
198+ if output != case . output
194199 # Do additional error dumping, as @test will not format errors in a nice way
195- @error " Test \" $description \" failed" output= Text (output) ref= Text (ref )
200+ @error " Test \" $(case . description) \" failed" output= Text (output) ref= Text (case . output )
196201 end
197- @test output == ref
202+ @test output == case . output
198203 end
199204 end
200205end
@@ -213,20 +218,20 @@ function refresh_ir_test_cases(filename, pattern=nothing)
213218 println (io, preamble, " \n " )
214219 println (io, " #*******************************************************************************" )
215220 end
216- for (expect_error, is_broken, description, input, ref) in cases
217- if isnothing (pattern) || occursin (pattern, description)
218- ir = format_ir_for_test (test_mod, description, input, expect_error, is_broken )
219- if rstrip (ir) != ref
220- @info " Refreshing test case $(repr (description)) in $filename "
221+ for case in cases
222+ if isnothing (pattern) || occursin (pattern, case . description)
223+ ir = format_ir_for_test (test_mod, case )
224+ if rstrip (ir) != case . output
225+ @info " Refreshing test case $(repr (case . description)) in $filename "
221226 end
222227 else
223- ir = ref
228+ ir = case . output
224229 end
225230 println (io,
226231 """
227232 ########################################
228- $(comment_description (description))
229- $(strip (input))
233+ $(comment_description (case . description))
234+ $(strip (case . input))
230235 #---------------------
231236 $ir
232237 """
0 commit comments