File: tracevar_test.rb

package info (click to toggle)
ruby-byebug 11.1.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,252 kB
  • sloc: ruby: 8,835; ansic: 1,662; sh: 6; makefile: 4
file content (71 lines) | stat: -rw-r--r-- 2,001 bytes parent folder | download | duplicates (3)
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
64
65
66
67
68
69
70
71
# frozen_string_literal: true

require "test_helper"

module Byebug
  #
  # Tests gloabal variable tracing functionality.
  #
  class TracevarTest < TestCase
    def program
      strip_line_numbers <<-RUBY
         1:  module Byebug
         2:    #
         3:    # Toy class to test global variable tracing
         4:    #
         5:    class #{example_class}
         6:      def with_verbose(value)
         7:        previous = $VERBOSE
         8:        $VERBOSE = value
         9:        yield
        10:      ensure
        11:        $VERBOSE = previous
        12:      end
        13:    end
        14:
        15:    #{example_class}.new.with_verbose(true) do
        16:      byebug
        17:      $VERBOSE = false
        18:      $VERBOSE ||= true
        19:      $VERBOSE &&= false
        20:    end
        21:  end
      RUBY
    end

    def test_tracevar_tracks_global_variables
      enter "tracevar $VERBOSE", "cont 19", "untracevar $VERBOSE"
      debug_code(program)

      check_output_includes \
        "traced global variable '$VERBOSE' has value 'false'",
        "traced global variable '$VERBOSE' has value 'true'"
    end

    def test_tracevar_stop_makes_program_stop_when_global_var_changes
      enter "tracevar $VERBOSE stop", "cont 19", "untracevar $VERBOSE"

      debug_code(program) { assert_equal 18, frame.line }
    end

    def test_tracevar_nostop_does_not_stop_when_global_var_changes
      enter "tracevar $VERBOSE nostop", "cont 19", "untracevar $VERBOSE"

      debug_code(program) { assert_equal 19, frame.line }
    end

    def test_tracevar_shows_an_error_message_if_no_global_variable_is_specified
      enter "tracevar"
      debug_code(program)

      check_error_includes("tracevar needs a global variable name")
    end

    def test_tracevar_shows_an_error_message_if_there_is_no_such_global_var
      enter "tracevar $FOO"
      debug_code(program)

      check_error_includes "'$FOO' is not a global variable."
    end
  end
end