Skip to content

Commit 279155f

Browse files
committed
Add yamatanooroti test example
1 parent 45aeb52 commit 279155f

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@ Rake::TestTask.new(:test) do |t|
77
t.test_files = FileList["test/**/test_*.rb"]
88
end
99

10+
Rake::TestTask.new(:test_yamatanooroti) do |t|
11+
t.libs << 'test'
12+
t.libs << 'lib'
13+
#t.loader = :direct
14+
t.pattern = 'test/irb/yamatanooroti/test_*.rb'
15+
end
16+
1017
task :default => :test
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
require 'irb'
2+
3+
begin
4+
require 'yamatanooroti'
5+
6+
class IRB::TestRendering < Yamatanooroti::TestCase
7+
def setup
8+
@pwd = Dir.pwd
9+
suffix = '%010d' % Random.rand(0..65535)
10+
@tmpdir = File.join(File.expand_path(Dir.tmpdir), "test_irb_#{$$}_#{suffix}")
11+
begin
12+
Dir.mkdir(@tmpdir)
13+
rescue Errno::EEXIST
14+
FileUtils.rm_rf(@tmpdir)
15+
Dir.mkdir(@tmpdir)
16+
end
17+
@irbrc_backup = ENV['IRBRC']
18+
@irbrc_file = ENV['IRBRC'] = File.join(@tmpdir, 'temporaty_irbrc')
19+
File.unlink(@irbrc_file) if File.exist?(@irbrc_file)
20+
end
21+
22+
def teardown
23+
FileUtils.rm_rf(@tmpdir)
24+
ENV['IRBRC'] = @irbrc_backup
25+
ENV.delete('RELINE_TEST_PROMPT') if ENV['RELINE_TEST_PROMPT']
26+
end
27+
28+
def test_launch
29+
write_irbrc <<~'LINES'
30+
puts 'start IRB'
31+
LINES
32+
start_terminal(25, 80, %W{ruby -I#{@pwd}/lib -I#{@pwd}/../reline/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
33+
write(<<~EOC)
34+
'Hello, World!'
35+
EOC
36+
close
37+
assert_screen(<<~EOC)
38+
start IRB
39+
irb(main):001:0> 'Hello, World!'
40+
=> "Hello, World!"
41+
irb(main):002:0>
42+
EOC
43+
end
44+
45+
private def write_irbrc(content)
46+
File.open(@irbrc_file, 'w') do |f|
47+
f.write content
48+
end
49+
end
50+
end
51+
rescue LoadError, NameError
52+
# On Ruby repository, this test suit doesn't run because Ruby repo doesn't
53+
# have the yamatanooroti gem.
54+
end

0 commit comments

Comments
 (0)