ruby-changes:74455
From: Stan <ko1@a...>
Date: Sat, 12 Nov 2022 06:05:49 +0900 (JST)
Subject: [ruby-changes:74455] 14a1394bcd (master): [ruby/irb] Simplify info command's tests
https://git.ruby-lang.org/ruby.git/commit/?id=14a1394bcd From 14a1394bcd85c90c9f14f687fd4a80ba5b96b437 Mon Sep 17 00:00:00 2001 From: Stan Lo <stan001212@g...> Date: Fri, 11 Nov 2022 21:05:31 +0000 Subject: [ruby/irb] Simplify info command's tests (https://github.com/ruby/irb/pull/440) https://github.com/ruby/irb/commit/5942949226 --- test/irb/test_cmd.rb | 290 ++++++++++++++++++++++++--------------------------- 1 file changed, 136 insertions(+), 154 deletions(-) diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb index eafa8be382..3af4ccec98 100644 --- a/test/irb/test_cmd.rb +++ b/test/irb/test_cmd.rb @@ -5,7 +5,7 @@ require "irb/extend-command" https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L5 require_relative "helper" module TestIRB - class ExtendCommand < TestCase + class ExtendCommandTest < TestCase class TestInputMethod < ::IRB::InputMethod attr_reader :list, :line_no @@ -58,164 +58,146 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L58 restore_encodings end - def test_irb_info_multiline - FileUtils.touch("#{@tmpdir}/.inputrc") - FileUtils.touch("#{@tmpdir}/.irbrc") - IRB.setup(__FILE__, argv: []) - IRB.conf[:USE_MULTILINE] = true - IRB.conf[:USE_SINGLELINE] = false - IRB.conf[:VERBOSE] = false - lang_backup = ENV.delete("LANG") - lc_all_backup = ENV.delete("LC_ALL") - workspace = IRB::WorkSpace.new(self) - irb = IRB::Irb.new(workspace, TestInputMethod.new([])) - IRB.conf[:MAIN_CONTEXT] = irb.context - expected = %r{ - Ruby\sversion:\s.+\n - IRB\sversion:\sirb\s.+\n - InputMethod:\sAbstract\sInputMethod\n - \.irbrc\spath:\s.+\n - RUBY_PLATFORM:\s.+\n - East\sAsian\sAmbiguous\sWidth:\s\d\n - #{@is_win ? 'Code\spage:\s\d+\n' : ''} - }x - assert_match expected, irb.context.main.irb_info.to_s - ensure - ENV["LANG"] = lang_backup - ENV["LC_ALL"] = lc_all_backup - end + class InfoCommandTest < ExtendCommandTest + def setup + super + @locals_backup = ENV.delete("LANG"), ENV.delete("LC_ALL") + end - def test_irb_info_singleline - FileUtils.touch("#{@tmpdir}/.inputrc") - FileUtils.touch("#{@tmpdir}/.irbrc") - IRB.setup(__FILE__, argv: []) - IRB.conf[:USE_MULTILINE] = false - IRB.conf[:USE_SINGLELINE] = true - IRB.conf[:VERBOSE] = false - lang_backup = ENV.delete("LANG") - lc_all_backup = ENV.delete("LC_ALL") - workspace = IRB::WorkSpace.new(self) - irb = IRB::Irb.new(workspace, TestInputMethod.new([])) - IRB.conf[:MAIN_CONTEXT] = irb.context - expected = %r{ - Ruby\sversion:\s.+\n - IRB\sversion:\sirb\s.+\n - InputMethod:\sAbstract\sInputMethod\n - \.irbrc\spath:\s.+\n - RUBY_PLATFORM:\s.+\n - East\sAsian\sAmbiguous\sWidth:\s\d\n - #{@is_win ? 'Code\spage:\s\d+\n' : ''} - }x - info = irb.context.main.irb_info - capture_output do - # Reline::Core#ambiguous_width may access STDOUT, not $stdout - stdout = STDOUT.dup - STDOUT.reopen(IO::NULL, "w") - info = info.to_s + def teardown + super + ENV["LANG"], ENV["LC_ALL"] = @locals_backup + end + + def test_irb_info_multiline + FileUtils.touch("#{@tmpdir}/.inputrc") + FileUtils.touch("#{@tmpdir}/.irbrc") + + out, err = execute_lines( + "irb_info", + conf: { USE_MULTILINE: true, USE_SINGLELINE: false } + ) + + expected = %r{ + Ruby\sversion:\s.+\n + IRB\sversion:\sirb\s.+\n + InputMethod:\sAbstract\sInputMethod\n + \.irbrc\spath:\s.+\n + RUBY_PLATFORM:\s.+\n + East\sAsian\sAmbiguous\sWidth:\s\d\n + #{@is_win ? 'Code\spage:\s\d+\n' : ''} + }x + + assert_empty err + assert_match expected, out + end + + def test_irb_info_singleline + FileUtils.touch("#{@tmpdir}/.inputrc") + FileUtils.touch("#{@tmpdir}/.irbrc") + + out, err = execute_lines( + "irb_info", + conf: { USE_MULTILINE: false, USE_SINGLELINE: true } + ) + + expected = %r{ + Ruby\sversion:\s.+\n + IRB\sversion:\sirb\s.+\n + InputMethod:\sAbstract\sInputMethod\n + \.irbrc\spath:\s.+\n + RUBY_PLATFORM:\s.+\n + East\sAsian\sAmbiguous\sWidth:\s\d\n + #{@is_win ? 'Code\spage:\s\d+\n' : ''} + }x + + assert_empty err + assert_match expected, out + end + + def test_irb_info_multiline_without_rc_files + inputrc_backup = ENV["INPUTRC"] + ENV["INPUTRC"] = "unknown_inpurc" + ext_backup = IRB::IRBRC_EXT + IRB.__send__(:remove_const, :IRBRC_EXT) + IRB.const_set(:IRBRC_EXT, "unknown_ext") + + out, err = execute_lines( + "irb_info", + conf: { USE_MULTILINE: true, USE_SINGLELINE: false } + ) + + expected = %r{ + Ruby\sversion:\s.+\n + IRB\sversion:\sirb\s.+\n + InputMethod:\sAbstract\sInputMethod\n + RUBY_PLATFORM:\s.+\n + East\sAsian\sAmbiguous\sWidth:\s\d\n + #{@is_win ? 'Code\spage:\s\d+\n' : ''} + }x + + assert_empty err + assert_match expected, out ensure - STDOUT.reopen(stdout) - stdout.close + ENV["INPUTRC"] = inputrc_backup + IRB.__send__(:remove_const, :IRBRC_EXT) + IRB.const_set(:IRBRC_EXT, ext_backup) end - assert_match expected, info - ensure - ENV["LANG"] = lang_backup - ENV["LC_ALL"] = lc_all_backup - end - def test_irb_info_multiline_without_rc_files - inputrc_backup = ENV["INPUTRC"] - ENV["INPUTRC"] = "unknown_inpurc" - ext_backup = IRB::IRBRC_EXT - IRB.__send__(:remove_const, :IRBRC_EXT) - IRB.const_set(:IRBRC_EXT, "unknown_ext") - IRB.setup(__FILE__, argv: []) - IRB.conf[:USE_MULTILINE] = true - IRB.conf[:USE_SINGLELINE] = false - IRB.conf[:VERBOSE] = false - lang_backup = ENV.delete("LANG") - lc_all_backup = ENV.delete("LC_ALL") - workspace = IRB::WorkSpace.new(self) - irb = IRB::Irb.new(workspace, TestInputMethod.new([])) - IRB.conf[:MAIN_CONTEXT] = irb.context - expected = %r{ - Ruby\sversion:\s.+\n - IRB\sversion:\sirb\s.+\n - InputMethod:\sAbstract\sInputMethod\n - RUBY_PLATFORM:\s.+\n - East\sAsian\sAmbiguous\sWidth:\s\d\n - #{@is_win ? 'Code\spage:\s\d+\n' : ''} - \z - }x - assert_match expected, irb.context.main.irb_info.to_s - ensure - ENV["INPUTRC"] = inputrc_backup - IRB.__send__(:remove_const, :IRBRC_EXT) - IRB.const_set(:IRBRC_EXT, ext_backup) - ENV["LANG"] = lang_backup - ENV["LC_ALL"] = lc_all_backup - end + def test_irb_info_singleline_without_rc_files + inputrc_backup = ENV["INPUTRC"] + ENV["INPUTRC"] = "unknown_inpurc" + ext_backup = IRB::IRBRC_EXT + IRB.__send__(:remove_const, :IRBRC_EXT) + IRB.const_set(:IRBRC_EXT, "unknown_ext") - def test_irb_info_singleline_without_rc_files - inputrc_backup = ENV["INPUTRC"] - ENV["INPUTRC"] = "unknown_inpurc" - ext_backup = IRB::IRBRC_EXT - IRB.__send__(:remove_const, :IRBRC_EXT) - IRB.const_set(:IRBRC_EXT, "unknown_ext") - IRB.setup(__FILE__, argv: []) - IRB.conf[:USE_MULTILINE] = false - IRB.conf[:USE_SINGLELINE] = true - IRB.conf[:VERBOSE] = false - lang_backup = ENV.delete("LANG") - lc_all_backup = ENV.delete("LC_ALL") - workspace = IRB::WorkSpace.new(self) - irb = IRB::Irb.new(workspace, TestInputMethod.new([])) - IRB.conf[:MAIN_CONTEXT] = irb.context - expected = %r{ - Ruby\sversion:\s.+\n - IRB\sversion:\sirb\s.+\n - InputMethod:\sAbstract\sInputMethod\n - RUBY_PLATFORM:\s.+\n - East\sAsian\sAmbiguous\sWidth:\s\d\n - #{@is_win ? 'Code\spage:\s\d+\n' : ''} - \z - }x - assert_match expected, irb.context.main.irb_info.to_s - ensure - ENV["INPUTRC"] = inputrc_backup - IRB.__send__(:remove_const, :IRBRC_EXT) - IRB.const_set(:IRBRC_EXT, ext_backup) - ENV["LANG"] = lang_backup - ENV["LC_ALL"] = lc_all_backup - end + out, err = execute_lines( + "irb_info", + conf: { USE_MULTILINE: false, USE_SINGLELINE: true } + ) - def test_irb_info_lang - FileUtils.touch("#{@tmpdir}/.inputrc") - FileUtils.touch("#{@tmpdir}/.irbrc") - IRB.setup(__FILE__, argv: []) - IRB.conf[:USE_MULTILINE] = true - IRB.conf[:USE_SINGLELINE] = false - IRB.conf[:VERBOSE] = false - lang_backup = ENV.delete("LANG") - lc_all_backup = ENV.delete("LC_ALL") - ENV["LANG"] = "ja_JP.UTF-8" - ENV["LC_ALL"] = "en_US.UTF-8" - workspace = IRB::WorkSpace.new(self) - irb = IRB::Irb.new(workspace, TestInputMethod.new([])) - IRB.conf[:MAIN_CONTEXT] = irb.context - expected = %r{ - Ruby\sversion: .+\n - IRB\sversion:\sirb .+\n - InputMethod:\sAbstract\sInputMethod\n - \.irbrc\spath: .+\n - RUBY_PLATFORM: .+\n - LANG\senv:\sja_JP\.UTF-8\n - LC_ALL\senv:\sen_US\.UTF-8\n - East\sAsian\sAmbiguous\sWidth:\s\d\n - }x - assert_match expected, irb.context.main.irb_info.to_s - ensure - ENV["LANG"] = lang_backup - ENV["LC_ALL"] = lc_all_backup + expected = %r{ + Ruby\sversion:\s.+\n + IRB\sversion:\sirb\s.+\n + InputMethod:\sAbstract\sInputMethod\n + RUBY_PLATFORM:\s.+\n + East\sAsian\sAmbiguous\sWidth:\s\d\n + #{@is_win ? 'Code\spage:\s\d+\n' : ''} + }x + + assert_empty err + assert_match expected, out + ensure + ENV["INPUTRC"] = inputrc_backup + IRB.__send__(:remove_const, :IRBRC_EX (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/