debugger 1.2.4 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. data/.gitignore +14 -0
  2. data/.travis.yml +0 -1
  3. data/CHANGELOG.md +9 -0
  4. data/Gemfile +3 -0
  5. data/README.md +2 -0
  6. data/Rakefile +3 -55
  7. data/debugger.gemspec +2 -0
  8. data/lib/debugger/version.rb +1 -1
  9. data/lib/ruby-debug-base.rb +3 -1
  10. data/lib/ruby-debug/commands/irb.rb +1 -1
  11. data/lib/ruby-debug/commands/jump.rb +1 -1
  12. data/lib/ruby-debug/commands/method.rb +1 -1
  13. data/lib/ruby-debug/commands/show.rb +1 -1
  14. data/lib/ruby-debug/commands/trace.rb +2 -2
  15. data/lib/ruby-debug/commands/variables.rb +3 -3
  16. data/test/breakpoints_test.rb +365 -0
  17. data/test/conditions_test.rb +76 -0
  18. data/test/continue_test.rb +28 -0
  19. data/test/display_test.rb +141 -0
  20. data/test/edit_test.rb +55 -0
  21. data/test/eval_test.rb +92 -0
  22. data/test/examples/breakpoint1.rb +15 -0
  23. data/test/examples/breakpoint2.rb +7 -0
  24. data/test/examples/conditions.rb +4 -0
  25. data/test/examples/continue.rb +4 -0
  26. data/test/examples/display.rb +5 -0
  27. data/test/examples/edit.rb +3 -0
  28. data/test/examples/edit2.rb +3 -0
  29. data/test/examples/eval.rb +4 -0
  30. data/test/examples/finish.rb +20 -0
  31. data/test/examples/frame.rb +31 -0
  32. data/test/examples/help.rb +2 -0
  33. data/test/examples/info.rb +48 -0
  34. data/test/examples/info2.rb +3 -0
  35. data/test/examples/irb.rb +6 -0
  36. data/test/examples/jump.rb +14 -0
  37. data/test/examples/kill.rb +2 -0
  38. data/test/examples/list.rb +12 -0
  39. data/test/examples/method.rb +15 -0
  40. data/test/examples/post_mortem.rb +19 -0
  41. data/test/examples/quit.rb +2 -0
  42. data/test/examples/reload.rb +6 -0
  43. data/test/examples/restart.rb +6 -0
  44. data/test/examples/save.rb +3 -0
  45. data/test/examples/set.rb +3 -0
  46. data/test/examples/set_annotate.rb +12 -0
  47. data/test/examples/settings.rb +1 -0
  48. data/test/examples/show.rb +2 -0
  49. data/test/examples/source.rb +3 -0
  50. data/test/examples/stepping.rb +21 -0
  51. data/test/examples/thread.rb +32 -0
  52. data/test/examples/tmate.rb +10 -0
  53. data/test/examples/trace.rb +7 -0
  54. data/test/examples/trace_threads.rb +20 -0
  55. data/test/examples/variables.rb +26 -0
  56. data/test/finish_test.rb +48 -0
  57. data/test/frame_test.rb +140 -0
  58. data/test/help_test.rb +50 -0
  59. data/test/info_test.rb +325 -0
  60. data/test/irb_test.rb +81 -0
  61. data/test/jump_test.rb +70 -0
  62. data/test/kill_test.rb +47 -0
  63. data/test/list_test.rb +145 -0
  64. data/test/method_test.rb +70 -0
  65. data/test/post_mortem_test.rb +25 -0
  66. data/test/quit_test.rb +55 -0
  67. data/test/reload_test.rb +43 -0
  68. data/test/restart_test.rb +143 -0
  69. data/test/save_test.rb +92 -0
  70. data/test/set_test.rb +163 -0
  71. data/test/show_test.rb +292 -0
  72. data/test/source_test.rb +44 -0
  73. data/test/stepping_test.rb +118 -0
  74. data/test/support/breakpoint.rb +12 -0
  75. data/test/support/context.rb +14 -0
  76. data/test/support/matchers.rb +67 -0
  77. data/test/support/mocha_extensions.rb +71 -0
  78. data/test/support/processor.rb +7 -0
  79. data/test/support/test_dsl.rb +205 -0
  80. data/test/support/test_interface.rb +66 -0
  81. data/test/test_helper.rb +8 -0
  82. data/test/thread_test.rb +122 -0
  83. data/test/tmate_test.rb +43 -0
  84. data/test/trace_test.rb +154 -0
  85. data/test/variables_test.rb +114 -0
  86. metadata +107 -158
  87. data/test/base/base.rb +0 -71
  88. data/test/base/binding.rb +0 -24
  89. data/test/base/catchpoint.rb +0 -22
  90. data/test/base/load.rb +0 -36
  91. data/test/bp_loop_issue.rb +0 -3
  92. data/test/classes.rb +0 -11
  93. data/test/config.yaml +0 -8
  94. data/test/data/annotate.cmd +0 -29
  95. data/test/data/annotate.right +0 -139
  96. data/test/data/break_bad.cmd +0 -18
  97. data/test/data/break_bad.right +0 -28
  98. data/test/data/break_loop_bug.cmd +0 -5
  99. data/test/data/break_loop_bug.right +0 -15
  100. data/test/data/breakpoints.cmd +0 -38
  101. data/test/data/breakpoints.right +0 -98
  102. data/test/data/catch.cmd +0 -20
  103. data/test/data/catch.right +0 -49
  104. data/test/data/catch2.cmd +0 -19
  105. data/test/data/catch2.right +0 -65
  106. data/test/data/catch3.cmd +0 -11
  107. data/test/data/catch3.right +0 -37
  108. data/test/data/condition.cmd +0 -28
  109. data/test/data/condition.right +0 -65
  110. data/test/data/ctrl.cmd +0 -23
  111. data/test/data/ctrl.right +0 -70
  112. data/test/data/display.cmd +0 -24
  113. data/test/data/display.right +0 -44
  114. data/test/data/dollar-0.right +0 -2
  115. data/test/data/dollar-0a.right +0 -2
  116. data/test/data/dollar-0b.right +0 -2
  117. data/test/data/edit.cmd +0 -12
  118. data/test/data/edit.right +0 -19
  119. data/test/data/emacs_basic.cmd +0 -43
  120. data/test/data/emacs_basic.right +0 -106
  121. data/test/data/enable.cmd +0 -20
  122. data/test/data/enable.right +0 -36
  123. data/test/data/finish.cmd +0 -16
  124. data/test/data/finish.right +0 -31
  125. data/test/data/frame.cmd +0 -26
  126. data/test/data/frame.right +0 -55
  127. data/test/data/help.cmd +0 -20
  128. data/test/data/help.right +0 -21
  129. data/test/data/history.right +0 -7
  130. data/test/data/info-thread.cmd +0 -13
  131. data/test/data/info-thread.right +0 -37
  132. data/test/data/info-var-bug2.cmd +0 -5
  133. data/test/data/info-var-bug2.right +0 -10
  134. data/test/data/info-var.cmd +0 -23
  135. data/test/data/info-var.right +0 -52
  136. data/test/data/info.cmd +0 -21
  137. data/test/data/info.right +0 -65
  138. data/test/data/jump.cmd +0 -16
  139. data/test/data/jump.right +0 -56
  140. data/test/data/jump2.cmd +0 -16
  141. data/test/data/jump2.right +0 -44
  142. data/test/data/linetrace.cmd +0 -6
  143. data/test/data/linetrace.right +0 -23
  144. data/test/data/list.cmd +0 -19
  145. data/test/data/list.right +0 -127
  146. data/test/data/method.cmd +0 -10
  147. data/test/data/method.right +0 -21
  148. data/test/data/methodsig.cmd +0 -10
  149. data/test/data/methodsig.right +0 -20
  150. data/test/data/next.cmd +0 -22
  151. data/test/data/next.right +0 -61
  152. data/test/data/noquit.right +0 -1
  153. data/test/data/output.cmd +0 -6
  154. data/test/data/output.right +0 -31
  155. data/test/data/pm-bug.cmd +0 -7
  156. data/test/data/pm-bug.right +0 -12
  157. data/test/data/post-mortem-next.cmd +0 -8
  158. data/test/data/post-mortem-next.right +0 -14
  159. data/test/data/post-mortem-osx.right +0 -31
  160. data/test/data/post-mortem.cmd +0 -13
  161. data/test/data/post-mortem.right +0 -32
  162. data/test/data/quit.cmd +0 -6
  163. data/test/data/quit.right +0 -0
  164. data/test/data/raise.cmd +0 -11
  165. data/test/data/raise.right +0 -23
  166. data/test/data/save.cmd +0 -34
  167. data/test/data/save.right +0 -59
  168. data/test/data/scope-var.cmd +0 -42
  169. data/test/data/scope-var.right +0 -587
  170. data/test/data/setshow.cmd +0 -56
  171. data/test/data/setshow.right +0 -98
  172. data/test/data/source.cmd +0 -5
  173. data/test/data/source.right +0 -15
  174. data/test/data/stepping.cmd +0 -21
  175. data/test/data/stepping.right +0 -50
  176. data/test/data/test-init-cygwin.right +0 -7
  177. data/test/data/test-init-osx.right +0 -4
  178. data/test/data/test-init.right +0 -5
  179. data/test/data/trace.right +0 -14
  180. data/test/dollar-0.rb +0 -5
  181. data/test/gcd-dbg-nox.rb +0 -30
  182. data/test/gcd-dbg.rb +0 -29
  183. data/test/gcd.rb +0 -18
  184. data/test/helper.rb +0 -142
  185. data/test/info-var-bug.rb +0 -47
  186. data/test/info-var-bug2.rb +0 -2
  187. data/test/jump.rb +0 -14
  188. data/test/jump2.rb +0 -27
  189. data/test/lib/commands/catchpoint_test.rb +0 -28
  190. data/test/lib/commands/unit/regexp.rb +0 -38
  191. data/test/next.rb +0 -18
  192. data/test/null.rb +0 -1
  193. data/test/output.rb +0 -2
  194. data/test/pm-base.rb +0 -17
  195. data/test/pm-bug.rb +0 -3
  196. data/test/pm-catch.rb +0 -12
  197. data/test/pm-catch2.rb +0 -27
  198. data/test/pm-catch3.rb +0 -47
  199. data/test/pm.rb +0 -11
  200. data/test/raise.rb +0 -3
  201. data/test/rdebug-save.1 +0 -7
  202. data/test/runall +0 -12
  203. data/test/scope-var.rb +0 -29
  204. data/test/tdebug.rb +0 -246
  205. data/test/test-annotate.rb +0 -24
  206. data/test/test-break-bad.rb +0 -36
  207. data/test/test-breakpoints.rb +0 -24
  208. data/test/test-catch.rb +0 -24
  209. data/test/test-catch2.rb +0 -24
  210. data/test/test-catch3.rb +0 -24
  211. data/test/test-condition.rb +0 -24
  212. data/test/test-ctrl.rb +0 -51
  213. data/test/test-display.rb +0 -25
  214. data/test/test-dollar-0.rb +0 -39
  215. data/test/test-edit.rb +0 -25
  216. data/test/test-emacs-basic.rb +0 -25
  217. data/test/test-enable.rb +0 -24
  218. data/test/test-finish.rb +0 -33
  219. data/test/test-frame.rb +0 -33
  220. data/test/test-help.rb +0 -54
  221. data/test/test-hist.rb +0 -65
  222. data/test/test-info-thread.rb +0 -31
  223. data/test/test-info-var.rb +0 -46
  224. data/test/test-info.rb +0 -25
  225. data/test/test-init.rb +0 -43
  226. data/test/test-jump.rb +0 -34
  227. data/test/test-list.rb +0 -24
  228. data/test/test-method.rb +0 -33
  229. data/test/test-next.rb +0 -24
  230. data/test/test-output.rb +0 -25
  231. data/test/test-quit.rb +0 -29
  232. data/test/test-raise.rb +0 -24
  233. data/test/test-remote.rb +0 -14
  234. data/test/test-save.rb +0 -30
  235. data/test/test-scope-var.rb +0 -24
  236. data/test/test-setshow.rb +0 -24
  237. data/test/test-source.rb +0 -24
  238. data/test/test-stepping.rb +0 -25
  239. data/test/test-trace.rb +0 -46
  240. data/test/thread1.rb +0 -25
  241. data/test/trunc-call.rb +0 -30
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ tmp
2
+ vendor/bundle
3
+
4
+ .rvmrc
5
+ .gdbinit
6
+ .gdb_history
7
+ .bundle
8
+
9
+ lib/ruby_debug.bundle
10
+ ext/ruby_debug/breakpoint.c
11
+ ext/ruby_debug/ruby_debug.c
12
+ ext/ruby_debug/ruby_debug.h
13
+
14
+ Gemfile.lock
data/.travis.yml CHANGED
@@ -1,4 +1,3 @@
1
- before_install: bundle init --gemspec=debugger.gemspec
2
1
  before_script: rake compile
3
2
  rvm:
4
3
  - 1.9.2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 1.3.0 - thanks to @astashov
2
+ * New and improved test suite
3
+ * Fix line tracing
4
+ * Fix source reloading
5
+ * Fix error message of jump command
6
+ * Fix trace and trace all commands
7
+ * Fix -d flag to irb command
8
+ * Fix method command being detected
9
+
1
10
  ## 1.2.4
2
11
  * Bump ruby_core_source dependency
3
12
 
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/README.md CHANGED
@@ -91,6 +91,7 @@ tutorial](http://bashdb.sourceforge.net/ruby-debug/rdebug-emacs.html)
91
91
  * No downloading ruby source during install - was behavior of old ruby_core_source dependency
92
92
  * Fix LocalJumpError caused by using proc in extconf.rb
93
93
  * Fix where command failing at top level
94
+ * A new and improved test suite
94
95
  * Passing tests are up on travis-ci
95
96
  * Minor
96
97
  * The gem name matches the module namespace, Debugger, and main required file, debugger.
@@ -126,6 +127,7 @@ Let's keep this working for the ruby community!
126
127
  ## Credits
127
128
 
128
129
  * Thanks to the original authors: Kent Sibilev and Mark Moseley
130
+ * Thanks to astashov for bringing in a new and improved test suite and various bug fixes.
129
131
  * Contributors: ericpromislow, jnimety, adammck, hipe, FooBarWidget
130
132
  * Fork started on awesome @relevance fridays!
131
133
 
data/Rakefile CHANGED
@@ -7,62 +7,10 @@ Rake::ExtensionTask.new('ruby_debug')
7
7
 
8
8
  SO_NAME = "ruby_debug.so"
9
9
 
10
- COMMON_FILES = FileList[
11
- 'AUTHORS',
12
- 'CHANGES',
13
- 'LICENSE',
14
- 'README',
15
- 'Rakefile',
16
- ]
17
-
18
- CLI_TEST_FILE_LIST = FileList['test/lib/commands/unit/*.rb',
19
- 'test/lib/commands/*_test.rb',
20
- 'test/lib/**/*_test.rb',
21
- 'test/test-remote.rb']
22
- # disabled until requires fixed and tests pass
23
- # 'test/test-*.rb']
24
- CLI_FILES = COMMON_FILES + FileList[
25
- "lib/**/*",
26
- 'ChangeLog',
27
- 'bin/*',
28
- 'doc/rdebug.1',
29
- 'test/**/data/*.cmd',
30
- 'test/**/data/*.right',
31
- 'test/**/*.rb',
32
- 'rdbg.rb',
33
- CLI_TEST_FILE_LIST
34
- ]
35
-
36
- BASE_TEST_FILE_LIST = %w(
37
- test/base/base.rb
38
- test/base/binding.rb
39
- test/base/catchpoint.rb)
40
- BASE_FILES = COMMON_FILES + FileList[
41
- 'ext/ruby_debug/breakpoint.c',
42
- 'ext/ruby_debug/extconf.rb',
43
- 'ext/ruby_debug/ruby_debug.c',
44
- 'ext/ruby_debug/ruby_debug.h',
45
- 'ext/win32/*',
46
- 'lib/**/*',
47
- BASE_TEST_FILE_LIST,
48
- ]
49
-
50
- desc "Test everything."
51
- task :test => :test_base do
10
+ desc "Run new MiniTest tests."
11
+ task :test do
52
12
  Rake::TestTask.new(:test) do |t|
53
- t.libs << './ext'
54
- t.libs << './lib'
55
- t.test_files = CLI_TEST_FILE_LIST
56
- t.verbose = true
57
- end
58
- end
59
-
60
- desc "Test ruby-debug-base."
61
- task :test_base => :lib do
62
- Rake::TestTask.new(:test_base) do |t|
63
- t.libs << './ext'
64
- t.libs << './lib'
65
- t.test_files = FileList[BASE_TEST_FILE_LIST]
13
+ t.test_files = FileList["test/*_test.rb"]
66
14
  t.verbose = true
67
15
  end
68
16
  end
data/debugger.gemspec CHANGED
@@ -24,4 +24,6 @@ handling, bindings for stack frames among other things.
24
24
  s.add_dependency "debugger-linecache", '~> 1.1.1'
25
25
  s.add_development_dependency 'rake', '~> 0.9.2.2'
26
26
  s.add_development_dependency 'rake-compiler', '~> 0.8.0'
27
+ s.add_development_dependency 'minitest', '~> 2.12.1'
28
+ s.add_development_dependency 'mocha', '~> 0.13.0'
27
29
  end
@@ -1,5 +1,5 @@
1
1
  module Debugger
2
2
  # TODO: remove version from C ext
3
3
  send :remove_const, :VERSION if const_defined? :VERSION
4
- VERSION = '1.2.4'
4
+ VERSION = '1.3.0'
5
5
  end
@@ -46,7 +46,7 @@ module Debugger
46
46
  end
47
47
 
48
48
  def at_tracing(file, line)
49
- @tracing_started = true if File.identical?(file, File.join(Debugger::INITIAL_DIR, Debugger::PROG_SCRIPT))
49
+ @tracing_started = File.identical?(file, Debugger::PROG_SCRIPT)
50
50
  handler.at_tracing(self, file, line) if @tracing_started
51
51
  end
52
52
 
@@ -91,6 +91,8 @@ module Debugger
91
91
  end
92
92
 
93
93
  def source_reload
94
+ Object.send(:remove_const, "SCRIPT_LINES__") if Object.const_defined?("SCRIPT_LINES__")
95
+ Object.const_set("SCRIPT_LINES__", {})
94
96
  LineCache::clear_file_cache
95
97
  end
96
98
 
@@ -72,7 +72,7 @@ module Debugger
72
72
  throw :IRB_EXIT, :cont if $rdebug_in_irb
73
73
  end
74
74
 
75
- add_debugging = @match.is_a?(Array) && '-d' == @match[1]
75
+ add_debugging = @match.is_a?(MatchData) && '-d' == @match[1]
76
76
  $rdebug_state = @state if add_debugging
77
77
  $rdebug_in_irb = true
78
78
  cont = IRB.start_session(get_binding)
@@ -23,7 +23,7 @@ module Debugger
23
23
  return
24
24
  end
25
25
  if !numeric?(@match[1])
26
- puts "Bad line number: " + @match[1]
26
+ errmsg "Bad line number: " + @match[1]
27
27
  return
28
28
  end
29
29
  line = @match[1].to_i
@@ -42,7 +42,7 @@ module Debugger
42
42
  # Implements the debugger 'method' command.
43
43
  class MethodCommand < Command
44
44
  def regexp
45
- /^\s*m(?:ethod)?\s+((iv)|(i(:?nstance\s+)?)\s+)?/
45
+ /^\s*m(?:ethod)?\s+((iv)|(i(:?nstance)?)\s+)?/
46
46
  end
47
47
 
48
48
  def execute
@@ -68,7 +68,7 @@ module Debugger
68
68
  i += 1
69
69
  end
70
70
  else
71
- s='No readline suport'
71
+ s='No readline support'
72
72
  end
73
73
  return s
74
74
  when /^debuggertesting$/
@@ -11,10 +11,10 @@ module Debugger
11
11
  if @match[1] =~ /on|off/
12
12
  onoff = 'on' == @match[1]
13
13
  if @match[2]
14
- Debugger.current_context.tracing = onoff
14
+ Debugger.tracing = onoff
15
15
  print "Tracing %s all threads.\n" % (onoff ? 'on' : 'off')
16
16
  else
17
- Debugger.tracing = onoff
17
+ Debugger.current_context.tracing = onoff
18
18
  print "Tracing %s on current thread.\n" % (onoff ? 'on' : 'off')
19
19
  end
20
20
  elsif @match[1] =~ /var(?:iable)?/
@@ -4,10 +4,10 @@ module Debugger
4
4
  ary.sort!
5
5
  for v in ary
6
6
  begin
7
- s = debug_eval(v, b).inspect
7
+ s = debug_eval(v.to_s, b).inspect
8
8
  rescue
9
9
  begin
10
- s = debug_eval(v, b).to_s
10
+ s = debug_eval(v.to_s, b).to_s
11
11
  rescue
12
12
  s = "*Error in evaluation*"
13
13
  end
@@ -78,7 +78,7 @@ module Debugger
78
78
 
79
79
  def help(cmd)
80
80
  %{
81
- v[ar] c[onst] <object>\t\tshow constants of object
81
+ v[ar] co[nst] <object>\t\tshow constants of object
82
82
  }
83
83
  end
84
84
  end
@@ -0,0 +1,365 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe "Breakpoints" do
4
+ include TestDsl
5
+
6
+ describe "setting breakpoint in the current file" do
7
+ before { enter 'break 10' }
8
+ subject { breakpoint }
9
+
10
+ def check_subject(field, value)
11
+ debug_file("breakpoint1") { subject.send(field).must_equal value }
12
+ end
13
+
14
+ it("must have correct pos") { check_subject(:pos, 10) }
15
+ it("must have correct source") { check_subject(:source, fullpath("breakpoint1")) }
16
+ it("must have correct expression") { check_subject(:expr, nil) }
17
+ it("must have correct hit count") { check_subject(:hit_count, 0) }
18
+ it("must have correct hit value") { check_subject(:hit_value, 0) }
19
+ it("must be enabled") { check_subject(:enabled?, true) }
20
+ it("must return right response") do
21
+ id = nil
22
+ debug_file('breakpoint1') { id = subject.id }
23
+ check_output_includes "Breakpoint #{id} file #{fullpath('breakpoint1')}, line 10"
24
+ end
25
+ end
26
+
27
+
28
+ describe "using shortcut for the command" do
29
+ before { enter 'b 10' }
30
+ it "must set a breakpoint" do
31
+ debug_file("breakpoint1") { Debugger.breakpoints.size.must_equal 1 }
32
+ end
33
+ end
34
+
35
+
36
+ describe "setting breakpoint to unexisted line" do
37
+ before { enter 'break 100' }
38
+
39
+ it "must not create a breakpoint" do
40
+ debug_file("breakpoint1") { Debugger.breakpoints.must_be_empty }
41
+ end
42
+
43
+ it "must show an error" do
44
+ debug_file("breakpoint1")
45
+ check_output_includes "There are only #{LineCache.size(fullpath('breakpoint1'))} lines in file \"breakpoint1.rb\".", interface.error_queue
46
+ end
47
+ end
48
+
49
+
50
+ describe "setting breakpoint to incorrect line" do
51
+ before { enter 'break 8' }
52
+
53
+ it "must not create a breakpoint" do
54
+ debug_file("breakpoint1") { Debugger.breakpoints.must_be_empty }
55
+ end
56
+
57
+ it "must show an error" do
58
+ debug_file("breakpoint1")
59
+ check_output_includes 'Line 8 is not a stopping point in file "breakpoint1.rb".', interface.error_queue
60
+ end
61
+ end
62
+
63
+
64
+ describe "stopping at breakpoint" do
65
+ it "must stop at the correct line" do
66
+ enter 'break 14', 'cont'
67
+ debug_file("breakpoint1") { state.line.must_equal 14 }
68
+ end
69
+
70
+ it "must stop at the correct file" do
71
+ enter 'break 14', 'cont'
72
+ debug_file("breakpoint1") { state.file.must_equal fullpath("breakpoint1") }
73
+ end
74
+
75
+ describe "show a message" do
76
+ temporary_change_hash_value(Debugger::Command.settings, :basename, false)
77
+
78
+ it "must show a message with full filename" do
79
+ enter 'break 14', 'cont'
80
+ debug_file("breakpoint1")
81
+ check_output_includes "Breakpoint 1 at #{fullpath('breakpoint1')}:14"
82
+ end
83
+
84
+ it "must show a message with basename" do
85
+ enter 'set basename', 'break 14', 'cont'
86
+ debug_file("breakpoint1")
87
+ check_output_includes "Breakpoint 1 at breakpoint1.rb:14"
88
+ end
89
+ end
90
+ end
91
+
92
+
93
+ describe "reloading source on change" do
94
+ temporary_change_hash_value(Debugger::Command.settings, :reload_source_on_change, false)
95
+
96
+ it "must not reload source if autoreload is not set" do
97
+ enter(
98
+ 'set noautoreload',
99
+ ->{change_line_in_file(fullpath('breakpoint1'), 14, ''); 'break 14'},
100
+ ->{change_line_in_file(fullpath('breakpoint1'), 14, 'c = a + b'); 'cont'}
101
+ )
102
+ debug_file "breakpoint1"
103
+ check_output_includes "Breakpoint 1 at #{fullpath('breakpoint1')}:14"
104
+ end
105
+
106
+ it "must reload source if autoreload is set" do
107
+ enter(
108
+ 'set autoreload',
109
+ ->{change_line_in_file(fullpath('breakpoint1'), 14, ''); 'break 14'},
110
+ # Setting second breakpoint just to reload the source code after rolling the file changes back
111
+ ->{change_line_in_file(fullpath('breakpoint1'), 14, 'c = a + b'); 'break 15'}, 'cont'
112
+ )
113
+ debug_file "breakpoint1"
114
+ check_output_includes "Line 14 is not a stopping point in file \"breakpoint1.rb\".", interface.error_queue
115
+ end
116
+ end
117
+
118
+
119
+ describe "set breakpoint in a file" do
120
+ describe "successfully" do
121
+ before do
122
+ enter "break #{fullpath('breakpoint2')}:3", 'cont'
123
+ end
124
+
125
+ it "must stop at the correct line" do
126
+ debug_file("breakpoint1") { state.line.must_equal 3 }
127
+ end
128
+
129
+ it "must stop at the correct file" do
130
+ debug_file("breakpoint1") { state.file.must_equal fullpath("breakpoint2") }
131
+ end
132
+ end
133
+
134
+ describe "when setting breakpoint to unexisted file" do
135
+ before do
136
+ enter "break asf:324"
137
+ debug_file("breakpoint1")
138
+ end
139
+ it "must show an error" do
140
+ check_output_includes "No source file named asf", interface.error_queue
141
+ end
142
+
143
+ it "must ask about setting breakpoint anyway" do
144
+ check_output_includes "Set breakpoint anyway? (y/n)", interface.confirm_queue
145
+ end
146
+ end
147
+ end
148
+
149
+
150
+ describe "set breakpoint to a method" do
151
+ describe "set breakpoint to an instance method" do
152
+ before do
153
+ enter 'break A#b', 'cont'
154
+ end
155
+
156
+ it "must stop at the correct line" do
157
+ debug_file("breakpoint1") { state.line.must_equal 5 }
158
+ end
159
+
160
+ it "must stop at the correct file" do
161
+ debug_file("breakpoint1") { state.file.must_equal fullpath("breakpoint1") }
162
+ end
163
+ end
164
+
165
+ describe "set breakpoint to a class method" do
166
+ before do
167
+ enter 'break A.a', 'cont'
168
+ end
169
+
170
+ it "must stop at the correct line" do
171
+ debug_file("breakpoint1") { state.line.must_equal 2 }
172
+ end
173
+
174
+ it "must stop at the correct file" do
175
+ debug_file("breakpoint1") { state.file.must_equal fullpath("breakpoint1") }
176
+ end
177
+ end
178
+
179
+ describe "set breakpoint to unexisted class" do
180
+ it "must show an error" do
181
+ enter "break B.a"
182
+ debug_file("breakpoint1")
183
+ check_output_includes "Unknown class B.", interface.error_queue
184
+ end
185
+ end
186
+ end
187
+
188
+
189
+ describe "set breakpoint to an invalid location" do
190
+ before { enter "break foo" }
191
+
192
+ it "must not create a breakpoint" do
193
+ debug_file("breakpoint1") { Debugger.breakpoints.must_be_empty }
194
+ end
195
+
196
+ it "must show an error" do
197
+ debug_file("breakpoint1")
198
+ check_output_includes 'Invalid breakpoint location: foo.', interface.error_queue
199
+ end
200
+ end
201
+
202
+
203
+ describe "disabling a breakpoint" do
204
+ describe "successfully" do
205
+ before { enter "break 14" }
206
+
207
+ describe "short syntax" do
208
+ before { enter ->{"disable #{breakpoint.id}"}, "break 15" }
209
+ it "must have a breakpoint with #enabled? returning false" do
210
+ debug_file("breakpoint1") { breakpoint.enabled?.must_equal false }
211
+ end
212
+
213
+ it "must not stop on the disabled breakpoint" do
214
+ enter "cont"
215
+ debug_file("breakpoint1") { state.line.must_equal 15 }
216
+ end
217
+ end
218
+
219
+ describe "full syntax" do
220
+ before { enter ->{"disable breakpoints #{breakpoint.id}"}, "break 15" }
221
+ it "must have a breakpoint with #enabled? returning false" do
222
+ debug_file("breakpoint1") { breakpoint.enabled?.must_equal false }
223
+ end
224
+ end
225
+ end
226
+
227
+ describe "errors" do
228
+ it "must show an error if syntax is incorrect" do
229
+ enter "disable"
230
+ debug_file("breakpoint1")
231
+ check_output_includes(
232
+ '"disable" must be followed "display", "breakpoints" or breakpoint numbers.',
233
+ interface.error_queue
234
+ )
235
+ end
236
+
237
+ it "must show an error if no breakpoints is set" do
238
+ enter "disable 1"
239
+ debug_file("breakpoint1")
240
+ check_output_includes 'No breakpoints have been set.', interface.error_queue
241
+ end
242
+
243
+ it "must show an error if not a number is provided as an argument to 'disable' command" do
244
+ enter "break 14", "disable foo"
245
+ debug_file("breakpoint1")
246
+ check_output_includes "Disable breakpoints argument 'foo' needs to be a number."
247
+ end
248
+ end
249
+ end
250
+
251
+
252
+ describe "enabling a breakpoint" do
253
+ describe "successfully" do
254
+ before { enter "break 14" }
255
+ describe "short syntax" do
256
+ before { enter ->{"enable #{breakpoint.id}"}, "break 15" }
257
+
258
+ it "must have a breakpoint with #enabled? returning true" do
259
+ debug_file("breakpoint1") { breakpoint.enabled?.must_equal true }
260
+ end
261
+
262
+ it "must stop on the enabled breakpoint" do
263
+ enter "cont"
264
+ debug_file("breakpoint1") { state.line.must_equal 14 }
265
+ end
266
+ end
267
+
268
+ describe "full syntax" do
269
+ before { enter ->{"enable breakpoints #{breakpoint.id}"}, "break 15" }
270
+
271
+ it "must have a breakpoint with #enabled? returning true" do
272
+ debug_file("breakpoint1") { breakpoint.enabled?.must_equal true }
273
+ end
274
+ end
275
+ end
276
+
277
+ describe "errors" do
278
+ it "must show an error if syntax is incorrect" do
279
+ enter "enable"
280
+ debug_file("breakpoint1")
281
+ check_output_includes(
282
+ '"enable" must be followed "display", "breakpoints" or breakpoint numbers.',
283
+ interface.error_queue
284
+ )
285
+ end
286
+ end
287
+ end
288
+
289
+
290
+ describe "deleting a breakpoint" do
291
+ before { enter "break 14", ->{"delete #{breakpoint.id}"}, "break 15" }
292
+
293
+ it "must have only one breakpoint" do
294
+ debug_file("breakpoint1") { Debugger.breakpoints.size.must_equal 1 }
295
+ end
296
+
297
+ it "must not stop on the disabled breakpoint" do
298
+ enter "cont"
299
+ debug_file("breakpoint1") { state.line.must_equal 15 }
300
+ end
301
+ end
302
+
303
+
304
+ describe "Conditional breakpoints" do
305
+ it "must stop if the condition is correct" do
306
+ enter "break 14 if b == 5", "break 15", "cont"
307
+ debug_file("breakpoint1") { state.line.must_equal 14 }
308
+ end
309
+
310
+ it "must skip if the condition is incorrect" do
311
+ enter "break 14 if b == 3", "break 15", "cont"
312
+ debug_file("breakpoint1") { state.line.must_equal 15 }
313
+ end
314
+
315
+ it "must show an error when conditional syntax is wrong" do
316
+ enter "break 14 ifa b == 3", "break 15", "cont"
317
+ debug_file("breakpoint1") { state.line.must_equal 15 }
318
+ check_output_includes "Expecting 'if' in breakpoint condition; got: ifa b == 3.", interface.error_queue
319
+ end
320
+
321
+ describe "enabling with wrong conditional syntax" do
322
+ before do
323
+ enter(
324
+ "break 14",
325
+ ->{"disable #{breakpoint.id}"},
326
+ ->{"cond #{breakpoint.id} b -=( 3"},
327
+ ->{"enable #{breakpoint.id}"}
328
+ )
329
+ end
330
+
331
+ it "must not enable a breakpoint" do
332
+ debug_file("breakpoint1") { breakpoint.enabled?.must_equal false }
333
+ end
334
+
335
+ it "must show an error" do
336
+ debug_file("breakpoint1")
337
+ check_output_includes(
338
+ 'Expression "b -=( 3" syntactically incorrect; breakpoint remains disabled.',
339
+ interface.error_queue
340
+ )
341
+ end
342
+ end
343
+
344
+ it "must show an error if no file or line is specified" do
345
+ enter "break ifa b == 3", "break 15", "cont"
346
+ debug_file("breakpoint1") { state.line.must_equal 15 }
347
+ check_output_includes "Invalid breakpoint location: ifa b == 3.", interface.error_queue
348
+ end
349
+
350
+ it "must show an error if expression syntax is invalid" do
351
+ enter "break if b -=) 3", "break 15", "cont"
352
+ debug_file("breakpoint1") { state.line.must_equal 15 }
353
+ check_output_includes 'Expression "b -=) 3" syntactically incorrect; breakpoint disabled.', interface.error_queue
354
+ end
355
+ end
356
+
357
+
358
+ describe "Post Mortem" do
359
+ it "must be able to set breakpoints in post-mortem mode" do
360
+ enter 'cont', 'break 12', 'cont'
361
+ debug_file("post_mortem") { state.line.must_equal 12 }
362
+ end
363
+ end
364
+
365
+ end