summaryrefslogtreecommitdiff
path: root/test/irb
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2021-02-06 20:23:51 +0900
committergit <svn-admin@ruby-lang.org>2021-02-06 20:45:08 +0900
commit5704b5fe5e42bd5b1f42a27368cd5d52dd5a9060 (patch)
tree4c8f1a274875baa8613c2c4012fc79851b866ee4 /test/irb
parente1e61e256bd65ac3f293ba1513d1a934b9a3bff9 (diff)
[ruby/irb] Allow "measure" command to take block
https://github.com/ruby/irb/commit/20f1ca23e9
Diffstat (limited to 'test/irb')
-rw-r--r--test/irb/test_cmd.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb
index 106e4d2..045ce0f 100644
--- a/test/irb/test_cmd.rb
+++ b/test/irb/test_cmd.rb
@@ -276,6 +276,40 @@ module TestIRB
assert_match(/\A=> 3\nCUSTOM is added\.\n=> nil\ncustom processing time: .+\n=> 3\n=> nil\n=> 3\n/, out)
end
+ def test_measure_with_proc
+ IRB.init_config(nil)
+ IRB.conf[:PROMPT] = {
+ DEFAULT: {
+ PROMPT_I: '> ',
+ PROMPT_S: '> ',
+ PROMPT_C: '> ',
+ PROMPT_N: '> '
+ }
+ }
+ IRB.conf[:VERBOSE] = false
+ IRB.conf[:PROMPT_MODE] = :DEFAULT
+ IRB.conf[:MEASURE] = false
+ input = TestInputMethod.new([
+ "3\n",
+ "measure { |context, code, line_no, &block|\n",
+ " result = block.()\n",
+ " puts 'aaa' if IRB.conf[:MEASURE]\n",
+ "}\n",
+ "3\n",
+ "measure :off\n",
+ "3\n",
+ ])
+ c = Class.new(Object)
+ irb = IRB::Irb.new(IRB::WorkSpace.new(c.new), input)
+ irb.context.return_format = "=> %s\n"
+ out, err = capture_output do
+ irb.eval_input
+ end
+ assert_empty err
+ assert_match(/\A=> 3\nBLOCK is added\.\n=> nil\naaa\n=> 3\n=> nil\n=> 3\n/, out)
+ assert_empty(c.class_variables)
+ end
+
def test_irb_source
IRB.init_config(nil)
File.write("#{@tmpdir}/a.rb", "a = 'hi'\n")