require_relative 'test_helper' class TestThread < TestDsl::TestCase let(:release) { 'eval Thread.main[:should_break] = true' } describe 'list' do it 'must show current thread by "plus" sign' do thnum = nil enter 'break 8', 'cont', 'thread list', release debug_file('thread') { thnum = Byebug.contexts.first.thnum } check_output_includes /\+ #{thnum} #\t#{fullpath('thread')}:8/ end it 'must work with shortcut' do thnum = nil enter 'break 8', 'cont', 'th list', release debug_file('thread') { thnum = Byebug.contexts.first.thnum } check_output_includes /\+ #{thnum} #\t#{fullpath('thread')}:8/ end it 'must show 3 available threads' do enter 'break 21', 'cont', 'thread list', release debug_file 'thread' check_output_includes /(\+)?\d+ #/, /(\+)?\d+ #/, /(\+)?\d+ #/ end end describe 'stop' do it 'must mark thread as suspended' do thnum = nil enter 'c 21', ->{ "thread stop #{Byebug.contexts.last.thnum}" }, release debug_file('thread') { thnum = Byebug.contexts.last.thnum } check_output_includes /\$ #{thnum} #{ "thread stop #{Byebug.contexts.last.thnum}" }, release debug_file('thread') check_output_doesnt_include /Tracing: #{fullpath('thread')}:16/, /Tracing: #{fullpath('thread')}:17/ end it 'must show error message if thread number is not specified' do enter 'break 8', 'cont', 'thread stop', release debug_file 'thread' check_error_includes '"thread stop" needs a thread number' end it 'must show error message when trying to stop current thread' do enter 'cont 8', ->{"thread stop #{Byebug.contexts.first.thnum}"}, release debug_file 'thread' check_error_includes "It's the current thread" end end describe 'resume' do it 'must mark remove thread from the suspended state' do thnum = nil enter 'cont 21', -> { thnum = Byebug.contexts.last.thnum ; "thread stop #{thnum}" }, -> { "thread resume #{thnum}" }, release debug_file('thread') { Byebug.contexts.last.suspended?.must_equal false } check_output_includes /\$ #{thnum} #{ "thread resume #{Byebug.contexts.first.thnum}" }, release debug_file 'thread' check_error_includes "It's the current thread" end it 'must show error message if it is not stopped' do enter 'c 21', ->{ "thread resume #{Byebug.contexts.last.thnum}" }, release debug_file 'thread' check_error_includes 'Already running' end end describe 'switch' do it 'must switch to another thread' do enter 'c 21', ->{ "thread switch #{Byebug.contexts.last.thnum}" }, release debug_file('thread') { $state.line.must_equal 16 } end it 'must show error message if thread number is not specified' do enter 'break 8', 'cont', 'thread switch', release debug_file 'thread' check_error_includes '"thread switch" needs a thread number' end it 'must show error message when trying to switch current thread' do enter 'c 8', ->{ "thread switch #{Byebug.contexts.first.thnum}" }, release debug_file 'thread' check_error_includes "It's the current thread" end end end