summaryrefslogtreecommitdiff
path: root/test/irb/command/test_force_exit.rb
blob: 9e86c644d6d8a428d9e18dfae0bf64ef8a0b6cce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: false
require 'irb'

require_relative "../helper"

module TestIRB
  class ForceExitTest < IntegrationTestCase
    def test_forced_exit_finishes_process_immediately
      write_ruby <<~'ruby'
        puts "First line"
        puts "Second line"
        binding.irb
        puts "Third line"
        binding.irb
        puts "Fourth line"
      ruby

      output = run_ruby_file do
        type "123"
        type "456"
        type "exit!"
      end

      assert_match(/First line\r\n/, output)
      assert_match(/Second line\r\n/, output)
      assert_match(/irb\(main\):001> 123/, output)
      assert_match(/irb\(main\):002> 456/, output)
      refute_match(/Third line\r\n/, output)
      refute_match(/Fourth line\r\n/, output)
    end

    def test_forced_exit_in_nested_sessions
      write_ruby <<~'ruby'
        def foo
          binding.irb
        end

        binding.irb
        binding.irb
      ruby

      output = run_ruby_file do
        type "123"
        type "foo"
        type "exit!"
      end

      assert_match(/irb\(main\):001> 123/, output)
    end

    def test_forced_exit_out_of_irb_session
      write_ruby <<~'ruby'
        at_exit { puts 'un' + 'reachable' }
        binding.irb
        exit! # this will call exit! method overrided by command
      ruby
      output = run_ruby_file do
        type "exit"
      end
      assert_not_include(output, 'unreachable')
    end
  end
end