rb8-trepanning 0.1.3-universal-ruby-1.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (274) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGES +34 -0
  3. data/ChangeLog +875 -0
  4. data/README.textile +59 -0
  5. data/Rakefile +215 -0
  6. data/app/.gitignore +1 -0
  7. data/app/cmd_parse.kpeg +241 -0
  8. data/app/cmd_parse.rb +212 -0
  9. data/app/cmd_parser.rb +1948 -0
  10. data/app/complete.rb +79 -0
  11. data/app/default.rb +90 -0
  12. data/app/display.rb +148 -0
  13. data/app/eventbuffer.rb +147 -0
  14. data/app/frame.rb +166 -0
  15. data/app/irb.rb +114 -0
  16. data/app/options.rb +200 -0
  17. data/app/run.rb +74 -0
  18. data/app/util.rb +65 -0
  19. data/bin/.gitignore +1 -0
  20. data/bin/trepan8 +115 -0
  21. data/data/.gitignore +1 -0
  22. data/data/irbrc +41 -0
  23. data/interface/.gitignore +1 -0
  24. data/interface/base_intf.rb +109 -0
  25. data/interface/client.rb +82 -0
  26. data/interface/comcodes.rb +20 -0
  27. data/interface/script.rb +110 -0
  28. data/interface/server.rb +147 -0
  29. data/interface/user.rb +165 -0
  30. data/io/base_io.rb +148 -0
  31. data/io/input.rb +158 -0
  32. data/io/null_output.rb +46 -0
  33. data/io/string_array.rb +156 -0
  34. data/io/tcpclient.rb +129 -0
  35. data/io/tcpfns.rb +33 -0
  36. data/io/tcpserver.rb +141 -0
  37. data/lib/debugger.rb +8 -0
  38. data/lib/trepanning.rb +283 -0
  39. data/processor/.gitignore +1 -0
  40. data/processor/command-ruby-debug/breakpoints.rb +155 -0
  41. data/processor/command-ruby-debug/catchpoint.rb +55 -0
  42. data/processor/command-ruby-debug/condition.rb +49 -0
  43. data/processor/command-ruby-debug/control.rb +31 -0
  44. data/processor/command-ruby-debug/display.rb +120 -0
  45. data/processor/command-ruby-debug/enable.rb +202 -0
  46. data/processor/command-ruby-debug/frame.rb +199 -0
  47. data/processor/command-ruby-debug/help.rb +63 -0
  48. data/processor/command-ruby-debug/info.rb +359 -0
  49. data/processor/command-ruby-debug/method.rb +84 -0
  50. data/processor/command-ruby-debug/reload.rb +40 -0
  51. data/processor/command-ruby-debug/save.rb +90 -0
  52. data/processor/command-ruby-debug/set.rb +237 -0
  53. data/processor/command-ruby-debug/show.rb +251 -0
  54. data/processor/command-ruby-debug/source.rb +36 -0
  55. data/processor/command-ruby-debug/threads.rb +189 -0
  56. data/processor/command-ruby-debug/trace.rb +57 -0
  57. data/processor/command-ruby-debug/variables.rb +199 -0
  58. data/processor/command.rb +270 -0
  59. data/processor/command/.gitignore +1 -0
  60. data/processor/command/alias.rb +54 -0
  61. data/processor/command/backtrace.rb +123 -0
  62. data/processor/command/base/cmd.rb +177 -0
  63. data/processor/command/base/subcmd.rb +230 -0
  64. data/processor/command/base/submgr.rb +188 -0
  65. data/processor/command/base/subsubcmd.rb +128 -0
  66. data/processor/command/base/subsubmgr.rb +199 -0
  67. data/processor/command/break.rb +114 -0
  68. data/processor/command/catch.rb +71 -0
  69. data/processor/command/complete.rb +39 -0
  70. data/processor/command/continue.rb +57 -0
  71. data/processor/command/directory.rb +50 -0
  72. data/processor/command/disable.rb +85 -0
  73. data/processor/command/display.rb +78 -0
  74. data/processor/command/down.rb +54 -0
  75. data/processor/command/edit.rb +79 -0
  76. data/processor/command/enable.rb +48 -0
  77. data/processor/command/eval.rb +90 -0
  78. data/processor/command/exit.rb +66 -0
  79. data/processor/command/finish.rb +59 -0
  80. data/processor/command/frame.rb +97 -0
  81. data/processor/command/help.rb +230 -0
  82. data/processor/command/help/.gitignore +1 -0
  83. data/processor/command/help/README +10 -0
  84. data/processor/command/help/command.txt +58 -0
  85. data/processor/command/help/examples.txt +16 -0
  86. data/processor/command/help/filename.txt +40 -0
  87. data/processor/command/help/location.txt +37 -0
  88. data/processor/command/help/suffixes.txt +17 -0
  89. data/processor/command/info.rb +28 -0
  90. data/processor/command/info_subcmd/.gitignore +1 -0
  91. data/processor/command/info_subcmd/args.rb +39 -0
  92. data/processor/command/info_subcmd/breakpoints.rb +80 -0
  93. data/processor/command/info_subcmd/catch.rb +36 -0
  94. data/processor/command/info_subcmd/files.rb +39 -0
  95. data/processor/command/info_subcmd/globals.rb +64 -0
  96. data/processor/command/info_subcmd/line.rb +30 -0
  97. data/processor/command/info_subcmd/locals.rb +69 -0
  98. data/processor/command/info_subcmd/macro.rb +62 -0
  99. data/processor/command/info_subcmd/program.rb +51 -0
  100. data/processor/command/info_subcmd/ruby.rb +57 -0
  101. data/processor/command/info_subcmd/source.rb +74 -0
  102. data/processor/command/info_subcmd/stack.rb +25 -0
  103. data/processor/command/info_subcmd/threads.rb +75 -0
  104. data/processor/command/kill.rb +78 -0
  105. data/processor/command/list.rb +117 -0
  106. data/processor/command/macro.rb +68 -0
  107. data/processor/command/next.rb +79 -0
  108. data/processor/command/parsetree.rb +56 -0
  109. data/processor/command/pp.rb +40 -0
  110. data/processor/command/pr.rb +37 -0
  111. data/processor/command/ps.rb +40 -0
  112. data/processor/command/restart.rb +86 -0
  113. data/processor/command/save.rb +58 -0
  114. data/processor/command/set.rb +47 -0
  115. data/processor/command/set_subcmd/.gitignore +1 -0
  116. data/processor/command/set_subcmd/abbrev.rb +25 -0
  117. data/processor/command/set_subcmd/auto.rb +27 -0
  118. data/processor/command/set_subcmd/auto_subcmd/.gitignore +1 -0
  119. data/processor/command/set_subcmd/auto_subcmd/eval.rb +53 -0
  120. data/processor/command/set_subcmd/auto_subcmd/irb.rb +33 -0
  121. data/processor/command/set_subcmd/auto_subcmd/list.rb +33 -0
  122. data/processor/command/set_subcmd/basename.rb +25 -0
  123. data/processor/command/set_subcmd/callstyle.rb +46 -0
  124. data/processor/command/set_subcmd/confirm.rb +24 -0
  125. data/processor/command/set_subcmd/debug.rb +47 -0
  126. data/processor/command/set_subcmd/different.rb +61 -0
  127. data/processor/command/set_subcmd/highlight.rb +43 -0
  128. data/processor/command/set_subcmd/max.rb +26 -0
  129. data/processor/command/set_subcmd/max_subcmd/list.rb +49 -0
  130. data/processor/command/set_subcmd/max_subcmd/stack.rb +50 -0
  131. data/processor/command/set_subcmd/max_subcmd/string.rb +76 -0
  132. data/processor/command/set_subcmd/max_subcmd/width.rb +49 -0
  133. data/processor/command/set_subcmd/reload.rb +42 -0
  134. data/processor/command/set_subcmd/timer.rb +58 -0
  135. data/processor/command/set_subcmd/trace.rb +37 -0
  136. data/processor/command/set_subcmd/trace_subcmd/buffer.rb +42 -0
  137. data/processor/command/set_subcmd/trace_subcmd/print.rb +41 -0
  138. data/processor/command/shell.rb +139 -0
  139. data/processor/command/show.rb +39 -0
  140. data/processor/command/show_subcmd/.gitignore +1 -0
  141. data/processor/command/show_subcmd/abbrev.rb +20 -0
  142. data/processor/command/show_subcmd/alias.rb +46 -0
  143. data/processor/command/show_subcmd/args.rb +34 -0
  144. data/processor/command/show_subcmd/auto.rb +28 -0
  145. data/processor/command/show_subcmd/auto_subcmd/eval.rb +27 -0
  146. data/processor/command/show_subcmd/auto_subcmd/irb.rb +23 -0
  147. data/processor/command/show_subcmd/auto_subcmd/list.rb +22 -0
  148. data/processor/command/show_subcmd/basename.rb +20 -0
  149. data/processor/command/show_subcmd/callstyle.rb +22 -0
  150. data/processor/command/show_subcmd/confirm.rb +18 -0
  151. data/processor/command/show_subcmd/debug.rb +26 -0
  152. data/processor/command/show_subcmd/debug_subcmd/dbgr.rb +21 -0
  153. data/processor/command/show_subcmd/debug_subcmd/skip.rb +22 -0
  154. data/processor/command/show_subcmd/debug_subcmd/step.rb +22 -0
  155. data/processor/command/show_subcmd/different.rb +26 -0
  156. data/processor/command/show_subcmd/directories.rb +22 -0
  157. data/processor/command/show_subcmd/highlight.rb +24 -0
  158. data/processor/command/show_subcmd/max.rb +27 -0
  159. data/processor/command/show_subcmd/max_subcmd/list.rb +38 -0
  160. data/processor/command/show_subcmd/max_subcmd/stack.rb +36 -0
  161. data/processor/command/show_subcmd/max_subcmd/string.rb +42 -0
  162. data/processor/command/show_subcmd/max_subcmd/width.rb +37 -0
  163. data/processor/command/show_subcmd/reload.rb +18 -0
  164. data/processor/command/show_subcmd/timer.rb +18 -0
  165. data/processor/command/show_subcmd/trace.rb +29 -0
  166. data/processor/command/show_subcmd/trace_subcmd/buffer.rb +65 -0
  167. data/processor/command/show_subcmd/trace_subcmd/print.rb +23 -0
  168. data/processor/command/show_subcmd/version.rb +23 -0
  169. data/processor/command/source.rb +134 -0
  170. data/processor/command/step.rb +81 -0
  171. data/processor/command/tbreak.rb +19 -0
  172. data/processor/command/unalias.rb +44 -0
  173. data/processor/command/undisplay.rb +59 -0
  174. data/processor/command/up.rb +72 -0
  175. data/processor/default.rb +56 -0
  176. data/processor/display.rb +17 -0
  177. data/processor/eval.rb +113 -0
  178. data/processor/eventbuf.rb +105 -0
  179. data/processor/frame.rb +172 -0
  180. data/processor/help.rb +92 -0
  181. data/processor/helper.rb +76 -0
  182. data/processor/hook.rb +134 -0
  183. data/processor/load_cmds.rb +258 -0
  184. data/processor/location.rb +174 -0
  185. data/processor/main.rb +455 -0
  186. data/processor/mock.rb +136 -0
  187. data/processor/msg.rb +61 -0
  188. data/processor/processor.rb +674 -0
  189. data/processor/running.rb +168 -0
  190. data/processor/stepping.rb +18 -0
  191. data/processor/subcmd.rb +161 -0
  192. data/processor/validate.rb +355 -0
  193. data/processor/virtual.rb +34 -0
  194. data/test/data/.gitignore +1 -0
  195. data/test/data/break_bad.cmd +19 -0
  196. data/test/data/break_bad.right +29 -0
  197. data/test/data/break_loop_bug.cmd +5 -0
  198. data/test/data/break_loop_bug.right +15 -0
  199. data/test/data/dollar-0.right +2 -0
  200. data/test/data/dollar-0a.right +2 -0
  201. data/test/data/dollar-0b.right +2 -0
  202. data/test/data/edit.cmd +14 -0
  203. data/test/data/edit.right +24 -0
  204. data/test/data/file-with-space.cmd +6 -0
  205. data/test/data/file-with-space.right +4 -0
  206. data/test/data/printvar.cmd +17 -0
  207. data/test/data/printvar.right +31 -0
  208. data/test/data/raise.cmd +11 -0
  209. data/test/data/raise.right +19 -0
  210. data/test/data/source.cmd +5 -0
  211. data/test/data/source.right +18 -0
  212. data/test/data/stepping-1.9.right +50 -0
  213. data/test/data/stepping.cmd +21 -0
  214. data/test/data/stepping.right +48 -0
  215. data/test/data/trepan8-save.1 +6 -0
  216. data/test/example/bp_loop_issue.rb +3 -0
  217. data/test/example/break-bug.rb +7 -0
  218. data/test/example/brkpt-class-bug.rb +8 -0
  219. data/test/example/classes.rb +11 -0
  220. data/test/example/dollar-0.rb +5 -0
  221. data/test/example/except-bug1.rb +4 -0
  222. data/test/example/except-bug2.rb +7 -0
  223. data/test/example/file with space.rb +1 -0
  224. data/test/example/gcd.rb +18 -0
  225. data/test/example/info-var-bug.rb +47 -0
  226. data/test/example/info-var-bug2.rb +2 -0
  227. data/test/example/null.rb +1 -0
  228. data/test/example/pm-bug.rb +3 -0
  229. data/test/example/pm.rb +11 -0
  230. data/test/example/raise.rb +3 -0
  231. data/test/integration/.gitignore +4 -0
  232. data/test/integration/config.yaml +8 -0
  233. data/test/integration/helper.rb +154 -0
  234. data/test/integration/test-break_bad.rb +26 -0
  235. data/test/integration/test-dollar-0.rb +31 -0
  236. data/test/integration/test-edit.rb +17 -0
  237. data/test/integration/test-file-with-space.rb +26 -0
  238. data/test/integration/test-printvar.rb +17 -0
  239. data/test/integration/test-raise.rb +21 -0
  240. data/test/integration/test-source.rb +16 -0
  241. data/test/integration/test-stepping.rb +24 -0
  242. data/test/unit/.gitignore +1 -0
  243. data/test/unit/cmd-helper.rb +52 -0
  244. data/test/unit/mock-helper.rb +12 -0
  245. data/test/unit/test-app-cmd_parse.rb +97 -0
  246. data/test/unit/test-app-cmd_parser.rb +23 -0
  247. data/test/unit/test-app-complete.rb +39 -0
  248. data/test/unit/test-app-frame.rb +32 -0
  249. data/test/unit/test-app-options.rb +92 -0
  250. data/test/unit/test-app-run.rb +14 -0
  251. data/test/unit/test-app-util.rb +44 -0
  252. data/test/unit/test-base-cmd.rb +45 -0
  253. data/test/unit/test-base-subcmd.rb +57 -0
  254. data/test/unit/test-base-submgr.rb +23 -0
  255. data/test/unit/test-base-subsubcmd.rb +17 -0
  256. data/test/unit/test-cmd-alias.rb +48 -0
  257. data/test/unit/test-cmd-exit.rb +27 -0
  258. data/test/unit/test-cmd-help.rb +104 -0
  259. data/test/unit/test-cmd-kill.rb +46 -0
  260. data/test/unit/test-cmd-source.rb +34 -0
  261. data/test/unit/test-completion.rb +42 -0
  262. data/test/unit/test-intf-user.rb +46 -0
  263. data/test/unit/test-io-input.rb +27 -0
  264. data/test/unit/test-io-tcp.rb +33 -0
  265. data/test/unit/test-io-tcpclient.rb +54 -0
  266. data/test/unit/test-io-tcpfns.rb +17 -0
  267. data/test/unit/test-io-tcpserver.rb +50 -0
  268. data/test/unit/test-proc-eval.rb +36 -0
  269. data/test/unit/test-proc-hook.rb +30 -0
  270. data/test/unit/test-proc-load_cmds.rb +50 -0
  271. data/test/unit/test-proc-location.rb +79 -0
  272. data/test/unit/test-subcmd-help.rb +44 -0
  273. data/trepan8.gemspec +58 -0
  274. metadata +388 -0
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'; require 'require_relative'
3
+ # require_relative '../../lib/trepanning'
4
+ require_relative 'helper'
5
+
6
+ # Test 'source' command handling.
7
+ class TestSource < Test::Unit::TestCase
8
+ include TestHelper
9
+ def test_basic
10
+ common_setup(__FILE__)
11
+ Dir.chdir(@srcdir) do
12
+ assert_equal(true,
13
+ run_debugger(@testname, @prefix + '../example/gcd.rb 3 5'))
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'; require 'require_relative'
3
+ # require_relative '../../lib/trepanning'
4
+ require_relative 'helper'
5
+
6
+ # Test that step commands
7
+ class TestStepping < Test::Unit::TestCase
8
+ include TestHelper
9
+ def test_basic
10
+ common_setup(__FILE__)
11
+ Dir.chdir(@srcdir) do
12
+ if RUBY_VERSION =~ /1.9/
13
+ else
14
+ rightfile = File.join(%W(.. data #{@testname}-1.9.right))
15
+ assert_equal(true,
16
+ run_debugger(@testname,
17
+ @prefix + '../example/gcd.rb 3 5',
18
+ nil, false, 'tdebug.rb', rightfile))
19
+ assert_equal(true,
20
+ run_debugger(@testname, @prefix + '../example/gcd.rb 3 5'))
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1 @@
1
+ /*~
@@ -0,0 +1,52 @@
1
+ require 'test/unit'
2
+ require 'rubygems'; require 'require_relative'
3
+ # require_relative '../../app/core'
4
+ require_relative '../../processor/mock'
5
+ require_relative '../../processor/frame'
6
+
7
+
8
+ module UnitHelper
9
+
10
+ module_function
11
+ def common_setup
12
+ @dbg ||= MockDebugger::MockDebugger.new(:nx => true)
13
+ @cmdproc = Trepan::CmdProcessor.new(@dbg.intf)
14
+ @cmdproc.frame_initialize
15
+ @cmdproc.dbgr = @dbg
16
+ @cmds = @cmdproc.commands
17
+
18
+ def @cmdproc.errmsg(message, opts={})
19
+ @errmsgs << message
20
+ end
21
+ def @cmdproc.errmsgs
22
+ @errmsgs
23
+ end
24
+ def @cmdproc.msg(message, opts={})
25
+ @msgs << message
26
+ end
27
+ def @cmdproc.msgs
28
+ @msgs
29
+ end
30
+ def @cmdproc.section(message, opts={})
31
+ @msgs << message
32
+ end
33
+ reset_cmdproc_vars
34
+ end
35
+
36
+ def common_teardown
37
+ @cmdproc.finalize
38
+ end
39
+
40
+ def reset_cmdproc_vars
41
+ @cmdproc.instance_variable_set('@msgs', [])
42
+ @cmdproc.instance_variable_set('@errmsgs', [])
43
+ end
44
+
45
+ end
46
+
47
+ if __FILE__ == $0
48
+ include UnitHelper
49
+ common_setup
50
+ p @cmdproc.msgs
51
+ p @dbg
52
+ end
@@ -0,0 +1,12 @@
1
+ require 'test/unit'
2
+ require 'rubygems'; require 'require_relative'
3
+ require 'ruby-debug-base'
4
+ require_relative '../../processor/mock'
5
+
6
+ module MockUnitHelper
7
+ def common_setup(name)
8
+ Debugger.start unless Debugger.started?
9
+ @dbg, @cmd = MockDebugger::setup(name, false)
10
+ end
11
+ end
12
+
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative '../../app/cmd_parse'
5
+
6
+ class TestCmdParse < Test::Unit::TestCase
7
+
8
+ # require_relative '../../lib/trepanning'
9
+ def test_parse_location
10
+ [['fn', [:fn, nil, nil]],
11
+ ['fn 2', [:fn, :line, 2]],
12
+ ['fn @5', [:fn, :offset, 5]],
13
+ ['@3', [nil, :offset, 3]],
14
+ ['fn:6', [:fn, :line, 6]],
15
+ ["#{__FILE__}:5", [:file, :line, 5]],
16
+ ['fn:@15', [:fn, :offset, 15]],
17
+ ].each do |location, expect|
18
+ cp = parse_location(location)
19
+ assert cp, "should be able to parse #{location} as a location"
20
+ assert_equal(expect[0], cp.container_type,
21
+ "mismatch container_type on #{location}")
22
+ assert_equal(expect[1], cp.position_type,
23
+ "mismatch position_type on #{location}")
24
+ assert_equal(expect[2], cp.position,
25
+ "mismatch position on #{location}")
26
+ end
27
+
28
+ # %w(0 1e10 a.b).each do |location|
29
+ # begin
30
+ # cp = CmdParse.new(name)
31
+ # assert_equal nil cp._location,
32
+ # "should be able to parse #{name} as a location"
33
+ # end
34
+ # end
35
+ end
36
+
37
+ module Testing
38
+ def testing; 5 end
39
+ module_function :testing
40
+ end
41
+
42
+ def test_parse_identifier
43
+ %w(a a1 $global __FILE__ Constant).each do |name|
44
+ cp = CmdParse.new(name)
45
+ assert cp._identifier, "should be able to parse #{name} as an identifier"
46
+ end
47
+ %w(0 1e10 @10).each do |name|
48
+ cp = CmdParse.new(name)
49
+ assert_equal(true, !cp._identifier,
50
+ "should not have been able to parse of #{name}")
51
+ end
52
+ end
53
+
54
+ def test_parse_method
55
+ [['Object', 0], ['A::B', 1], ['A::B::C', 2],
56
+ ['A::B::C::D', 3], ['A::B.c', 2], ['A.b.c.d', 3]].each do |name, count|
57
+ cp = CmdParse.new(name)
58
+ assert cp._class_module_chain, "should be able to parse of #{name}"
59
+ m = cp.result
60
+ count.times do |i|
61
+ assert m, "Chain item #{i} of #{name} should not be nil"
62
+ m = m.chain[1]
63
+ end
64
+ assert_nil m.chain, "#{count} chain item in #{cp.result} should be nil"
65
+ end
66
+ ['A(5)'].each do |name|
67
+ cp = CmdParse.new(name)
68
+ cp._class_module_chain
69
+ assert_not_equal(name, cp.result.name,
70
+ "should not have been able to parse of #{name}")
71
+ end
72
+ end
73
+
74
+ include Trepan::CmdParser
75
+ def test_method_name
76
+ def five; 5 end
77
+ %w(five Kernel.eval
78
+ Testing.testing Kernel::eval File.basename).each do |str|
79
+ meth = meth_for_string(str, binding)
80
+ assert meth.kind_of?(Method), "#{str} method's class should be Method, not #{meth.class}"
81
+ end
82
+ x = File
83
+ def x.five; 5; end
84
+ %w(x.basename x.five).each do |str|
85
+ meth = meth_for_string(str, binding)
86
+ assert meth.kind_of?(Method), "#{str} method's class should be Method, not #{meth.class}"
87
+ end
88
+ %w(Array.collect).each do |str|
89
+ meth = meth_for_string(str, binding)
90
+ assert meth.kind_of?(UnboundMethod), "#{meth.class}"
91
+ end
92
+ %w(O5).each do |str|
93
+ meth = meth_for_string(str, binding)
94
+ assert_equal nil, meth, "should not have found a method for #{str}"
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative '../../app/cmd_parser'
5
+
6
+ class TestAppCmdParser < Test::Unit::TestCase
7
+ def setup
8
+ @cp = CmdParse.new('', :debug=>true)
9
+ end
10
+
11
+ def test_parse_filename
12
+ [
13
+ ['filename', 'filename'],
14
+ ['"this is a filename"', 'this is a filename'],
15
+ ['this\ is\ another\ filename', 'this is another filename'],
16
+ ['C\:filename', 'C:filename']
17
+ ].each do |name, expect|
18
+ @cp.setup_parser(name, :debug => true)
19
+ res = @cp._filename
20
+ assert_equal(expect, @cp.result)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative '../../app/complete'
5
+
6
+ class TestAppUtil < Test::Unit::TestCase
7
+ include Trepan::Complete
8
+ def test_complete
9
+ hash = {'ab' => 1, 'aac' => 2, 'aa' => 3, 'a' => 4}
10
+ ary = hash.keys.sort
11
+ [[[], 'b'], [ary, 'a'], [%w(aa aac), 'aa'],
12
+ [ary, ''], [['ab'], 'ab'], [[], 'abc']].each do |result, prefix|
13
+ assert_equal(result, complete_token(ary, prefix),
14
+ "Trouble matching #{ary}.inspect on #{prefix.inspect}")
15
+ end
16
+ [[ary, 'a'], [%w(aa aac), 'aa'],
17
+ [['ab'], 'ab'], [[], 'abc']].each do |result_keys, prefix|
18
+ result = result_keys.map {|key| [key, hash[key]]}
19
+ assert_equal(result, complete_token_with_next(hash, prefix),
20
+ "Trouble matching #{hash}.inspect on #{prefix.inspect}")
21
+ end
22
+
23
+ end
24
+
25
+ def test_next_token
26
+ x = ' now is the time'
27
+ [[0, [ 5, 'now']],
28
+ [2, [ 5, 'now']],
29
+ [5, [ 8, 'is']],
30
+ [8, [13, 'the']],
31
+ [9, [13, 'the']],
32
+ [13, [19, 'time']],
33
+ [19, [19, '']],
34
+ ].each do |pos, expect|
35
+ assert_equal expect, next_token(x, pos)
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative '../../app/frame'
5
+
6
+ class TestAppFrame < Test::Unit::TestCase
7
+ def test_basic
8
+ require 'rubygems'
9
+ require 'ruby-debug-base'; Debugger.start
10
+ skip "Things are different on an unpatched 1.9.2" if
11
+ RUBY_VERSION =~ /1.9.2/
12
+ x = 1
13
+ Debugger.skip do
14
+ frame = Trepan::Frame.new(Debugger.current_context)
15
+ assert_equal __LINE__-2, frame.line
16
+ assert frame.stack_size >= 2, "Frame size should be >= 2, is #{frame.stack_size}"
17
+ assert_equal 'skip', frame.method_name
18
+ assert_equal __FILE__, frame.file
19
+ assert_equal 0, frame.index
20
+ assert_equal Debugger, frame.klass
21
+ assert_equal 1, eval('x', frame.binding)
22
+ frame.index = 1
23
+ assert_equal 'test_basic', frame.method_name
24
+ assert_equal __FILE__, frame.file
25
+ assert_equal Thread.current, frame.thread
26
+ assert_equal self.class, frame.klass
27
+ assert_equal 1, eval('x', frame.binding)
28
+ end
29
+ Debugger.stop
30
+ end
31
+
32
+ end
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'stringio'
4
+ require 'tempfile'
5
+ require 'rubygems'; require 'require_relative'
6
+ require_relative '../../app/options'
7
+
8
+ # To have something to work with.
9
+ load 'tmpdir.rb'
10
+
11
+ class TestAppOptions < Test::Unit::TestCase
12
+
13
+ def setup
14
+ @options = Trepan::DEFAULT_CMDLINE_SETTINGS.clone
15
+ @stderr = StringIO.new
16
+ @stdout = StringIO.new
17
+ @options = Trepan::copy_default_options
18
+ @opts = Trepan::setup_options(@options, @stdout, @stderr)
19
+ end
20
+
21
+ def test_cd
22
+ rest = @opts.parse(['--cd', Dir.tmpdir])
23
+ assert_equal(Dir.tmpdir, @options[:chdir])
24
+ assert_equal('', @stderr.string)
25
+ assert_equal('', @stdout.string)
26
+
27
+ setup
28
+ tf = Tempfile.new("delete-me")
29
+ orig_cd = @options[:chdir]
30
+ rest = @opts.parse(['--cd', tf.path])
31
+ assert_equal(orig_cd, @options[:chdir])
32
+ assert_not_equal('', @stderr.string)
33
+ assert_equal('', @stdout.string)
34
+ File.unlink tf.path
35
+ # FIXME: add test where directory isn't executable.
36
+ end
37
+
38
+ def test_binary_opts
39
+ %w(nx readline).each do |name|
40
+ setup
41
+ o = ["--#{name}"]
42
+ rest = @opts.parse o
43
+ assert_equal('', @stderr.string)
44
+ assert_equal(true, @options[name.to_sym])
45
+ end
46
+ # --no- options
47
+ %w(readline).each do |name|
48
+ o = ["--no-#{name}"]
49
+ rest = @opts.parse o
50
+ assert_equal('', @stderr.string)
51
+ assert_equal(false, @options[name.to_sym])
52
+ end
53
+ end
54
+
55
+ # FIXME: have to work around the fact that exit is called by help.
56
+ def no_test_help_and_version_opts
57
+ %w(help version).each do |name|
58
+ setup
59
+ o = ["--#{name}"]
60
+ rest = @opts.parse o
61
+ assert_not_equal('', @stdout.string)
62
+ assert_equal('', @stderr.string)
63
+ assert_equal(true, @options[name.to_sym])
64
+ other_sym = 'help' == name ? :version : :help
65
+ assert_equal(false, @options.member?(other_sym))
66
+ end
67
+ end
68
+
69
+ def test_both_client_server_opts
70
+ # Try each of --client and --server options separately
71
+ %w(client server).each do |name|
72
+ setup
73
+ o = ["--#{name}"]
74
+ rest = @opts.parse o
75
+ assert_equal('', @stdout.string)
76
+ assert_equal('', @stderr.string)
77
+ assert_equal(true, @options[name.to_sym])
78
+ end
79
+
80
+ # Try both --client and --server together. Should give a warning
81
+ setup
82
+ o = %w(--client --server)
83
+ rest = @opts.parse o
84
+ assert_not_equal('', @stderr.string)
85
+ assert_equal('', @stdout.string)
86
+ assert_equal(true, @options[:client])
87
+ ## FIXME - reinstate
88
+ ## assert_equal(false, @options[:server])
89
+
90
+ end
91
+
92
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative '../../app/run'
5
+
6
+ class TestAppRun < Test::Unit::TestCase
7
+ include Trepan
8
+ def test_basic
9
+ assert_equal(true, File.executable?(whence_file('irb')))
10
+ ng = whence_file('probably-does-not-exist')
11
+ assert_equal(true, File.executable?(ng) || ng == 'probably-does-not-exist')
12
+ end
13
+
14
+ end
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative '../../app/util'
5
+
6
+ class TestAppUtil < Test::Unit::TestCase
7
+ include Trepan::Util
8
+ def test_safe_repr
9
+ string = 'The time has come to talk of many things.'
10
+ assert_equal(string, safe_repr(string, 50))
11
+ assert_equal('The time... things.', safe_repr(string, 17))
12
+ assert_equal('"The tim... things."', safe_repr(string.inspect, 17))
13
+ string = "'The time has come to talk of many things.'"
14
+ assert_equal("'The tim... things.'", safe_repr(string, 17))
15
+ end
16
+
17
+ # def test_find_main_script
18
+ # locs = Rubinius::VM.backtrace(0, true)
19
+ # i = find_main_script(locs)
20
+ # assert_equal(true, !!i)
21
+ # assert_equal(false, !!find_main_script(locs[0..i]))
22
+ # end
23
+
24
+ def test_abbrev
25
+ list = %w(disassemble disable distance up)
26
+ [['dis', 'dis'],
27
+ ['disas', 'disassemble'],
28
+ ['u', 'up'],
29
+ ['upper', 'upper'],
30
+ ['foo', 'foo']].each do |name, expect|
31
+ assert_equal expect, uniq_abbrev(list, name)
32
+ end
33
+ end
34
+
35
+ def test_extract_expression
36
+ [['if condition("if")', 'condition("if")'],
37
+ ['until until_termination', 'until_termination'],
38
+ ['return return_value', 'return_value'],
39
+ ['nothing_to_be.done', 'nothing_to_be.done'],
40
+ ].each do |stmt, expect|
41
+ assert_equal expect, extract_expression(stmt)
42
+ end
43
+ end
44
+ end