File: source_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 (61 lines) | stat: -rw-r--r-- 1,246 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
# frozen_string_literal: true

require "test_helper"

module Byebug
  #
  # Tests reading Byebug commands from a file.
  #
  class SourceTest < TestCase
    def program
      strip_line_numbers <<-RUBY
        1:  module Byebug
        2:    byebug
        3:
        4:    a = 2
        5:    a + 3
        6:  end
      RUBY
    end

    def setup
      File.open("source_example.txt", "w") do |f|
        f.puts "break 4"
        f.puts "break 5 if true"
      end

      super
    end

    def teardown
      File.delete("source_example.txt")
      super
    rescue StandardError
      retry
    end

    def test_source_runs_byebug_commands_from_file
      enter "source source_example.txt"

      debug_code(program) do
        assert_equal 4, Breakpoint.first.pos
        assert_equal 5, Breakpoint.last.pos
        assert_equal "true", Breakpoint.last.expr
      end
    end

    def test_source_shows_an_error_if_file_not_found
      enter "source blabla"
      debug_code(program)

      check_error_includes(/File ".*blabla" not found/)
    end

    def test_source_without_arguments_shows_help
      enter "source"
      debug_code(program)

      check_output_includes("Restores a previously saved byebug session")
    end
  end
end