ruby-changes:58773
From: aycabta <ko1@a...>
Date: Wed, 13 Nov 2019 15:17:03 +0900 (JST)
Subject: [ruby-changes:58773] a5b6d7bca8 (master): Suppress warnings except for when last evaluation
https://git.ruby-lang.org/ruby.git/commit/?id=a5b6d7bca8 From a5b6d7bca84fce6e13c68e8753893c4697960e3a Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Wed, 13 Nov 2019 15:10:05 +0900 Subject: Suppress warnings except for when last evaluation Co-authored-by: Kazuhiro NISHIYAMA <zn@m...> diff --git a/lib/irb.rb b/lib/irb.rb index 97af046..2bf46aa 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -766,7 +766,10 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L766 # s-expression where the second selement of the top level array is an # array of parsed expressions. The first element of each expression is the # expression's type. - ASSIGNMENT_NODE_TYPES.include?(Ripper.sexp(line)&.dig(1,-1,0)) + verbose, $VERBOSE = $VERBOSE, nil + result = ASSIGNMENT_NODE_TYPES.include?(Ripper.sexp(line)&.dig(1,-1,0)) + $VERBOSE = verbose + result end ATTR_TTY = "\e[%sm" diff --git a/lib/irb/color.rb b/lib/irb/color.rb index 3ce628f..d2b9674 100644 --- a/lib/irb/color.rb +++ b/lib/irb/color.rb @@ -154,6 +154,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L154 def scan(code, allow_last_error:) pos = [1, 0] + verbose, $VERBOSE = $VERBOSE, nil lexer = Ripper::Lexer.new(code) if lexer.respond_to?(:scan) # Ruby 2.7+ lexer.scan.each do |elem| @@ -177,6 +178,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L178 yield(elem.event, elem.tok, elem.state) end end + $VERBOSE = verbose end def dispatch_seq(token, expr, str, in_symbol:) diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index a7b8ad8..58a3e1e 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -71,20 +71,27 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L71 end end + def ripper_lex_without_warning(code) + verbose, $VERBOSE = $VERBOSE, nil + tokens = Ripper.lex(code) + $VERBOSE = verbose + tokens + end + def set_auto_indent(context) if @io.respond_to?(:auto_indent) and context.auto_indent_mode @io.auto_indent do |lines, line_index, byte_pointer, is_newline| if is_newline md = lines[line_index - 1].match(/(\A +)/) prev_spaces = md.nil? ? 0 : md[1].count(' ') - @tokens = Ripper.lex(lines[0..line_index].join("\n")) + @tokens = ripper_lex_without_warning(lines[0..line_index].join("\n")) depth_difference = check_newline_depth_difference prev_spaces + depth_difference * 2 else code = line_index.zero? ? '' : lines[0..(line_index - 1)].map{ |l| l + "\n" }.join last_line = lines[line_index]&.byteslice(0, byte_pointer) code += last_line if last_line - @tokens = Ripper.lex(code) + @tokens = ripper_lex_without_warning(code) corresponding_token_depth = check_corresponding_token_depth if corresponding_token_depth corresponding_token_depth @@ -97,7 +104,7 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L104 end def check_state(code) - @tokens = Ripper.lex(code) + @tokens = ripper_lex_without_warning(code) ltype = process_literal_type indent = process_nesting_level continue = process_continue @@ -160,7 +167,7 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L167 end code = @line + (line.nil? ? '' : line) code.gsub!(/\s*\z/, '').concat("\n") - @tokens = Ripper.lex(code) + @tokens = ripper_lex_without_warning(code) @continue = process_continue @code_block_open = check_code_block(code) @indent = process_nesting_level diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb index d58477c..075db35 100644 --- a/test/irb/test_context.rb +++ b/test/irb/test_context.rb @@ -63,6 +63,12 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_context.rb#L63 assert_not_match(/rescue _\.class/, e.message) end + def test_evaluate_with_onigmo_warning + assert_warning("(irb):1: warning: character class has duplicated range: /[aa]/\n") do + @context.evaluate('/[aa]/', 1) + end + end + def test_eval_input verbose, $VERBOSE = $VERBOSE, nil input = TestInputMethod.new([ -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/