byebug 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +8 -0
  3. data/AUTHORS +10 -0
  4. data/CHANGELOG.md +2 -0
  5. data/CONTRIBUTING.md +1 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +20 -0
  8. data/README.md +5 -0
  9. data/Rakefile +28 -0
  10. data/bin/byebug +395 -0
  11. data/byebug.gemspec +29 -0
  12. data/doc/hanoi.rb +35 -0
  13. data/doc/primes.rb +28 -0
  14. data/doc/rdebug-emacs.texi +1030 -0
  15. data/doc/test-tri2.rb +18 -0
  16. data/doc/tri3.rb +8 -0
  17. data/doc/triangle.rb +12 -0
  18. data/ext/byebug/breakpoint.c +476 -0
  19. data/ext/byebug/byebug.c +512 -0
  20. data/ext/byebug/byebug.h +131 -0
  21. data/ext/byebug/context.c +424 -0
  22. data/ext/byebug/extconf.rb +21 -0
  23. data/ext/byebug/locker.c +53 -0
  24. data/lib/byebug.rb +404 -0
  25. data/lib/byebug/command.rb +232 -0
  26. data/lib/byebug/commands/breakpoints.rb +153 -0
  27. data/lib/byebug/commands/catchpoint.rb +56 -0
  28. data/lib/byebug/commands/condition.rb +49 -0
  29. data/lib/byebug/commands/continue.rb +38 -0
  30. data/lib/byebug/commands/control.rb +110 -0
  31. data/lib/byebug/commands/display.rb +122 -0
  32. data/lib/byebug/commands/edit.rb +48 -0
  33. data/lib/byebug/commands/enable.rb +202 -0
  34. data/lib/byebug/commands/eval.rb +176 -0
  35. data/lib/byebug/commands/finish.rb +43 -0
  36. data/lib/byebug/commands/frame.rb +303 -0
  37. data/lib/byebug/commands/help.rb +56 -0
  38. data/lib/byebug/commands/info.rb +462 -0
  39. data/lib/byebug/commands/irb.rb +123 -0
  40. data/lib/byebug/commands/jump.rb +66 -0
  41. data/lib/byebug/commands/kill.rb +51 -0
  42. data/lib/byebug/commands/list.rb +94 -0
  43. data/lib/byebug/commands/method.rb +84 -0
  44. data/lib/byebug/commands/quit.rb +39 -0
  45. data/lib/byebug/commands/reload.rb +40 -0
  46. data/lib/byebug/commands/save.rb +90 -0
  47. data/lib/byebug/commands/set.rb +210 -0
  48. data/lib/byebug/commands/show.rb +246 -0
  49. data/lib/byebug/commands/skip.rb +35 -0
  50. data/lib/byebug/commands/source.rb +36 -0
  51. data/lib/byebug/commands/stepping.rb +83 -0
  52. data/lib/byebug/commands/threads.rb +189 -0
  53. data/lib/byebug/commands/tmate.rb +36 -0
  54. data/lib/byebug/commands/trace.rb +56 -0
  55. data/lib/byebug/commands/variables.rb +199 -0
  56. data/lib/byebug/context.rb +58 -0
  57. data/lib/byebug/helper.rb +69 -0
  58. data/lib/byebug/interface.rb +223 -0
  59. data/lib/byebug/processor.rb +468 -0
  60. data/lib/byebug/version.rb +3 -0
  61. data/man/rdebug.1 +241 -0
  62. data/test/breakpoints_test.rb +357 -0
  63. data/test/conditions_test.rb +77 -0
  64. data/test/continue_test.rb +44 -0
  65. data/test/display_test.rb +141 -0
  66. data/test/edit_test.rb +56 -0
  67. data/test/eval_test.rb +92 -0
  68. data/test/examples/breakpoint1.rb +15 -0
  69. data/test/examples/breakpoint2.rb +7 -0
  70. data/test/examples/conditions.rb +4 -0
  71. data/test/examples/continue.rb +4 -0
  72. data/test/examples/display.rb +5 -0
  73. data/test/examples/edit.rb +3 -0
  74. data/test/examples/edit2.rb +3 -0
  75. data/test/examples/eval.rb +4 -0
  76. data/test/examples/finish.rb +20 -0
  77. data/test/examples/frame.rb +20 -0
  78. data/test/examples/frame_threads.rb +31 -0
  79. data/test/examples/help.rb +2 -0
  80. data/test/examples/info.rb +38 -0
  81. data/test/examples/info2.rb +3 -0
  82. data/test/examples/info_threads.rb +48 -0
  83. data/test/examples/irb.rb +6 -0
  84. data/test/examples/jump.rb +14 -0
  85. data/test/examples/kill.rb +2 -0
  86. data/test/examples/list.rb +12 -0
  87. data/test/examples/method.rb +15 -0
  88. data/test/examples/post_mortem.rb +19 -0
  89. data/test/examples/quit.rb +2 -0
  90. data/test/examples/reload.rb +6 -0
  91. data/test/examples/restart.rb +6 -0
  92. data/test/examples/save.rb +3 -0
  93. data/test/examples/set.rb +3 -0
  94. data/test/examples/set_annotate.rb +12 -0
  95. data/test/examples/settings.rb +1 -0
  96. data/test/examples/show.rb +2 -0
  97. data/test/examples/source.rb +3 -0
  98. data/test/examples/stepping.rb +21 -0
  99. data/test/examples/thread.rb +32 -0
  100. data/test/examples/tmate.rb +10 -0
  101. data/test/examples/trace.rb +7 -0
  102. data/test/examples/trace_threads.rb +20 -0
  103. data/test/examples/variables.rb +26 -0
  104. data/test/finish_test.rb +48 -0
  105. data/test/frame_test.rb +143 -0
  106. data/test/help_test.rb +50 -0
  107. data/test/info_test.rb +313 -0
  108. data/test/irb_test.rb +81 -0
  109. data/test/jump_test.rb +70 -0
  110. data/test/kill_test.rb +48 -0
  111. data/test/list_test.rb +145 -0
  112. data/test/method_test.rb +70 -0
  113. data/test/post_mortem_test.rb +27 -0
  114. data/test/quit_test.rb +56 -0
  115. data/test/reload_test.rb +44 -0
  116. data/test/restart_test.rb +164 -0
  117. data/test/save_test.rb +92 -0
  118. data/test/set_test.rb +177 -0
  119. data/test/show_test.rb +293 -0
  120. data/test/source_test.rb +45 -0
  121. data/test/stepping_test.rb +130 -0
  122. data/test/support/breakpoint.rb +13 -0
  123. data/test/support/context.rb +14 -0
  124. data/test/support/matchers.rb +67 -0
  125. data/test/support/mocha_extensions.rb +72 -0
  126. data/test/support/processor.rb +7 -0
  127. data/test/support/test_dsl.rb +206 -0
  128. data/test/support/test_interface.rb +68 -0
  129. data/test/test_helper.rb +10 -0
  130. data/test/tmate_test.rb +44 -0
  131. data/test/trace_test.rb +159 -0
  132. data/test/variables_test.rb +119 -0
  133. metadata +265 -0
@@ -0,0 +1,44 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe "Reload Command" do
4
+ include TestDsl
5
+ temporary_change_hash_value(Byebug::Command.settings, :reload_source_on_change, false)
6
+
7
+ it "must notify that automatic reloading is off" do
8
+ enter 'reload'
9
+ debug_file 'reload'
10
+ check_output_includes "Source code is reloaded. Automatic reloading is off."
11
+ end
12
+
13
+ it "must notify that automatic reloading is on" do
14
+ enter 'set autoreload', 'reload'
15
+ debug_file 'reload'
16
+ check_output_includes "Source code is reloaded. Automatic reloading is on."
17
+ end
18
+
19
+ describe "reloading" do
20
+ after { change_line_in_file(fullpath('reload'), 4, '4') }
21
+ it "must reload the code" do
22
+ enter 'break 3', 'cont', 'l 4-4', -> do
23
+ change_line_in_file(fullpath('reload'), 4, '100')
24
+ 'reload'
25
+ end, 'l 4-4'
26
+ debug_file 'reload'
27
+ check_output_includes "4 100"
28
+ end
29
+ end
30
+
31
+ describe "Post Mortem" do
32
+ #after { change_line_in_file(fullpath('post_mortem'), 7, ' z = 4') }
33
+ it "must work in post-mortem mode" do
34
+ skip("No post morten mode for now")
35
+ #enter 'cont', -> do
36
+ # change_line_in_file(fullpath('post_mortem'), 7, 'z = 100')
37
+ # 'reload'
38
+ #end, 'l 7-7'
39
+ #debug_file 'post_mortem'
40
+ #check_output_includes "7 z = 100"
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,164 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe "Restart Command" do
4
+ include TestDsl
5
+
6
+ def must_restart
7
+ Byebug::RestartCommand.any_instance.unstub(:exec)
8
+ Byebug::RestartCommand.any_instance.expects(:exec)
9
+ end
10
+
11
+ describe "Restart Command 2" do
12
+
13
+ temporary_set_const(Byebug, "INITIAL_DIR",
14
+ Pathname.new(__FILE__ + "/../..").realpath.to_s)
15
+ temporary_set_const(Byebug, "PROG_SCRIPT",
16
+ Pathname.new(fullpath('restart')).realpath.to_s)
17
+ temporary_set_const(Byebug, "RDEBUG_SCRIPT", 'rdebug_script')
18
+ temporary_change_hash_value(Byebug::Command.settings, :argv, 'argv')
19
+ Byebug::RestartCommand.any_instance.stubs(:exec).
20
+ with("#{Byebug::RDEBUG_SCRIPT} argv")
21
+
22
+ it "must be restarted with arguments" do
23
+ Byebug::RestartCommand.any_instance.expects(:exec).
24
+ with("#{Byebug::RDEBUG_SCRIPT} test/examples/restart.rb 1 2 3")
25
+ enter 'restart 1 2 3'
26
+ debug_file('restart')
27
+ end
28
+
29
+ it "must be restarted without arguments" do
30
+ temporary_set_const(Byebug, "RDEBUG_SCRIPT", 'rdebug_script') do
31
+ temporary_set_const(Byebug, "PROG_SCRIPT",
32
+ Pathname.new(fullpath('restart')).
33
+ relative_path_from(Pathname.new(__FILE__ + "/../..")).
34
+ cleanpath.to_s) do
35
+ temporary_change_hash_value(Byebug::Command.settings, :argv, ['argv']) do
36
+ Byebug::RestartCommand.
37
+ any_instance.expects(:exec).with("#{Byebug::RDEBUG_SCRIPT} argv")
38
+ enter 'restart'
39
+ debug_file('restart')
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ it "must specify arguments by 'set' command" do
46
+ temporary_change_hash_value(Byebug::Command.settings, :argv, []) do
47
+ temporary_set_const(Byebug, "RDEBUG_SCRIPT", 'rdebug_script') do
48
+ Byebug::RestartCommand.any_instance.expects(:exec).with("#{Byebug::RDEBUG_SCRIPT} 1 2 3")
49
+ enter 'set args 1 2 3', 'restart'
50
+ debug_file('restart')
51
+ end
52
+ end
53
+ end
54
+
55
+ describe "messaging" do
56
+ before { enter 'restart' }
57
+
58
+ describe "reexecing" do
59
+
60
+ it "must restart" do
61
+ must_restart
62
+ debug_file('restart')
63
+ end
64
+
65
+ it "must show a message about reexecing" do
66
+ temporary_set_const(Byebug, "PROG_SCRIPT",
67
+ Pathname.new(fullpath('restart')).
68
+ relative_path_from(Pathname.new(__FILE__ + "/../..")).
69
+ cleanpath.to_s) do
70
+ temporary_change_hash_value(Byebug::Command.settings, :argv,
71
+ [Byebug::PROG_SCRIPT]) do
72
+ temporary_set_const(Byebug, "RDEBUG_SCRIPT",
73
+ Pathname.new(__FILE__ + "/../../bin/byebug").realpath.to_s) do
74
+ debug_file('restart')
75
+ check_output_includes "Re exec'ing:\n\t#{Byebug::RDEBUG_SCRIPT}"
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ describe "no script is specified and don't use $0" do
83
+ before do
84
+ force_set_const(Byebug, "DEFAULT_START_SETTINGS", init: false, post_mortem: false, tracing: nil)
85
+ end
86
+
87
+ it "must not restart" do
88
+ must_restart.never
89
+ debug_file('restart')
90
+ end
91
+
92
+ it "must show an error message" do
93
+ debug_file('restart')
94
+ check_output_includes "Don't know name of debugged program", interface.error_queue
95
+ end
96
+ end
97
+
98
+ it "must use prog_script from $0 if PROG_SCRIPT is undefined" do
99
+ $0 = 'prog-0'
100
+ Byebug.send(:remove_const, "PROG_SCRIPT")
101
+ force_set_const(Byebug, "DEFAULT_START_SETTINGS", init: true, post_mortem: false, tracing: nil)
102
+ debug_file('restart')
103
+ check_output_includes "Ruby program prog-0 doesn't exist", interface.error_queue
104
+ end
105
+
106
+ describe "no script at the specified path" do
107
+ before { force_set_const(Byebug, "PROG_SCRIPT", 'blabla') }
108
+
109
+ it "must not restart" do
110
+ must_restart.never
111
+ debug_file('restart')
112
+ end
113
+
114
+ it "must show an error message" do
115
+ debug_file('restart')
116
+ check_output_includes "Ruby program blabla doesn't exist", interface.error_queue
117
+ end
118
+ end
119
+
120
+ describe "byebug runner script is not specified" do
121
+
122
+ it "must restart anyway" do
123
+ must_restart
124
+ debug_file('restart')
125
+ end
126
+
127
+ it "must show a warning message" do
128
+ debug_file('restart')
129
+ check_output_includes "Byebug was not called from the outset..."
130
+ end
131
+
132
+ it "must show a warning message when prog script is not executable" do
133
+ debug_file('restart')
134
+ check_output_includes "Ruby program #{Byebug::PROG_SCRIPT} doesn't seem to be executable..."
135
+ check_output_includes "We'll add a call to Ruby."
136
+ end
137
+ end
138
+
139
+ describe "when can't change the dir to INITIAL_DIR" do
140
+ before { force_set_const(Byebug, "INITIAL_DIR", "unexisted/path") }
141
+
142
+ it "must restart anyway" do
143
+ must_restart
144
+ debug_file('restart')
145
+ end
146
+
147
+ it "must show an error message " do
148
+ debug_file('restart')
149
+ check_output_includes "Failed to change initial directory unexisted/path"
150
+ end
151
+ end
152
+ end
153
+
154
+ describe "Post Mortem" do
155
+ it "must work in post-mortem mode" do
156
+ skip("No post morten mode for now")
157
+ #must_restart
158
+ #enter 'cont', 'restart'
159
+ #debug_file 'post_mortem'
160
+ end
161
+ end
162
+
163
+ end
164
+ end
@@ -0,0 +1,92 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe "Save Command" do
4
+ include TestDsl
5
+ let(:file_name) { 'save_output.txt' }
6
+
7
+ describe "successful saving" do
8
+ let(:file_contents) { File.read(file_name) }
9
+ before do
10
+ enter 'break 2', 'break 3 if true', 'catch NoMethodError', 'display 2 + 3', 'display 5 + 6',
11
+ 'set autoeval', 'set autolist',
12
+ "save #{file_name}"
13
+ debug_file 'save'
14
+ end
15
+ after do
16
+ FileUtils.rm(file_name)
17
+ end
18
+
19
+ it "must save usual breakpoints" do
20
+ file_contents.must_include "break #{fullpath('save')}:2"
21
+ end
22
+
23
+ it "must save conditinal breakpoints" do
24
+ file_contents.must_include "break #{fullpath('save')}:3 if true"
25
+ end
26
+
27
+ it "must save catchpoints" do
28
+ file_contents.must_include "catch NoMethodError"
29
+ end
30
+
31
+ # Not sure why it is suppressed, but this is like it is now.
32
+ it "must not save displays" do
33
+ file_contents.wont_include "display 2 + 3"
34
+ end
35
+
36
+ describe "saving settings" do
37
+ it "must save autoeval" do
38
+ file_contents.must_include "set autoeval on"
39
+ end
40
+
41
+ it "must save basename" do
42
+ file_contents.must_include "set basename off"
43
+ end
44
+
45
+ it "must save byebugtesting" do
46
+ file_contents.must_include "set byebugtesting on"
47
+ end
48
+
49
+ it "must save autolist" do
50
+ file_contents.must_include "set autolist on"
51
+ end
52
+
53
+ it "must save autoirb" do
54
+ file_contents.must_include "set autoirb off"
55
+ end
56
+ end
57
+
58
+ it "must show a message about successful saving" do
59
+ check_output_includes "Saved to '#{file_name}'"
60
+ end
61
+
62
+ end
63
+
64
+ describe "without filename" do
65
+ let(:file_contents) { File.read(interface.restart_file) }
66
+ after { FileUtils.rm(interface.restart_file) }
67
+
68
+ it "must fabricate a filename if not provided" do
69
+ enter "save"
70
+ debug_file 'save'
71
+ file_contents.must_include "set autoirb"
72
+ end
73
+
74
+ it "must show a message where the file is saved" do
75
+ enter "save"
76
+ debug_file 'save'
77
+ check_output_includes "Saved to '#{interface.restart_file}'"
78
+ end
79
+ end
80
+
81
+ describe "Post Mortem" do
82
+ #let(:file_contents) { File.read(file_name) }
83
+ #after { FileUtils.rm(file_name) }
84
+ it "must work in post-mortem mode" do
85
+ skip("No post morten mode for now")
86
+ #enter 'cont', "save #{file_name}"
87
+ #debug_file 'post_mortem'
88
+ #file_contents.must_include "set autoirb off"
89
+ end
90
+ end
91
+
92
+ end
@@ -0,0 +1,177 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe "Set Command" do
4
+ include TestDsl
5
+
6
+ describe "setting to on" do
7
+ temporary_change_hash_value(Byebug::Command.settings, :autolist, 0)
8
+
9
+ it "must set a setting to on" do
10
+ enter 'set autolist on'
11
+ debug_file 'set'
12
+ Byebug::Command.settings[:autolist].must_equal 1
13
+ end
14
+
15
+ it "must set a setting to on by 1" do
16
+ enter 'set autolist 1'
17
+ debug_file 'set'
18
+ Byebug::Command.settings[:autolist].must_equal 1
19
+ end
20
+
21
+ it "must set a setting to on by default" do
22
+ enter 'set autolist'
23
+ debug_file 'set'
24
+ Byebug::Command.settings[:autolist].must_equal 1
25
+ end
26
+
27
+ it "must set a setting using shortcut" do
28
+ enter 'set autol'
29
+ debug_file 'set'
30
+ Byebug::Command.settings[:autolist].must_equal 1
31
+ end
32
+ end
33
+
34
+ describe "setting to off" do
35
+ temporary_change_hash_value(Byebug::Command.settings, :autolist, 1)
36
+
37
+ it "must set a setting to off" do
38
+ enter 'set autolist off'
39
+ debug_file 'set'
40
+ Byebug::Command.settings[:autolist].must_equal 0
41
+ end
42
+
43
+ it "must set a setting to off by 0" do
44
+ enter 'set autolist 0'
45
+ debug_file 'set'
46
+ Byebug::Command.settings[:autolist].must_equal 0
47
+ end
48
+
49
+ it "must set a setting to off by 'no' suffix" do
50
+ enter 'set noautolist'
51
+ debug_file 'set'
52
+ Byebug::Command.settings[:autolist].must_equal 0
53
+ end
54
+ end
55
+
56
+ describe "messages" do
57
+ temporary_change_hash_value(Byebug::Command.settings, :autolist, 0)
58
+
59
+ it "must show a message after setting" do
60
+ enter 'set autolist on'
61
+ debug_file 'set'
62
+ check_output_includes "autolist is on."
63
+ end
64
+ end
65
+
66
+ describe "byebugtesting" do
67
+ temporary_change_hash_value(Byebug::Command.settings, :byebugtesting, false)
68
+ before { $rdebug_state = nil }
69
+ after { $rdebug_state = nil }
70
+
71
+ it "must set $rdebug_context if byebugsetting is on" do
72
+ enter 'set byebugtesting', 'break 3', 'cont'
73
+ debug_file('set') { state.must_be_kind_of Byebug::CommandProcessor::State }
74
+ end
75
+
76
+ it "must set basename on too" do
77
+ temporary_change_hash_value(Byebug::Command.settings, :basename, false) do
78
+ enter 'set byebugtesting', 'show basename'
79
+ debug_file('set')
80
+ check_output_includes "basename is on."
81
+ end
82
+ end
83
+
84
+ it "must not set $rdebug_context if byebugsetting is off" do
85
+ enter 'set nobyebugtesting', 'break 3', 'cont'
86
+ debug_file('set') { state.must_be_nil }
87
+ end
88
+ end
89
+
90
+ describe "history" do
91
+ describe "save" do
92
+ it "must set history save to on" do
93
+ enter 'set history save on'
94
+ debug_file 'set'
95
+ interface.history_save.must_equal true
96
+ end
97
+
98
+ it "must show a message" do
99
+ enter 'set history save on'
100
+ debug_file 'set'
101
+ check_output_includes "Saving of history save is on."
102
+ end
103
+
104
+ it "must set history save to off" do
105
+ enter 'set history save off'
106
+ debug_file 'set'
107
+ interface.history_save.must_equal false
108
+ end
109
+ end
110
+
111
+ describe "size" do
112
+ it "must set history size" do
113
+ enter 'set history size 250'
114
+ debug_file 'set'
115
+ interface.history_length.must_equal 250
116
+ end
117
+
118
+ it "must show a message" do
119
+ enter 'set history size 250'
120
+ debug_file 'set'
121
+ check_output_includes "Byebug history size is 250"
122
+ end
123
+ end
124
+
125
+ describe "filename" do
126
+ it "must set history filename" do
127
+ enter 'set history filename .byebug-hist'
128
+ debug_file 'set'
129
+ interface.histfile.must_equal File.join(ENV["HOME"]||ENV["HOMEPATH"]||".", '.byebug-hist')
130
+ end
131
+
132
+ it "must show a message" do
133
+ enter 'set history filename .byebug-hist'
134
+ debug_file 'set'
135
+ check_output_includes "The filename in which to record the command history is \"#{File.join(ENV["HOME"]||ENV["HOMEPATH"]||".", ".byebug-hist")}\""
136
+ end
137
+ end
138
+
139
+ it "must show an error message if used wrong subcommand" do
140
+ enter 'set history bla 2'
141
+ debug_file 'set'
142
+ check_output_includes "Invalid history parameter bla. Should be 'filename', 'save' or 'size'."
143
+ end
144
+
145
+ it "must show an error message if provided only one argument" do
146
+ enter 'set history save'
147
+ debug_file 'set'
148
+ check_output_includes "Need two parameters for 'set history'; got 1."
149
+ end
150
+ end
151
+
152
+ describe "width" do
153
+ temporary_change_hash_value(Byebug::Command.settings, :width, 20)
154
+
155
+ it "must set ENV['COLUMNS'] by the 'set width' command" do
156
+ old_columns = ENV["COLUMNS"]
157
+ begin
158
+ enter 'set width 10'
159
+ debug_file 'set'
160
+ ENV["COLUMNS"].must_equal '10'
161
+ ensure
162
+ ENV["COLUMNS"] = old_columns
163
+ end
164
+ end
165
+ end
166
+
167
+ describe "Post Mortem" do
168
+ temporary_change_hash_value(Byebug::Command.settings, :autolist, 0)
169
+ it "must work in post-mortem mode" do
170
+ skip("No post morten mode for now")
171
+ #enter 'cont', "set autolist on"
172
+ #debug_file 'post_mortem'
173
+ #check_output_includes "autolist is on."
174
+ end
175
+ end
176
+
177
+ end