rtinspect 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/COPYING +340 -0
  2. data/LICENSE +53 -0
  3. data/README +331 -0
  4. data/TODO +36 -0
  5. data/lib/rtinspect.rb +950 -0
  6. data/test/test.rb +162 -0
  7. metadata +54 -0
data/test/test.rb ADDED
@@ -0,0 +1,162 @@
1
+ require 'timeout'
2
+ require 'expect'
3
+ require 'test/unit'
4
+
5
+ require 'rtinspect'
6
+
7
+ class TestRuntimeInspectionThread < Test::Unit::TestCase
8
+
9
+ class Tracker
10
+ def self.assert_equal( &block )
11
+ @@assert_equal = block
12
+ end
13
+
14
+ def initialize( &assert_block )
15
+ $expect_verbose = $DEBUG
16
+ @sock = TCPSocket.new( 'localhost', 56789 )
17
+ @cmd_count = 1
18
+ @block_count = 0
19
+ @at_prompt = false
20
+ end
21
+
22
+ def assert( cmd=nil, *expected )
23
+ unless @at_prompt
24
+ @@assert_equal.call( ["\n"+prompt], @sock.expect(prompt) )
25
+ end
26
+ return unless cmd
27
+
28
+ if cmd.kind_of? Array
29
+ cmds = cmd
30
+ else
31
+ cmds = [cmd]
32
+ end
33
+
34
+ out = ''
35
+ cmds.each do |cmd|
36
+ puts( cmd )
37
+ $stdout.puts "expect: #{prompt}" if $DEBUG
38
+ timeout( 5 ) do
39
+ out += @sock.expect( prompt ).first
40
+ end
41
+ out.sub!( /test:\d+:\d> $/, '' )
42
+ end
43
+
44
+ if @block_count > 0
45
+ puts( '' )
46
+ @block_count += 1
47
+ $stdout.puts "expect: #{prompt}" if $DEBUG
48
+ timeout( 5 ) do
49
+ out += @sock.expect( prompt ).first
50
+ end
51
+ out.sub!( /test:\d+:\d> $/, '' )
52
+ end
53
+
54
+ @at_prompt = true
55
+
56
+ out.chomp!
57
+ @@assert_equal.call( expected.join("\n") + "\n", out )
58
+ end
59
+
60
+ def puts( msg )
61
+ $stdout.puts( "<- #{msg}" ) if $DEBUG
62
+ @sock.puts( msg )
63
+ @cmd_count += 1
64
+ end
65
+
66
+ def use_blocks=( enabled )
67
+ if( !enabled and @block_count > 0 )
68
+ # turn it off
69
+ assert( "rti.state.block_count = 0\n\n", '0' )
70
+ @block_count = 0
71
+ elsif( enabled and @block_count < 1 )
72
+ # turn it on
73
+ puts( 'rti.state.block_count = 1' )
74
+ @block_count = 1
75
+ timeout( 5 ) do
76
+ @sock.expect( prompt ).first
77
+ end
78
+ @at_prompt = true
79
+ end
80
+ end
81
+
82
+ def close
83
+ @sock.close
84
+ end
85
+
86
+ private
87
+
88
+ def prompt
89
+ "test:#{'%03d'%@cmd_count}:#{@block_count}> "
90
+ end
91
+ end
92
+
93
+ def setup
94
+ Tracker.assert_equal do |a1, a2|
95
+ assert_equal( a1, a2 )
96
+ end
97
+ end
98
+
99
+ def test_prompt
100
+ threads = Thread.list.dup
101
+ r = RuntimeInspectionThread.new
102
+ assert_not_equal( threads, Thread.list )
103
+ t = Tracker.new
104
+ t.assert
105
+ r.kill
106
+ r.join
107
+ assert_raise( Errno::EPIPE ) do
108
+ t.puts( 'foo' )
109
+ end
110
+ t.close
111
+ assert_equal( threads, Thread.list )
112
+ end
113
+
114
+ def test_locals
115
+ r = RuntimeInspectionThread.new
116
+ t = Tracker.new
117
+
118
+ t.assert( 'rti.state.use_yaml = true', "=> --- true" )
119
+
120
+ t.assert( 'local_variables',
121
+ '=> --- ',
122
+ '- rti' )
123
+
124
+ r.kill
125
+ end
126
+
127
+ def test_list
128
+ r = RuntimeInspectionThread.new
129
+ t = Tracker.new
130
+
131
+ t.assert( 'rti.list',
132
+ '=> ["bp_add", "bp_continue", "bp_del", "bp_fin", "bp_list", ' +
133
+ '"bp_next", "bp_start", "bp_step", "bp_stop", "get_object", ' +
134
+ '"initialize", "list", "name2class", "start_world", "state", ' +
135
+ '"stop_world"]' )
136
+
137
+ r.kill
138
+ end
139
+
140
+ def test_lookup
141
+ r = RuntimeInspectionThread.new
142
+ t = Tracker.new
143
+
144
+ Struct.new( 'Foo', :one, :two, :three )
145
+ foo = Struct::Foo.new( 1, 2, 3 )
146
+
147
+ t.use_blocks = true
148
+ t.assert( [ "foo = rti.get_object 'Foo'",
149
+ "foo.one = 11",
150
+ "foo.two = 22",
151
+ "p foo" ],
152
+ '#<struct Struct::Foo one=11, two=22, three=3>',
153
+ '=> nil' )
154
+
155
+ assert_equal( 11, foo.one )
156
+ assert_equal( 22, foo.two )
157
+ assert_equal( 3, foo.three )
158
+
159
+ r.kill
160
+ end
161
+
162
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: rtinspect
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-01-01 00:00:00 -08:00
8
+ summary: A thread that will enable remote access capabilities in a running Ruby process for debugging and inspection.
9
+ require_paths:
10
+ - lib
11
+ email: bradrf@gigglewax.com
12
+ homepage: http://rtinspect.rubyforge.org/
13
+ rubyforge_project:
14
+ description: This is a class that will enable remote access capabilities in a running Ruby process, exposing the ability to enable breakpoints, walk code (e.g. step/next/continue), inspect variables, modify codepaths, and many other debugging actions.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Brad Robel-Forrest
31
+ files:
32
+ - lib/rtinspect.rb
33
+ - test/test.rb
34
+ - README
35
+ - LICENSE
36
+ - COPYING
37
+ - TODO
38
+ test_files:
39
+ - test/test.rb
40
+ rdoc_options: []
41
+
42
+ extra_rdoc_files:
43
+ - README
44
+ - LICENSE
45
+ - COPYING
46
+ - TODO
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ requirements: []
52
+
53
+ dependencies: []
54
+