Skip to content

Commit

Permalink
Add a failing test for #115
Browse files Browse the repository at this point in the history
  • Loading branch information
David Rodríguez committed Feb 21, 2015
1 parent f86514c commit 99bd326
Showing 1 changed file with 59 additions and 7 deletions.
66 changes: 59 additions & 7 deletions test/commands/eval_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ def test_eval_properly_evaluates_expressions
check_output_includes '5'
end

def test_eval_properly_evals_expressions_involving_threads
enter 'eval Thread.new {}.join'
debug_code(program)
check_output_includes(/#<Thread:0x.* dead>/)
end

def test_eval_properly_evaluates_an_expression_using_timeout
def test_eval_properly_evaluates_expressions_using_threads
require 'timeout'
enter 'eval Timeout::timeout(60) { 1 }'
debug_code(program)
check_output_includes '1'
end

def test_eval_does_not_hang_when_evaluating_expressions_using_new_threads
enter 'eval Thread.new {}.join'
debug_code(program)
check_output_includes(/#<Thread:0x.* dead>/)
end

def test_eval_works_when_inspect_raises_an_exception
enter 'c 18', 'eval @foo'
debug_code(program) { assert_equal 18, state.line }
Expand Down Expand Up @@ -97,5 +97,57 @@ def test_putl_prints_expression_and_sorts_and_columnize_the_result
debug_code(program)
check_output_includes '1 3 5 7 9', '2 4 6 8'
end

def program_threads
<<-EOC
module Byebug
#
# Toy class to test evaluation in Byebug's prompt
#
class Hola
def initialize
Thread.new do
loop do
sleep 0.01
next if numbers.empty?
squares << (numbers.pop)**2
end
end
end
def numbers
@numbers ||= Queue.new
end
def squares
@squares ||= []
end
def calc(number)
numbers.push(number)
loop do
next if squares.empty?
return squares.pop
end
end
end
worker = Hola.new
byebug
'Processed: ' + worker.squares.join(' ')
end
EOC
end

def test_eval_does_not_hang_when_evaluating_expressions_using_old_threads
skip
enter 'eval worker.calc(10)'
debug_code(program_threads)
check_output_includes '100'
end
end
end

0 comments on commit 99bd326

Please sign in to comment.