rbx-linecache 0.44-universal-rubinius

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/data/if4.rb ADDED
@@ -0,0 +1,14 @@
1
+ # [ 6, 6, 7, 8, 10]
2
+
3
+ # Running through Tracer will not give the line numbers in the same
4
+ # order. Also note 9 before 7. This is because in the parse tree
5
+ # != has been turned into == with the branches switched.
6
+ [true, false].each do |t|
7
+ if t != true
8
+ 8
9
+ else
10
+ 10
11
+ end
12
+ end
13
+
14
+
data/test/data/if5.rb ADDED
@@ -0,0 +1,7 @@
1
+ # [2, 3, 3, 4, 4]
2
+ x=2
3
+ x=3 if x='a' or
4
+ false
5
+ # What's weird here is we get two stops on line 4 and both times x is
6
+ # 4. In Ruby 1.9 we don't get *any* line traces.
7
+
data/test/data/if6.rb ADDED
@@ -0,0 +1,4 @@
1
+ # [ 2 ]
2
+ x = 2 if x=3
3
+
4
+
data/test/data/if7.rb ADDED
@@ -0,0 +1,8 @@
1
+ # [ 2, 2, 3, 4, 6 ]
2
+ def f()
3
+ y=1
4
+ true
5
+ end
6
+ x = 2 if f()
7
+
8
+
@@ -0,0 +1,3 @@
1
+ # [ 3 ]
2
+ # MATCH -- FIXME we are not getting a match token.
3
+ /.*/
@@ -0,0 +1,5 @@
1
+ # [ 3 ]
2
+ # MATCH3
3
+ 3 =~ /
4
+ x*
5
+ /
@@ -0,0 +1,6 @@
1
+ # [ 3, 4, 5 ]
2
+ # MATCH3
3
+ y = 3
4
+ 4 =~ /
5
+ #{y}*
6
+ /
@@ -0,0 +1,6 @@
1
+ # [ 3, 4, 6 ]
2
+ # not and lit
3
+ 3
4
+ not 4
5
+ not
6
+ 6
data/test/lnum-diag.rb ADDED
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # begin require 'rubygems' rescue LoadError end
4
+ # require 'ruby-debug' ; Debugger.start
5
+
6
+ TEST_DIR = File.expand_path(File.dirname(__FILE__))
7
+ TOP_SRC_DIR = File.join(TEST_DIR, '..')
8
+ require File.join(TOP_SRC_DIR, 'lib', 'tracelines.rb')
9
+
10
+ def dump_file(file, opts)
11
+ puts file
12
+ begin
13
+ fp = File.open(file, 'r')
14
+ rescue Errno::ENOENT
15
+ puts "File #{file} is not readable."
16
+ return
17
+ end
18
+ lines = fp.read
19
+ if opts[:print_source]
20
+ puts '=' * 80
21
+ puts lines
22
+ end
23
+ if opts[:print_parse]
24
+ puts '=' * 80
25
+ cmd = "#{File.join(TEST_DIR, 'parse-show.rb')} #{file}"
26
+ system(cmd)
27
+ end
28
+ if opts[:print_trace]
29
+ require 'tracer'
30
+ puts '=' * 80
31
+ tracer = Tracer.new
32
+ tracer.add_filter lambda {|event, f, line, id, binding, klass|
33
+ __FILE__ != f && event == 'line'
34
+ }
35
+ tracer.on{load(file)}
36
+ end
37
+ expected_lnums = nil
38
+ if opts[:expect_line]
39
+ fp.rewind
40
+ first_line = fp.readline.chomp
41
+ expected_str = first_line[1..-1]
42
+ begin
43
+ expected_lnums = eval(expected_str, binding, __FILE__, __LINE__)
44
+ rescue SyntaxError
45
+ puts '=' * 80
46
+ puts "Failed reading expected values from #{file}"
47
+ end
48
+ end
49
+ fp.close()
50
+ got_lnums = TraceLineNumbers.lnums_for_str(lines)
51
+ if expected_lnums
52
+ puts "expecting: #{expected_lnums.inspect}"
53
+ puts '-' * 80
54
+ if expected_lnums
55
+ if got_lnums != expected_lnums
56
+ puts "mismatch: #{got_lnums.inspect}"
57
+ else
58
+ puts 'Got what was expected.'
59
+ end
60
+ else
61
+ puts got_lnums.inspect
62
+ end
63
+ else
64
+ puts got_lnums.inspect
65
+ end
66
+ end
67
+
68
+ require 'getoptlong'
69
+ program = File.basename($0)
70
+ opts = {
71
+ :print_source => true, # Print source file?
72
+ :print_trace => true, # Run Tracer over file?
73
+ :expect_line => true, # Source file has expected (correct) list of lines?
74
+ :print_parse => true, # Show ParseTree output?
75
+ }
76
+
77
+ getopts = GetoptLong.new(
78
+ [ '--expect', '-e', GetoptLong::NO_ARGUMENT ],
79
+ [ '--no-expect', '-E', GetoptLong::NO_ARGUMENT ],
80
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
81
+ [ '--parse', '-p', GetoptLong::NO_ARGUMENT ],
82
+ [ '--no-parse', '-P', GetoptLong::NO_ARGUMENT ],
83
+ [ '--source', '-s', GetoptLong::NO_ARGUMENT ],
84
+ [ '--no-source', '-S', GetoptLong::NO_ARGUMENT ],
85
+ [ '--trace', '-t', GetoptLong::NO_ARGUMENT ],
86
+ [ '--no-trace', '-T', GetoptLong::NO_ARGUMENT ])
87
+
88
+ getopts.each do |opt, arg|
89
+ case opt
90
+ when '--help'
91
+ puts "usage
92
+ Usage: #{$program} [options] file1 file2 ...
93
+
94
+ Diagnostic program to make see what TraceLineNumbers does and compare
95
+ against other output.
96
+
97
+ options:
98
+ -e --expect Read source file expected comment (default)
99
+ -E --no-expect Don't look for source file expected comment
100
+ -p --parse Show ParseTree Output (default)
101
+ -P --no-parse Don't show ParseTree output
102
+ -s --source Show source file (default)
103
+ -S --no-source Don't print source
104
+ -t --trace Show Tracer output (default)
105
+ -T --no-trace Don't show Tracer output
106
+ "
107
+ when '--expect'
108
+ opts[:expect_line] = true
109
+ when '--no-expect'
110
+ opts[:expect_line] = false
111
+ when '--parse'
112
+ opts[:print_parse] = true
113
+ when '--no-parse'
114
+ opts[:print_parse] = false
115
+ when '--source'
116
+ opts[:print_source] = true
117
+ when '--no-source'
118
+ opts[:print_source] = false
119
+ when '--trace'
120
+ opts[:print_trace] = true
121
+ when '--no-trace'
122
+ opts[:print_trace] = false
123
+ else
124
+ puts "Unknown and ignored option #{opt}"
125
+ end
126
+ end
127
+
128
+ ARGV.each do |file|
129
+ dump_file(file, opts)
130
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pp'
4
+ begin require 'rubygems' rescue LoadError end
5
+ require 'parse_tree'
6
+
7
+ ARGV.push "-" if ARGV.empty?
8
+
9
+ parse_tree = ParseTree.new(true)
10
+
11
+ ARGV.each do |file|
12
+ ruby = file == "-" ? $stdin.read : File.read(file)
13
+ pp parse_tree.parse_tree_for_string(ruby, file).first
14
+ end
data/test/rcov-bug.rb ADDED
@@ -0,0 +1,10 @@
1
+ # [3, 10]
2
+ # Some rcov bugs.
3
+ z = "
4
+ Now is the time
5
+ "
6
+
7
+ z =~
8
+ /
9
+ 5
10
+ /ix
data/test/short-file ADDED
@@ -0,0 +1,2 @@
1
+ # This is a small test file.
2
+
data/test/short-file2 ADDED
File without changes
@@ -0,0 +1,167 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'fileutils'
4
+ require 'tempfile'
5
+ require 'set'
6
+
7
+ # Test LineCache module
8
+ class TestLineCache < Test::Unit::TestCase
9
+ @@TEST_DIR = File.expand_path(File.dirname(__FILE__))
10
+ @@TOP_SRC_DIR = File.join(@@TEST_DIR, '..', 'lib')
11
+ require File.join(@@TOP_SRC_DIR, 'linecache.rb')
12
+
13
+ def setup
14
+ LineCache::clear_file_cache
15
+ end
16
+
17
+ def test_basic
18
+ fp = File.open(__FILE__, 'r')
19
+ compare_lines = fp.readlines()
20
+ fp.close
21
+
22
+ # Test getlines to read this file.
23
+ lines = LineCache::getlines(__FILE__)
24
+ assert_equal(compare_lines, lines,
25
+ 'We should get exactly the same lines as reading this file.')
26
+
27
+ # Test getline to read this file. The file should now be cached,
28
+ # so internally a different set of routines are used.
29
+ test_line = 1
30
+ line = LineCache::getline(__FILE__, test_line)
31
+ assert_equal(compare_lines[test_line-1], line,
32
+ 'We should get exactly the same line as reading this file.')
33
+
34
+ # Test getting the line via a relative file name
35
+ Dir.chdir(File.dirname(__FILE__)) do
36
+ short_file = File.basename(__FILE__)
37
+ test_line = 10
38
+ line = LineCache::getline(short_file, test_line)
39
+ assert_equal(compare_lines[test_line-1], line,
40
+ 'Short filename lookup should work')
41
+ end
42
+
43
+ # Write a temporary file; read contents, rewrite it and check that
44
+ # we get a change when calling getline.
45
+ tf = Tempfile.new("testing")
46
+ test_string = "Now is the time.\n"
47
+ tf.puts(test_string)
48
+ tf.close
49
+ line = LineCache::getline(tf.path, 1)
50
+ assert_equal(test_string, line,
51
+ "C'mon - a simple line test like this worked before.")
52
+ tf.open
53
+ test_string = "Now is another time.\n"
54
+ tf.puts(test_string)
55
+ tf.close
56
+ LineCache::checkcache
57
+ line = LineCache::getline(tf.path, 1)
58
+ assert_equal(test_string, line,
59
+ "checkcache should have reread the temporary file.")
60
+ FileUtils.rm tf.path
61
+
62
+ LineCache::update_cache(__FILE__)
63
+ LineCache::clear_file_cache
64
+ end
65
+
66
+ def test_cached
67
+ assert_equal(false, LineCache::cached?(__FILE__),
68
+ "file #{__FILE__} shouldn't be cached - just cleared cache.")
69
+ line = LineCache::getline(__FILE__, 1)
70
+ assert line
71
+ assert_equal(true, LineCache::cached?(__FILE__),
72
+ "file #{__FILE__} should now be cached")
73
+ assert_equal(false, LineCache::cached_script?('./short-file'),
74
+ "Should not find './short-file' in SCRIPT_LINES__")
75
+ assert_equal(true, 78 < LineCache.size(__FILE__))
76
+ # Dir.chdir(File.dirname(__FILE__)) do
77
+ # load('./short-file', 0)
78
+ # assert_equal(true, LineCache::cached_script?('./short-file'),
79
+ # "Should be able to find './short-file' in SCRIPT_LINES__")
80
+ # end
81
+ end
82
+
83
+ def test_remap
84
+ LineCache::remap_file(__FILE__, 'another-name')
85
+ line1 = LineCache::getline('another-name', 1)
86
+ line2 = LineCache::getline(__FILE__, 1)
87
+ assert_equal(line1, line2, 'Both lines should be the same via remap_file')
88
+ end
89
+
90
+ def test_remap_lines
91
+ LineCache::remap_file_lines(__FILE__, 'test2', (10..11), 6)
92
+
93
+ line5 = LineCache::getline(__FILE__, 5)
94
+ LineCache::remap_file_lines(__FILE__, 'test2', 9, 5)
95
+ rline9 = LineCache::getline('test2', 9)
96
+ assert_equal(line5, rline9,
97
+ 'lines should be the same via remap_file_line - remap integer')
98
+
99
+ line6 = LineCache::getline(__FILE__, 6)
100
+ rline10 = LineCache::getline('test2', 10)
101
+ assert_equal(line6, rline10,
102
+ 'lines should be the same via remap_file_line - range')
103
+
104
+ line7 = LineCache::getline(__FILE__, 7)
105
+ rline11 = LineCache::getline('test2', 11)
106
+ assert_equal(line7, rline11,
107
+ 'lines should be the same via remap_file_line - range')
108
+
109
+ line8 = LineCache::getline(__FILE__, 8)
110
+ LineCache::remap_file_lines(__FILE__, nil, 20, 8)
111
+ rline20 = LineCache::getline(__FILE__, 20)
112
+ assert_equal(line8, rline20,
113
+ 'lines should be the same via remap_file_line - nil file')
114
+ end
115
+
116
+ def test_stat
117
+ assert_equal(nil, LineCache::stat(__FILE__),
118
+ "stat for #{__FILE__} shouldn't be nil - just cleared cache.")
119
+ line = LineCache::getline(__FILE__, 1)
120
+ assert line
121
+ assert(LineCache::stat(__FILE__),
122
+ "file #{__FILE__} should now have a stat")
123
+ end
124
+
125
+ def test_path
126
+ assert_equal(nil, LineCache::path(__FILE__),
127
+ "path for #{__FILE__} should be nil - just cleared cache.")
128
+ path = LineCache::cache(__FILE__)
129
+ assert path
130
+ assert_equal(path, LineCache::path(__FILE__),
131
+ "path of #{__FILE__} should be the same as we got before")
132
+ end
133
+
134
+ def test_trace_line_numbers
135
+ test_file = File.join(@@TEST_DIR, 'short-file')
136
+ ## ?? Not sure if this is correct.
137
+ assert_equal([1], LineCache::trace_line_numbers(test_file))
138
+ test_file = File.join(@@TEST_DIR, 'short-file2')
139
+ assert_equal([1], LineCache::trace_line_numbers(test_file))
140
+ test_file = File.join(@@TEST_DIR, 'rcov-bug.rb')
141
+ assert_equal([3, 7, 8], LineCache::trace_line_numbers(test_file))
142
+ end
143
+
144
+ def test_sha1
145
+ test_file = File.join(@@TEST_DIR, 'short-file')
146
+ LineCache::cache(test_file)
147
+ assert_equal('3e1d87f3399fc73ae5683e106bce1b5ba823fc50',
148
+ LineCache::sha1(test_file))
149
+ end
150
+
151
+ def test_script
152
+ x = nil
153
+ line1 = "loc = Rubinius::VM::backtrace(0)[0]"
154
+ eval(line1 + "
155
+ x = LineCache::getline(loc.static_scope.script, 1)")
156
+ assert_equal(line1, x)
157
+ eval("loc = Rubinius::VM::backtrace(0)[0]
158
+ assert_equal(2, LineCache::size(loc.static_scope.script))")
159
+ string = "loc = Rubinius::VM::backtrace(0)[0]
160
+ LineCache::map_script(loc.static_scope.script)"
161
+ temp_filename = eval(string)
162
+ got_lines = File.open(temp_filename).readlines.join('')
163
+ assert_equal(string, got_lines.chomp)
164
+ assert_equal(1, File.unlink(temp_filename))
165
+ end
166
+
167
+ end
data/test/test-lnum.rb ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ # $Id$
3
+ require 'test/unit'
4
+
5
+ # Test TraceLineNumbers module
6
+ class TestLineNumbers2 < Test::Unit::TestCase
7
+ @@TEST_DIR = File.expand_path(File.dirname(__FILE__))
8
+ @@TOP_SRC_DIR = File.join(@@TEST_DIR, '..')
9
+ require File.join(@@TOP_SRC_DIR, 'lib', 'tracelines.rb')
10
+
11
+ def test_all_lnum_data
12
+ test_dir = File.join(@@TEST_DIR, 'data')
13
+ Dir.chdir(test_dir) do
14
+ Dir.glob('*.rb').sort.each do |f|
15
+ fp = File.open(f, 'r')
16
+ lines = fp.read
17
+ fp.rewind
18
+ first_line = fp.readline.chomp
19
+ fp.close()
20
+ expected_str = first_line[1..-1]
21
+ begin
22
+ expected_lnums = eval(expected_str, binding, __FILE__, __LINE__)
23
+ rescue
24
+ assert nil, "Failed reading expected values from #{f}"
25
+ else
26
+ got_lnums = TraceLineNumbers.lnums_for_str(lines)
27
+ assert_equal(expected_lnums, got_lnums, "Comparing file #{f}")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ # $Id: test-tracelines.rb 235 2010-12-25 14:22:47Z rockyb $
3
+ require 'test/unit'
4
+ require 'fileutils'
5
+ require 'tempfile'
6
+
7
+ # Test TestLineNumbers module
8
+ class TestLineNumbers1 < Test::Unit::TestCase
9
+
10
+ @@TEST_DIR = File.expand_path(File.dirname(__FILE__))
11
+ @@TOP_SRC_DIR = File.join(@@TEST_DIR, '..', 'lib')
12
+ require File.join(@@TOP_SRC_DIR, 'tracelines.rb')
13
+
14
+ @@rcov_file = File.join(@@TEST_DIR, 'rcov-bug.rb')
15
+ # File.open(@@rcov_file, 'r') {|fp|
16
+ # first_line = fp.readline[1..-2]
17
+ # @@rcov_lnums = eval(first_line, binding, __FILE__, __LINE__)
18
+ # }
19
+ @@rcov_lnums = [3, 7, 8]
20
+
21
+ def test_for_file
22
+ rcov_lines = TraceLineNumbers.lnums_for_file(@@rcov_file)
23
+ assert_equal(@@rcov_lnums, rcov_lines)
24
+ end
25
+
26
+ def test_for_string
27
+ string = "# Some rcov bugs.\nz = \"\nNow is the time\n\"\n\nz =~ \n /\n 5\n /ix\n"
28
+ rcov_lines = TraceLineNumbers.lnums_for_str(string)
29
+ check = [2, 6, 7]
30
+ # check = [2, 9]
31
+ assert_equal(check, rcov_lines)
32
+ end
33
+
34
+ def test_for_string_array
35
+ lines = File.open(@@rcov_file).readlines
36
+ rcov_lines =
37
+ TraceLineNumbers.lnums_for_str_array(lines)
38
+ assert_equal(@@rcov_lnums, rcov_lines)
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbx-linecache
3
+ version: !ruby/object:Gem::Version
4
+ hash: 83
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 44
9
+ version: "0.44"
10
+ platform: universal-rubinius
11
+ authors:
12
+ - R. Bernstein
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-25 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rbx-require-relative
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: |
35
+ LineCache is a module for reading and caching lines. This may be useful for
36
+ example in a debugger where the same lines are shown many times.
37
+
38
+ email: rockyb@rubyforge.net
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - README
45
+ - lib/linecache.rb
46
+ - lib/tracelines.rb
47
+ files:
48
+ - AUTHORS
49
+ - COPYING
50
+ - ChangeLog
51
+ - NEWS
52
+ - README
53
+ - Rakefile
54
+ - lib/tracelines.rb
55
+ - lib/linecache.rb
56
+ - test/parse-show.rb
57
+ - test/lnum-diag.rb
58
+ - test/rcov-bug.rb
59
+ - test/test-lnum.rb
60
+ - test/test-linecache.rb
61
+ - test/test-tracelines.rb
62
+ - test/data/if1.rb
63
+ - test/data/comments1.rb
64
+ - test/data/not-lit.rb
65
+ - test/data/begin2.rb
66
+ - test/data/block2.rb
67
+ - test/data/if6.rb
68
+ - test/data/end.rb
69
+ - test/data/case4.rb
70
+ - test/data/begin1.rb
71
+ - test/data/for1.rb
72
+ - test/data/match.rb
73
+ - test/data/match3a.rb
74
+ - test/data/class1.rb
75
+ - test/data/if3.rb
76
+ - test/data/if5.rb
77
+ - test/data/case1.rb
78
+ - test/data/def1.rb
79
+ - test/data/if7.rb
80
+ - test/data/block1.rb
81
+ - test/data/begin3.rb
82
+ - test/data/case3.rb
83
+ - test/data/case2.rb
84
+ - test/data/each1.rb
85
+ - test/data/if2.rb
86
+ - test/data/match3.rb
87
+ - test/data/if4.rb
88
+ - test/data/case5.rb
89
+ - test/short-file
90
+ - test/short-file2
91
+ has_rdoc: true
92
+ homepage: http://wiki.github.com/rocky/rbx-trepanning
93
+ licenses:
94
+ - MIT
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --title
98
+ - LineCache 0.44 Documentation
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ~>
105
+ - !ruby/object:Gem::Version
106
+ hash: 57
107
+ segments:
108
+ - 1
109
+ - 8
110
+ - 7
111
+ version: 1.8.7
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project: rocky-hacks
124
+ rubygems_version: 1.3.7
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: Read file with caching
128
+ test_files:
129
+ - test/parse-show.rb
130
+ - test/lnum-diag.rb
131
+ - test/rcov-bug.rb
132
+ - test/test-lnum.rb
133
+ - test/test-linecache.rb
134
+ - test/test-tracelines.rb