Remove system method for E2E testing because depends on ruby command
This commit is contained in:
parent
82f496a84b
commit
20ad101701
Notes:
git
2020-10-05 19:51:01 +09:00
@ -1,6 +1,7 @@
|
|||||||
# frozen_string_literal: false
|
# frozen_string_literal: false
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'irb'
|
require 'irb'
|
||||||
|
require 'irb/ext/save-history'
|
||||||
require 'readline'
|
require 'readline'
|
||||||
|
|
||||||
module TestIRB
|
module TestIRB
|
||||||
@ -13,27 +14,60 @@ module TestIRB
|
|||||||
IRB.conf[:RC_NAME_GENERATOR] = nil
|
IRB.conf[:RC_NAME_GENERATOR] = nil
|
||||||
end
|
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
|
def test_history_save_1
|
||||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
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
|
exit
|
||||||
EXPECTED_HISTORY
|
EXPECTED_HISTORY
|
||||||
IRB.conf[:USE_READLINE] = true
|
|
||||||
IRB.conf[:SAVE_HISTORY] = 1
|
|
||||||
IRB.conf[:USE_READLINE] = true
|
|
||||||
IRBRC
|
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
3
|
3
|
||||||
4
|
4
|
||||||
IRB_HISTORY
|
INITIAL_HISTORY
|
||||||
stdin.write("5\nexit\n")
|
5
|
||||||
end
|
exit
|
||||||
|
INPUT
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_history_save_100
|
def test_history_save_100
|
||||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
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
|
1
|
||||||
2
|
2
|
||||||
3
|
3
|
||||||
@ -41,22 +75,20 @@ module TestIRB
|
|||||||
5
|
5
|
||||||
exit
|
exit
|
||||||
EXPECTED_HISTORY
|
EXPECTED_HISTORY
|
||||||
IRB.conf[:USE_READLINE] = true
|
|
||||||
IRB.conf[:SAVE_HISTORY] = 100
|
|
||||||
IRB.conf[:USE_READLINE] = true
|
|
||||||
IRBRC
|
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
3
|
3
|
||||||
4
|
4
|
||||||
IRB_HISTORY
|
INITIAL_HISTORY
|
||||||
stdin.write("5\nexit\n")
|
5
|
||||||
end
|
exit
|
||||||
|
INPUT
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_history_save_bignum
|
def test_history_save_bignum
|
||||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
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
|
1
|
||||||
2
|
2
|
||||||
3
|
3
|
||||||
@ -64,22 +96,20 @@ module TestIRB
|
|||||||
5
|
5
|
||||||
exit
|
exit
|
||||||
EXPECTED_HISTORY
|
EXPECTED_HISTORY
|
||||||
IRB.conf[:USE_READLINE] = true
|
|
||||||
IRB.conf[:SAVE_HISTORY] = 10 ** 19
|
|
||||||
IRB.conf[:USE_READLINE] = true
|
|
||||||
IRBRC
|
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
3
|
3
|
||||||
4
|
4
|
||||||
IRB_HISTORY
|
INITIAL_HISTORY
|
||||||
stdin.write("5\nexit\n")
|
5
|
||||||
end
|
exit
|
||||||
|
INPUT
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_history_save_minus_as_infinity
|
def test_history_save_minus_as_infinity
|
||||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
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
|
1
|
||||||
2
|
2
|
||||||
3
|
3
|
||||||
@ -87,58 +117,49 @@ module TestIRB
|
|||||||
5
|
5
|
||||||
exit
|
exit
|
||||||
EXPECTED_HISTORY
|
EXPECTED_HISTORY
|
||||||
IRB.conf[:USE_READLINE] = true
|
|
||||||
IRB.conf[:SAVE_HISTORY] = -1 # infinity
|
|
||||||
IRB.conf[:USE_READLINE] = true
|
|
||||||
IRBRC
|
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
3
|
3
|
||||||
4
|
4
|
||||||
IRB_HISTORY
|
INITIAL_HISTORY
|
||||||
stdin.write("5\nexit\n")
|
5
|
||||||
end
|
exit
|
||||||
|
INPUT
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def assert_history_with_irbrc_and_irb_history(expected_history, irbrc, irb_history)
|
def assert_history(expected_history, initial_irb_history, input)
|
||||||
result = nil
|
backup_verbose, $VERBOSE = $VERBOSE, nil
|
||||||
result_history = nil
|
|
||||||
backup_irbrc = ENV.delete("IRBRC")
|
|
||||||
backup_home = ENV["HOME"]
|
backup_home = ENV["HOME"]
|
||||||
|
IRB.conf[:LC_MESSAGES] = IRB::Locale.new
|
||||||
|
actual_history = nil
|
||||||
Dir.mktmpdir("test_irb_history_#{$$}") do |tmpdir|
|
Dir.mktmpdir("test_irb_history_#{$$}") do |tmpdir|
|
||||||
ENV["HOME"] = tmpdir
|
ENV["HOME"] = tmpdir
|
||||||
open(IRB.rc_file, "w") do |f|
|
|
||||||
f.write(irbrc)
|
|
||||||
end
|
|
||||||
open(IRB.rc_file("_history"), "w") do |f|
|
open(IRB.rc_file("_history"), "w") do |f|
|
||||||
f.write(irb_history)
|
f.write(initial_irb_history)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_temp_stdio do |stdin, stdout|
|
io = TestInputMethod.new
|
||||||
yield(stdin, stdout)
|
io.class::HISTORY.clear
|
||||||
stdin.close
|
io.load_history
|
||||||
stdout.flush
|
io.class::HISTORY.concat(input.split)
|
||||||
system('ruby', '-Ilib', '-Itest', '-W0', '-rirb', '-e', 'IRB.start(__FILE__)', in: stdin.path, out: stdout.path, err: stdout.path)
|
io.save_history
|
||||||
result = stdout.read
|
|
||||||
stdout.close
|
io.load_history
|
||||||
end
|
|
||||||
open(IRB.rc_file("_history"), "r") do |f|
|
open(IRB.rc_file("_history"), "r") do |f|
|
||||||
result_history = f.read
|
actual_history = f.read
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert_equal(expected_history, result_history, <<~MESSAGE)
|
assert_equal(expected_history, actual_history, <<~MESSAGE)
|
||||||
expected:
|
expected:
|
||||||
#{expected_history}
|
#{expected_history}
|
||||||
but actual:
|
but actual:
|
||||||
#{result_history}
|
#{actual_history}
|
||||||
and stdout and stderr ware
|
|
||||||
#{result}
|
|
||||||
MESSAGE
|
MESSAGE
|
||||||
ensure
|
ensure
|
||||||
|
$VERBOSE = backup_verbose
|
||||||
ENV["HOME"] = backup_home
|
ENV["HOME"] = backup_home
|
||||||
ENV["IRBRC"] = backup_irbrc
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_temp_stdio
|
def with_temp_stdio
|
||||||
|
Loading…
x
Reference in New Issue
Block a user