File: eval_test.rb

package info (click to toggle)
ruby-byebug 13.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,288 kB
  • sloc: ruby: 9,013; ansic: 1,692; makefile: 4; sh: 4
file content (61 lines) | stat: -rw-r--r-- 1,389 bytes parent folder | download
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
# frozen_string_literal: true

require "test_helper"

module Byebug
  #
  # Tests expression evaluation.
  #
  class EvalTest < TestCase
    def program
      strip_line_numbers <<-RUBY
         1:  module Byebug
         2:    Foo = "Foo constant"
         3:    foo = :foo_variable
         4:    byebug
         5:  end
      RUBY
    end

    def test_eval_prints_values
      enter "Foo", "foo"
      debug_code(program)
      check_output_includes('"Foo constant"')
      check_output_includes(":foo_variable")
    end
  end

  #
  # Tests expression evalution of the code that uses TracePoint.
  #
  class EvalTracePointClassTest < TestCase
    def program
      strip_line_numbers <<-RUBY
         1:  result = :tp_class_not_called
         2:  autoload :Foo, "./foo"
         3:  TracePoint.new(:class) { |tp| result = :tp_class_called }.enable
         4:  byebug
         5:  result
      RUBY
    end

    def foo_program
      strip_line_numbers <<-RUBY
         1:  module Foo
         2:    def self.bar
         3:      "Foo.bar called"
         4:    end
         5:  end
      RUBY
    end

    def test_eval_triggers_class_tracepoint
      with_new_file("foo.rb", foo_program) do
        enter "Foo.bar", "result"
        debug_code(program)
        check_output_includes('"Foo.bar called"')
        check_output_includes(":tp_class_called")
      end
    end
  end
end