Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add display tests #123

Merged
merged 2 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/debug/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,7 @@ def process_command line
case arg
when /(\d+)/
if @displays[n = $1.to_i]
if ask "clear \##{n} #{@displays[n]}?"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think confirmation should be required when deleting a specific display setting. This is unnecessary imo and inconsistent with the delete command.

@displays.delete_at n
end
@displays.delete_at n
end
@tc << [:eval, :display, @displays]
when nil
Expand Down
68 changes: 68 additions & 0 deletions test/debug/display_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# frozen_string_literal: true

require_relative '../support/test_case'

module DEBUGGER__
class DisplayTest < TestCase
def program
<<~RUBY
1| a = 1
2| b = 2
3| binding.bp
4| __END__
RUBY
end

def test_display_displays_expressions_when_the_program_stopps
debug_code(program) do
type "display a"
assert_line_text(/0: a =/)
type "display b"
assert_line_text(/0: a = /)
assert_line_text(/1: b = /)
type "continue"
assert_line_text(/0: a = 1/)
assert_line_text(/1: b = 2/)

type "q!"
end
end

def test_display_without_expression_lists_display_settings
debug_code(program) do
type "display a"
type "display b"
type "display"
assert_line_text(/0: a = /)
assert_line_text(/1: b = /)

type "q!"
end
end

def test_undisplay_deletes_a_given_display_setting
debug_code(program) do
type "display a"
type "undisplay 0"
type "y"
type "continue"
assert_no_line_text(/0: a =/)

type "q!"
end
end

def test_undisplay_without_expression_deletes_all_display_settings
debug_code(program) do
type "display a"
type "display b"
type "undisplay"
type "y"
assert_no_line_text(/0: a = /)
assert_no_line_text(/1: b = /)

type "q!"
end
end
end
end
2 changes: 1 addition & 1 deletion test/support/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def debug_code(program, **options, &block)
end

DEBUG_MODE = false
ASK_CMD = %w[quit delete kill]
ASK_CMD = %w[quit delete kill undisplay]

def debug_print msg
print msg if DEBUG_MODE
Expand Down