diff --git a/README.md b/README.md index 99fa145..d8a19b8 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,11 @@ You can test the executed result and its rendering on the automatically detected require 'yamatanooroti' class MyTest < Yamatanooroti::TestCase - def setup - start_terminal(5, 30, ['irb', '-f', '--multiline']) - end - def test_example + start_terminal(5, 30, ['irb', '-f', '--multiline']) write(":a\n") - close assert_screen(['irb(main):001:0> :a', '=> :a', 'irb(main):002:0>', '', '']) + close end end ``` @@ -57,14 +54,11 @@ If you want to specify vterm environment that needs vterm gem, you can use `Yama require 'yamatanooroti' class MyTest < Yamatanooroti::VTermTestCase - def setup - start_terminal(5, 30, ['irb', '-f', '--multiline']) - end - def test_example + start_terminal(5, 30, ['irb', '-f', '--multiline']) write(":a\n") - close assert_screen(['irb(main):001:0> :a', '=> :a', 'irb(main):002:0>', '', '']) + close end end ``` @@ -82,15 +76,15 @@ Starts terminal internally that is sized `height` and `width` with `command` to If `startup_message` is given, `start_terminal` waits for the string to be printed and then returns. ```ruby -code = 'sleep 1; puts "aaa"; sleep 10; puts "bbb"' -start_terminal(5, 30, ['ruby', '-e', code], startup_message: 'aaa') -close +code = 'sleep 1; print "prompt>"; s = gets; sleep 1; puts s.upcase' +start_terminal(5, 30, ['ruby', '-e', code], startup_message: 'prompt>') +# Screen is already "prompt>" +write "hello\n" assert_screen(<<~EOC) - aaa + prompt>hello + HELLO EOC -# The start_terminal method waits for the output of the "aaa" as specified by -# the startup_message option, the "bbb" after 10 seconds won't come because -# the I/O is closed immediately after it. +close ``` ### `write(str)` diff --git a/test/yamatanooroti/test_multiplatform.rb b/test/yamatanooroti/test_multiplatform.rb index dbcd1af..85fe0fd 100644 --- a/test/yamatanooroti/test_multiplatform.rb +++ b/test/yamatanooroti/test_multiplatform.rb @@ -5,9 +5,12 @@ def setup start_terminal(5, 30, ['ruby', 'bin/simple_repl'], startup_message: 'prompt>') end + def teardown + close + end + def test_example write(":a\n") - close assert_screen(['prompt> :a', '=> :a', 'prompt>', '', '']) assert_screen(<<~EOC) prompt> :a @@ -23,14 +26,12 @@ def test_result_repeatedly write(":b\n") assert_screen(/=> :b\nprompt>/) assert_equal(['prompt> :a', '=> :a', 'prompt> :b', '=> :b', 'prompt>'], result) - close end def test_assert_screen_retries write("sleep 1\n") assert_screen(/=> 1\nprompt>/) assert_equal(['prompt> sleep 1', '=> 1', 'prompt>', '', ''], result) - close end def test_assert_screen_timeout @@ -38,12 +39,10 @@ def test_assert_screen_timeout assert_raise do assert_screen(/=> 3\nprompt>/) end - close end def test_auto_wrap write("12345678901234567890123\n") - close assert_screen(['prompt> 1234567890123456789012', '3', '=> 12345678901234567890123', 'prompt>', '']) assert_screen(<<~EOC) prompt> 1234567890123456789012 @@ -55,14 +54,12 @@ def test_auto_wrap def test_fullwidth write(":あ\n") - close assert_screen(/=> :あ\nprompt>/) assert_equal(['prompt> :あ', '=> :あ', 'prompt>', '', ''], result) end def test_two_fullwidth write(":あい\n") - close assert_screen(/=> :あい\nprompt>/) assert_equal(['prompt> :あい', '=> :あい', 'prompt>', '', ''], result) end diff --git a/test/yamatanooroti/test_run_ruby.rb b/test/yamatanooroti/test_run_ruby.rb index 28d7b7d..e4407f7 100644 --- a/test/yamatanooroti/test_run_ruby.rb +++ b/test/yamatanooroti/test_run_ruby.rb @@ -4,31 +4,29 @@ class Yamatanooroti::TestRunRuby < Yamatanooroti::TestCase def test_winsize start_terminal(5, 30, ['ruby', '-rio/console', '-e', 'puts(IO.console.winsize.inspect)']) - sleep 0.5 - close assert_screen(<<~EOC) [5, 30] EOC + close end def test_wait_for_startup_message - code = 'sleep 1; puts "aaa"; sleep 10; puts "bbb"' - start_terminal(5, 30, ['ruby', '-e', code], startup_message: 'aaa') - # The start_terminal method waits 1 sec for "aaa" as specified by - # wait_for_startup_message option and close immediately by the close - # method at the next line. The next "bbb" after waiting 1 sec more doesn't - # be caught because I/O is already closed. - close + code = 'sleep 1; print "prompt>"; s = gets; sleep 1; puts s.upcase' + start_terminal(5, 30, ['ruby', '-e', code], startup_message: 'prompt>') + assert_equal(['prompt>', '', '', '', ''], result) + write "hello\n" assert_screen(<<~EOC) - aaa + prompt>hello + HELLO EOC + close end def test_move_cursor_and_render start_terminal(5, 30, ['ruby', '-rio/console', '-e', 'STDOUT.puts(?A);STDOUT.goto(2,2);STDOUT.puts(?B)']) - assert_screen(/^ B/) - close + assert_screen(['A', '', ' B', '', '']) assert_equal(['A', '', ' B', '', ''], result) + close end def test_meta_key @@ -37,22 +35,22 @@ def test_meta_key write('aaa ccc') write("\M-b") write('bbb ') - close assert_screen(<<~EOC) >>>aaa bbb ccc EOC + close ensure get_out_from_tmpdir end def test_assert_screen_takes_a_message_when_failed start_terminal(5, 30, ['ruby', '-e', 'puts "aaa"']) - close assert_raise_with_message Test::Unit::AssertionFailedError, /\Amessage when failed/ do assert_screen(<<~EOC, 'message when failed') bbb EOC end + close end private