@@ -211,6 +211,13 @@ def test_irb_info_lang
211211 end
212212
213213 class MeasureTest < CommandTestCase
214+ CUSTOM_MEASURE_PROC = proc { |context , line , line_no , &block |
215+ raise 'Wrong argument' unless IRB ::Context === context && String === line && Integer === line_no
216+ time = Time . now
217+ result = block . ( )
218+ puts 'custom processing time: %fs' % ( Time . now - time ) if IRB . conf [ :MEASURE ]
219+ result
220+ }
214221 def test_measure
215222 conf = {
216223 PROMPT : {
@@ -295,12 +302,6 @@ def test_measure_enabled_by_rc
295302 end
296303
297304 def test_measure_enabled_by_rc_with_custom
298- measuring_proc = proc { |line , line_no , &block |
299- time = Time . now
300- result = block . ( )
301- puts 'custom processing time: %fs' % ( Time . now - time ) if IRB . conf [ :MEASURE ]
302- result
303- }
304305 conf = {
305306 PROMPT : {
306307 DEFAULT : {
@@ -311,7 +312,7 @@ def test_measure_enabled_by_rc_with_custom
311312 } ,
312313 PROMPT_MODE : :DEFAULT ,
313314 MEASURE : true ,
314- MEASURE_PROC : { CUSTOM : measuring_proc }
315+ MEASURE_PROC : { CUSTOM : CUSTOM_MEASURE_PROC }
315316 }
316317
317318 out , err = execute_lines (
@@ -325,12 +326,6 @@ def test_measure_enabled_by_rc_with_custom
325326 end
326327
327328 def test_measure_with_custom
328- measuring_proc = proc { |line , line_no , &block |
329- time = Time . now
330- result = block . ( )
331- puts 'custom processing time: %fs' % ( Time . now - time ) if IRB . conf [ :MEASURE ]
332- result
333- }
334329 conf = {
335330 PROMPT : {
336331 DEFAULT : {
@@ -341,7 +336,7 @@ def test_measure_with_custom
341336 } ,
342337 PROMPT_MODE : :DEFAULT ,
343338 MEASURE : false ,
344- MEASURE_PROC : { CUSTOM : measuring_proc }
339+ MEASURE_PROC : { CUSTOM : CUSTOM_MEASURE_PROC }
345340 }
346341 out , err = execute_lines (
347342 "3\n " ,
@@ -368,12 +363,12 @@ def test_measure_toggle
368363 PROMPT_MODE : :DEFAULT ,
369364 MEASURE : false ,
370365 MEASURE_PROC : {
371- FOO : proc { |&block | puts ' foo' ; block . call } ,
372- BAR : proc { |&block | puts ' bar' ; block . call }
366+ FOO : proc { |ctx , line , line_no , arg , &block | puts " foo( #{ arg . inspect } )" ; block . call } ,
367+ BAR : proc { |ctx , line , line_no , arg , &block | puts " bar( #{ arg . inspect } )" ; block . call }
373368 }
374369 }
375370 out , err = execute_lines (
376- "measure :foo\n " ,
371+ "measure :foo, :arg \n " ,
377372 "1\n " ,
378373 "measure :on, :bar\n " ,
379374 "2\n " ,
@@ -385,7 +380,7 @@ def test_measure_toggle
385380 )
386381
387382 assert_empty err
388- assert_match ( /\A FOO is added\. \n => nil\n foo\n => 1\n BAR is added\. \n => nil\n bar\n foo\n => 2\n => nil\n bar\n => 3\n => nil\n => 4\n / , out )
383+ assert_match ( /\A FOO is added\. \n => nil\n foo\( :arg \) \ n => 1\n BAR is added\. \n => nil\n bar\( nil \) \ n foo\( :arg \) \ n => 2\n => nil\n bar\( nil \) \n => 3\n => nil\n => 4\n / , out )
389384 end
390385
391386 def test_measure_with_proc_warning
0 commit comments