linecache2 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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
@@ -0,0 +1,2 @@
1
+ # This is a small test file.
2
+
@@ -0,0 +1,174 @@
1
+ #!/usr/bin/env ruby
2
+ require 'minitest/autorun'
3
+ require 'fileutils'
4
+ require 'tempfile'
5
+ require 'set'
6
+
7
+ # Test LineCache module
8
+ class TestLineCache < MiniTest::Test
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, 'linecache2.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_getline_eval
67
+ # str = eval("x=1
68
+ # LineCache::getline(RubyVM::Frame.get.iseq, 1)")
69
+ # assert_equal("x=1", str)
70
+ # str = eval("x=2
71
+ # LineCache::getline(RubyVM::Frame.get.iseq, 2)")
72
+ # assert_equal("LineCache::getline(RubyVM::Frame.get.iseq, 2)", str)
73
+ # end
74
+
75
+ def test_cached
76
+ assert_equal(false, LineCache::cached?(__FILE__),
77
+ "file #{__FILE__} shouldn't be cached - just cleared cache.")
78
+ line = LineCache::getline(__FILE__, 1)
79
+ assert line
80
+ assert_equal(true, LineCache::cached?(__FILE__),
81
+ "file #{__FILE__} should now be cached")
82
+ assert_equal(false, LineCache::cached_script?('./short-file'),
83
+ "Should not find './short-file' in SCRIPT_LINES__")
84
+ assert_equal(true, 78 < LineCache.size(__FILE__))
85
+ Dir.chdir(File.dirname(__FILE__)) do
86
+ filename = './short-file'
87
+ load(filename, 0)
88
+ fullname = File.expand_path(filename)
89
+ assert_equal(true, LineCache::cached_script?(fullname),
90
+ "Should be able to find '#{filename}' in SCRIPT_LINES__")
91
+ end
92
+ end
93
+
94
+ def test_remap
95
+ LineCache::remap_file(__FILE__, 'another-name')
96
+ line1 = LineCache::getline('another-name', 1)
97
+ line2 = LineCache::getline(__FILE__, 1)
98
+ assert_equal(line1, line2, 'Both lines should be the same via remap_file')
99
+ end
100
+
101
+ def test_remap_lines
102
+ LineCache::remap_file_lines(__FILE__, 'test2', (10..11), 6)
103
+
104
+ line5 = LineCache::getline(__FILE__, 5)
105
+ LineCache::remap_file_lines(__FILE__, 'test2', 9, 5)
106
+ rline9 = LineCache::getline('test2', 9)
107
+ assert_equal(line5, rline9,
108
+ 'lines should be the same via remap_file_line - remap integer')
109
+
110
+ line6 = LineCache::getline(__FILE__, 6)
111
+ rline10 = LineCache::getline('test2', 10)
112
+ assert_equal(line6, rline10,
113
+ 'lines should be the same via remap_file_line - range')
114
+
115
+ line7 = LineCache::getline(__FILE__, 7)
116
+ rline11 = LineCache::getline('test2', 11)
117
+ assert_equal(line7, rline11,
118
+ 'lines should be the same via remap_file_line - range')
119
+
120
+ line8 = LineCache::getline(__FILE__, 8)
121
+ LineCache::remap_file_lines(__FILE__, nil, 20, 8)
122
+ rline20 = LineCache::getline(__FILE__, 20)
123
+ assert_equal(line8, rline20,
124
+ 'lines should be the same via remap_file_line - nil file')
125
+ end
126
+
127
+ def test_stat
128
+ assert_equal(nil, LineCache::stat(__FILE__),
129
+ "stat for #{__FILE__} shouldn't be nil - just cleared cache.")
130
+ line = LineCache::getline(__FILE__, 1)
131
+ assert line
132
+ assert(LineCache::stat(__FILE__),
133
+ "file #{__FILE__} should now have a stat")
134
+ end
135
+
136
+ def test_path
137
+ assert_equal(nil, LineCache::path(__FILE__),
138
+ "path for #{__FILE__} should be nil - just cleared cache.")
139
+ path = LineCache::cache(__FILE__)
140
+ assert path
141
+ assert_equal(path, LineCache::path(__FILE__),
142
+ "path of #{__FILE__} should be the same as we got before")
143
+ end
144
+
145
+ def test_trace_line_numbers
146
+ # test_file = File.join(@@TEST_DIR, 'short-file')
147
+ # assert_equal([2], LineCache::trace_line_numbers(test_file))
148
+ test_file = File.join(@@TEST_DIR, 'rcov-bug.rb')
149
+ assert_equal([3, 10], LineCache::trace_line_numbers(test_file))
150
+ end
151
+
152
+ def test_sha1
153
+ test_file = File.join(@@TEST_DIR, 'short-file')
154
+ LineCache::cache(test_file)
155
+ assert_equal('3e1d87f3399fc73ae5683e106bce1b5ba823fc50',
156
+ LineCache::sha1(test_file))
157
+ end
158
+
159
+ # def test_iseq_cache
160
+ # template = "x=1
161
+ # y=2
162
+ # LineCache::getline(RubyVM::Frame.get.iseq, %d)"
163
+ # assert_equal("x=1", eval(template % 1))
164
+ # assert_equal("y=2", eval(template % 2))
165
+ # string = "a = 1
166
+ # b = 2
167
+ # LineCache::map_iseq(RubyVM::Frame.get.iseq)"
168
+ # temp_filename = eval(string)
169
+ # got_lines = File.open(temp_filename).readlines.join('')
170
+ # assert_equal(string, got_lines.chomp)
171
+ # assert_equal(1, File.unlink(temp_filename))
172
+ # end
173
+
174
+ end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ require 'minitest/autorun'
3
+
4
+ # require 'rubygems'
5
+ # require 'ruby-debug'; Debugger.init
6
+
7
+ # Test TraceLineNumbers module
8
+ class TestLineNumbers2 < MiniTest::Test
9
+ @@TEST_DIR = File.expand_path(File.dirname(__FILE__))
10
+ @@TOP_SRC_DIR = File.join(@@TEST_DIR, '..')
11
+ require_relative '../lib/tracelines'
12
+
13
+ def test_all_lnum_data
14
+ test_dir = File.join(@@TEST_DIR, 'data')
15
+ Dir.chdir(test_dir) do
16
+ Dir.glob('*.rb').sort.each do |f|
17
+ fp = File.open(f, 'r')
18
+ lines = fp.read
19
+ fp.rewind
20
+ first_line = fp.readline.chomp
21
+ fp.close()
22
+ expected_str = first_line[1..-1]
23
+ begin
24
+ expected_lnums = eval(expected_str, binding, __FILE__, __LINE__)
25
+ rescue
26
+ assert nil, "Failed reading expected values from #{f}"
27
+ else
28
+ got_lnums = TraceLineNumbers.lnums_for_str(lines)
29
+ assert_equal(expected_lnums, got_lnums,
30
+ "Mismatch for file #{f}")
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ require 'minitest/autorun'
3
+ require 'fileutils'
4
+ require 'tempfile'
5
+
6
+ SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
7
+ # Test TestLineNumbers module
8
+ class TestLineNumbers1 < MiniTest::Test
9
+
10
+ @@TEST_DIR = File.expand_path(File.dirname(__FILE__))
11
+ require_relative '../lib/tracelines'
12
+
13
+ @@rcov_file = File.join(@@TEST_DIR, 'rcov-bug.rb')
14
+ File.open(@@rcov_file, 'r') {|fp|
15
+ first_line = fp.readline[1..-2]
16
+ @@rcov_lnums = eval(first_line, binding, __FILE__, __LINE__)
17
+ }
18
+
19
+ def test_for_file
20
+ rcov_lines = TraceLineNumbers.lnums_for_file(@@rcov_file)
21
+ assert_equal(@@rcov_lnums, rcov_lines)
22
+ end
23
+
24
+ def test_for_string
25
+ string = "# Some rcov bugs.\nz = \"\nNow is the time\n\"\n\nz =~ \n /\n 5\n /ix\n"
26
+ rcov_lines = TraceLineNumbers::lnums_for_str(string)
27
+ assert_equal([2, 9], rcov_lines)
28
+ end
29
+
30
+ def test_for_string_array
31
+ load(@@rcov_file, 0)
32
+ rcov_lines =
33
+ TraceLineNumbers.lnums_for_str_array(SCRIPT_LINES__[@@rcov_file])
34
+ assert_equal(@@rcov_lnums, rcov_lines)
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: linecache2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
5
+ platform: ruby
6
+ authors:
7
+ - R. Bernstein
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ description: |
28
+ LineCache is a module for reading and caching lines. This may be useful for
29
+ example in a debugger where the same lines are shown many times.
30
+
31
+ This version works only with a Ruby 2.0 or greater.
32
+ email: rockyb@rubyforge.net
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files:
36
+ - README.md
37
+ - lib/tracelines.rb
38
+ files:
39
+ - AUTHORS
40
+ - COPYING
41
+ - ChangeLog
42
+ - NEWS
43
+ - README.md
44
+ - Rakefile
45
+ - lib/linecache2.rb
46
+ - lib/linecache2/colors.rb
47
+ - lib/linecache2/version.rb
48
+ - lib/tracelines.rb
49
+ - test/data/begin1.rb
50
+ - test/data/begin2.rb
51
+ - test/data/begin3.rb
52
+ - test/data/block1.rb
53
+ - test/data/block2.rb
54
+ - test/data/case1.rb
55
+ - test/data/case2.rb
56
+ - test/data/case3.rb
57
+ - test/data/case4.rb
58
+ - test/data/case5.rb
59
+ - test/data/class1.rb
60
+ - test/data/comments1.rb
61
+ - test/data/def1.rb
62
+ - test/data/each1.rb
63
+ - test/data/end.rb
64
+ - test/data/for1.rb
65
+ - test/data/if1.rb
66
+ - test/data/if2.rb
67
+ - test/data/if3.rb
68
+ - test/data/if4.rb
69
+ - test/data/if5.rb
70
+ - test/data/if6.rb
71
+ - test/data/if7.rb
72
+ - test/data/match.rb
73
+ - test/data/match3.rb
74
+ - test/data/match3a.rb
75
+ - test/data/not-lit.rb
76
+ - test/lnum-diag.rb
77
+ - test/parse-show.rb
78
+ - test/rcov-bug.rb
79
+ - test/short-file
80
+ - test/test-linecache.rb
81
+ - test/test-lnum.rb
82
+ - test/test-tracelines.rb
83
+ homepage: http://github.com/rocky/rb-linecache2
84
+ licenses:
85
+ - GPL2
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options:
89
+ - "--main"
90
+ - README.md
91
+ - "--title"
92
+ - LineCache 1.4.0 Documentation
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 2.0.0
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.8
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Module to read and cache Ruby program files and file information
111
+ test_files: []
112
+ has_rdoc: true