File: save_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 (94 lines) | stat: -rw-r--r-- 2,281 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# frozen_string_literal: true

require "test_helper"

module Byebug
  #
  # Tests saving Byebug commands to a file.
  #
  class SaveTest < TestCase
    def program
      strip_line_numbers <<-RUBY
        1:  module Byebug
        2:    byebug
        3:    a = 2
        4:    a + 3
        5:  end
      RUBY
    end

    def cleanup(file)
      File.delete(file)
    end

    def file_contents
      File.read(Setting[:savefile])
    end

    def test_save_records_regular_breakpoints
      enter "break 3", "save"
      debug_code(program)

      assert_includes file_contents, "break #{example_path}:3"
      cleanup(Setting[:savefile])
    end

    def test_save_records_conditional_breakpoints
      enter "break 4 if true", "save"
      debug_code(program)

      assert_includes file_contents, "break #{example_path}:4 if true"
      cleanup(Setting[:savefile])
    end

    def test_save_records_catchpoints
      enter "catch NoMethodError", "save", "catch NoMethodError off"
      debug_code(program)

      assert_includes file_contents, "catch NoMethodError"
      cleanup(Setting[:savefile])
    end

    def test_save_records_displays
      enter "display 2 + 3", "save"
      debug_code(program) { clear_displays }

      assert_includes file_contents, "display 2 + 3"
      cleanup(Setting[:savefile])
    end

    def test_save_records_current_state_of_settings
      enter "save"
      debug_code(program)

      assert_includes file_contents, "set basename false"
      assert_includes file_contents, "set autolist true"
      assert_includes file_contents, "set autoirb false"
      cleanup(Setting[:savefile])
    end

    def test_save_shows_a_success_message
      enter "save"
      debug_code(program)

      check_output_includes "Saved to '#{Setting[:savefile]}'"
      cleanup(Setting[:savefile])
    end

    def test_save_without_a_filename_uses_a_default_file
      enter "save output.txt"
      debug_code(program)

      assert_includes File.read("output.txt"), "set autoirb false"
      cleanup("output.txt")
    end

    def test_save_without_a_filename_shows_a_message_with_the_file_used
      enter "save output.txt"
      debug_code(program)

      check_output_includes "Saved to 'output.txt'"
      cleanup("output.txt")
    end
  end
end