[前][次][番号順一覧][スレッド一覧]

ruby-changes:63272

From: aycabta <ko1@a...>
Date: Mon, 5 Oct 2020 19:50:54 +0900 (JST)
Subject: [ruby-changes:63272] 20ad101701 (master): Remove system method for E2E testing because depends on ruby command

https://git.ruby-lang.org/ruby.git/commit/?id=20ad101701

From 20ad1017017ea736667d86fa0250dc1a39daefa1 Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Mon, 5 Oct 2020 18:57:47 +0900
Subject: Remove system method for E2E testing because depends on ruby command


diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb
index 8942d24..392a6af 100644
--- a/test/irb/test_history.rb
+++ b/test/irb/test_history.rb
@@ -1,6 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/test/irb/test_history.rb#L1
 # frozen_string_literal: false
 require 'test/unit'
 require 'irb'
+require 'irb/ext/save-history'
 require 'readline'
 
 module TestIRB
@@ -13,27 +14,60 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_history.rb#L14
       IRB.conf[:RC_NAME_GENERATOR] = nil
     end
 
+    class TestInputMethod < ::IRB::InputMethod
+      HISTORY = Array.new
+
+      include IRB::HistorySavingAbility
+
+      attr_reader :list, :line_no
+
+      def initialize(list = [])
+        super("test")
+        @line_no = 0
+        @list = list
+      end
+
+      def gets
+        @list[@line_no]&.tap {@line_no += 1}
+      end
+
+      def eof?
+        @line_no >= @list.size
+      end
+
+      def encoding
+        Encoding.default_external
+      end
+
+      def reset
+        @line_no = 0
+      end
+
+      def winsize
+        [10, 20]
+      end
+    end
+
     def test_history_save_1
       omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
-      assert_history_with_irbrc_and_irb_history(<<~EXPECTED_HISTORY, <<~IRBRC, <<~IRB_HISTORY) do |stdin|
+      IRB.conf[:SAVE_HISTORY] = 1
+      assert_history(<<~EXPECTED_HISTORY, <<~INITIAL_HISTORY, <<~INPUT)
         exit
       EXPECTED_HISTORY
-        IRB.conf[:USE_READLINE] = true
-        IRB.conf[:SAVE_HISTORY] = 1
-        IRB.conf[:USE_READLINE] = true
-      IRBRC
         1
         2
         3
         4
-      IRB_HISTORY
-        stdin.write("5\nexit\n")
-      end
+      INITIAL_HISTORY
+        5
+        exit
+      INPUT
     end
 
     def test_history_save_100
       omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
-      assert_history_with_irbrc_and_irb_history(<<~EXPECTED_HISTORY, <<~IRBRC, <<~IRB_HISTORY) do |stdin|
+      IRB.conf[:SAVE_HISTORY] = 100
+      assert_history(<<~EXPECTED_HISTORY, <<~INITIAL_HISTORY, <<~INPUT)
         1
         2
         3
@@ -41,22 +75,20 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_history.rb#L75
         5
         exit
       EXPECTED_HISTORY
-        IRB.conf[:USE_READLINE] = true
-        IRB.conf[:SAVE_HISTORY] = 100
-        IRB.conf[:USE_READLINE] = true
-      IRBRC
         1
         2
         3
         4
-      IRB_HISTORY
-        stdin.write("5\nexit\n")
-      end
+      INITIAL_HISTORY
+        5
+        exit
+      INPUT
     end
 
     def test_history_save_bignum
       omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
-      assert_history_with_irbrc_and_irb_history(<<~EXPECTED_HISTORY, <<~IRBRC, <<~IRB_HISTORY) do |stdin|
+      IRB.conf[:SAVE_HISTORY] = 10 ** 19
+      assert_history(<<~EXPECTED_HISTORY, <<~INITIAL_HISTORY, <<~INPUT)
         1
         2
         3
@@ -64,22 +96,20 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_history.rb#L96
         5
         exit
       EXPECTED_HISTORY
-        IRB.conf[:USE_READLINE] = true
-        IRB.conf[:SAVE_HISTORY] = 10 ** 19
-        IRB.conf[:USE_READLINE] = true
-      IRBRC
         1
         2
         3
         4
-      IRB_HISTORY
-        stdin.write("5\nexit\n")
-      end
+      INITIAL_HISTORY
+        5
+        exit
+      INPUT
     end
 
     def test_history_save_minus_as_infinity
       omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
-      assert_history_with_irbrc_and_irb_history(<<~EXPECTED_HISTORY, <<~IRBRC, <<~IRB_HISTORY) do |stdin|
+      IRB.conf[:SAVE_HISTORY] = -1 # infinity
+      assert_history(<<~EXPECTED_HISTORY, <<~INITIAL_HISTORY, <<~INPUT)
         1
         2
         3
@@ -87,58 +117,49 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_history.rb#L117
         5
         exit
       EXPECTED_HISTORY
-        IRB.conf[:USE_READLINE] = true
-        IRB.conf[:SAVE_HISTORY] = -1 # infinity
-        IRB.conf[:USE_READLINE] = true
-      IRBRC
         1
         2
         3
         4
-      IRB_HISTORY
-        stdin.write("5\nexit\n")
-      end
+      INITIAL_HISTORY
+        5
+        exit
+      INPUT
     end
 
     private
 
-    def assert_history_with_irbrc_and_irb_history(expected_history, irbrc, irb_history)
-      result = nil
-      result_history = nil
-      backup_irbrc = ENV.delete("IRBRC")
+    def assert_history(expected_history, initial_irb_history, input)
+      backup_verbose, $VERBOSE = $VERBOSE, nil
       backup_home = ENV["HOME"]
+      IRB.conf[:LC_MESSAGES] = IRB::Locale.new
+      actual_history = nil
       Dir.mktmpdir("test_irb_history_#{$$}") do |tmpdir|
         ENV["HOME"] = tmpdir
-        open(IRB.rc_file, "w") do |f|
-          f.write(irbrc)
-        end
         open(IRB.rc_file("_history"), "w") do |f|
-          f.write(irb_history)
+          f.write(initial_irb_history)
         end
 
-        with_temp_stdio do |stdin, stdout|
-          yield(stdin, stdout)
-          stdin.close
-          stdout.flush
-          system('ruby', '-Ilib', '-Itest', '-W0', '-rirb', '-e', 'IRB.start(__FILE__)', in: stdin.path, out: stdout.path, err: stdout.path)
-          result = stdout.read
-          stdout.close
-        end
+        io = TestInputMethod.new
+        io.class::HISTORY.clear
+        io.load_history
+        io.class::HISTORY.concat(input.split)
+        io.save_history
+
+        io.load_history
         open(IRB.rc_file("_history"), "r") do |f|
-          result_history = f.read
+          actual_history = f.read
         end
       end
-      assert_equal(expected_history, result_history, <<~MESSAGE)
+      assert_equal(expected_history, actual_history, <<~MESSAGE)
         expected:
         #{expected_history}
         but actual:
-        #{result_history}
-        and stdout and stderr ware
-        #{result}
+        #{actual_history}
       MESSAGE
     ensure
+      $VERBOSE = backup_verbose
       ENV["HOME"] = backup_home
-      ENV["IRBRC"] = backup_irbrc
     end
 
     def with_temp_stdio
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]