bindex 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -7
- data/README.md +7 -2
- data/Rakefile +3 -3
- data/lib/skiptrace.rb +8 -5
- data/lib/skiptrace/binding_ext.rb +5 -0
- data/lib/skiptrace/binding_locations.rb +34 -0
- data/lib/skiptrace/exception_ext.rb +5 -0
- data/lib/skiptrace/internal/jruby.rb +7 -0
- data/lib/skiptrace/{jruby_internals.jar → internal/jruby_internals.jar} +0 -0
- data/lib/skiptrace/{rubinius.rb → internal/rubinius.rb} +0 -0
- data/lib/skiptrace/location.rb +34 -0
- data/lib/skiptrace/version.rb +1 -1
- data/skiptrace.gemspec +1 -1
- data/test/fixtures/basic_nested_fixture.rb +11 -7
- data/test/fixtures/custom_error_fixture.rb +8 -6
- data/test/fixtures/eval_nested_fixture.rb +11 -7
- data/test/fixtures/flat_fixture.rb +7 -5
- data/test/fixtures/reraised_fixture.rb +11 -7
- data/test/skiptrace/current_bindings_test.rb +11 -0
- data/test/skiptrace/exception_test.rb +67 -0
- data/test/skiptrace/location_test.rb +18 -0
- data/test/test_helper.rb +5 -3
- metadata +15 -9
- data/lib/skiptrace/jruby.rb +0 -5
- data/test/current_bindings_test.rb +0 -7
- data/test/exception_test.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc0cd337ca86dbea712a96611e763bac2bfa6c5d071800dc31debfc9247014b2
|
4
|
+
data.tar.gz: cf366a1aeefb502da4a3fd8232b25ead77948edcae7a7e19519638f5548275a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37399ff142e9ac9248d161ed88af04b8cb84fcec714e472078aa509a160ba3fe744c75caa1d084275cad601ede518e748841e3b71443ee75ed5c796c5331eb2c
|
7
|
+
data.tar.gz: 8568a9a1b78ebf4bf58ceb461e3aed432901284aa8dbd8bf8321818cf90e0b60455a20b8a1c87ce42956d41606ca041437d37162c6721d94703a1e8f6f915220
|
data/.travis.yml
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
- ruby-2.
|
5
|
-
- ruby-2.
|
4
|
+
- ruby-2.5
|
5
|
+
- ruby-2.6
|
6
6
|
- ruby-head
|
7
7
|
|
8
|
-
- jruby-9.1.8.0
|
9
|
-
- jruby-head
|
10
|
-
|
11
8
|
allow_failures:
|
12
9
|
- rvm: ruby-head
|
13
10
|
- rvm: jruby-head
|
@@ -18,6 +15,4 @@ env:
|
|
18
15
|
|
19
16
|
before_install: gem install bundler
|
20
17
|
|
21
|
-
sudo: false
|
22
|
-
|
23
18
|
cache: bundler
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Skiptrace [![Build Status](https://travis-ci.org/gsamokovarov/
|
1
|
+
# Skiptrace [![Build Status](https://travis-ci.org/gsamokovarov/skiptrace.svg?branch=master)](https://travis-ci.org/gsamokovarov/skiptrace)
|
2
2
|
|
3
3
|
When Ruby raises an exception, it leaves you a backtrace to help you figure out
|
4
4
|
where did the exception originated in. Skiptrace gives you the bindings as well.
|
@@ -18,6 +18,11 @@ Skiptrace defines the following API:
|
|
18
18
|
|
19
19
|
Returns all the bindings up to the one in which the exception originated in.
|
20
20
|
|
21
|
+
#### Exception#binding_locations
|
22
|
+
|
23
|
+
Returns an array of `Skiptrace::Location` objects that are like [`Thread::Backtrace::Location`](https://ruby-doc.org/core-2.6.3/Thread/Backtrace/Location.html)
|
24
|
+
but also carry a `Binding` object for that frame through the `#binding` method.
|
25
|
+
|
21
26
|
#### Skiptrace.current_bindings
|
22
27
|
|
23
28
|
Returns all of the current Ruby execution state bindings. The first one is the
|
@@ -28,7 +33,7 @@ caller one and so on.
|
|
28
33
|
|
29
34
|
### CRuby
|
30
35
|
|
31
|
-
CRuby 2.
|
36
|
+
CRuby 2.5.0 and above is supported.
|
32
37
|
|
33
38
|
### JRuby
|
34
39
|
|
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ Bundler::GemHelper.install_tasks name: ENV.fetch('GEM_NAME', 'skiptrace')
|
|
7
7
|
|
8
8
|
Rake::TestTask.new do |t|
|
9
9
|
t.libs << 'test'
|
10
|
-
t.test_files = FileList['test
|
10
|
+
t.test_files = FileList['test/**/*_test.rb']
|
11
11
|
t.verbose = true
|
12
12
|
end
|
13
13
|
|
@@ -17,7 +17,7 @@ when 'ruby'
|
|
17
17
|
|
18
18
|
Rake::ExtensionTask.new('skiptrace') do |ext|
|
19
19
|
ext.name = 'cruby'
|
20
|
-
ext.lib_dir = 'lib/skiptrace'
|
20
|
+
ext.lib_dir = 'lib/skiptrace/internal'
|
21
21
|
end
|
22
22
|
|
23
23
|
task default: [:clean, :compile, :test]
|
@@ -26,7 +26,7 @@ when 'jruby'
|
|
26
26
|
|
27
27
|
Rake::JavaExtensionTask.new('skiptrace') do |ext|
|
28
28
|
ext.name = 'jruby_internals'
|
29
|
-
ext.lib_dir = 'lib/skiptrace'
|
29
|
+
ext.lib_dir = 'lib/skiptrace/internal'
|
30
30
|
ext.source_version = '1.8'
|
31
31
|
ext.target_version = '1.8'
|
32
32
|
end
|
data/lib/skiptrace.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
case RUBY_ENGINE
|
2
2
|
when 'rbx'
|
3
|
-
require 'skiptrace/rubinius'
|
3
|
+
require 'skiptrace/internal/rubinius'
|
4
4
|
when 'jruby'
|
5
|
-
require 'skiptrace/jruby'
|
5
|
+
require 'skiptrace/internal/jruby'
|
6
6
|
when 'ruby'
|
7
|
-
require 'skiptrace/cruby'
|
7
|
+
require 'skiptrace/internal/cruby'
|
8
8
|
end
|
9
9
|
|
10
|
-
require
|
11
|
-
|
10
|
+
require 'skiptrace/location'
|
11
|
+
require 'skiptrace/binding_locations'
|
12
|
+
require 'skiptrace/binding_ext'
|
13
|
+
require 'skiptrace/exception_ext'
|
14
|
+
require 'skiptrace/version'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Skiptrace
|
2
|
+
class BindingLocations < BasicObject
|
3
|
+
def initialize(locations, bindings)
|
4
|
+
@locations = locations
|
5
|
+
@bindings = bindings
|
6
|
+
@cached_locations = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def cached_location(location)
|
12
|
+
@cached_locations[location.to_s] ||= Location.new(location, guess_binding_around(location))
|
13
|
+
end
|
14
|
+
|
15
|
+
def guess_binding_around(location)
|
16
|
+
location && @bindings.find do |binding|
|
17
|
+
binding.source_location == [location.path, location.lineno]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing(name, *args, &block)
|
22
|
+
case maybe_location = @locations.public_send(name, *args, &block)
|
23
|
+
when ::Thread::Backtrace::Location
|
24
|
+
cached_location(maybe_location)
|
25
|
+
else
|
26
|
+
maybe_location
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def respond_to_missing?(name, include_all = false)
|
31
|
+
@locations.respond_to?(name, include_all)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Skiptrace
|
2
|
+
class Location
|
3
|
+
attr_reader :binding
|
4
|
+
|
5
|
+
def initialize(location, binding)
|
6
|
+
@location = location
|
7
|
+
@binding = binding
|
8
|
+
end
|
9
|
+
|
10
|
+
def absolute_path
|
11
|
+
@location.absolute_path
|
12
|
+
end
|
13
|
+
|
14
|
+
def base_label
|
15
|
+
@location.base_label
|
16
|
+
end
|
17
|
+
|
18
|
+
def inspect
|
19
|
+
@location.inspect
|
20
|
+
end
|
21
|
+
|
22
|
+
def label
|
23
|
+
@location.label
|
24
|
+
end
|
25
|
+
|
26
|
+
def lineno
|
27
|
+
@location.lineno
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
@location.to_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/skiptrace/version.rb
CHANGED
data/skiptrace.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.homepage = "https://github.com/gsamokovarov/skiptrace"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
15
|
-
spec.required_ruby_version = ">= 2.
|
15
|
+
spec.required_ruby_version = ">= 2.5.0"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0")
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -1,13 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module Skiptrace
|
2
|
+
module BasicNestedFixture
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def call
|
6
|
+
raise_an_error
|
7
|
+
rescue => exc
|
8
|
+
exc
|
9
|
+
end
|
7
10
|
|
8
|
-
|
11
|
+
private
|
9
12
|
|
10
13
|
def raise_an_error
|
11
14
|
raise
|
12
15
|
end
|
16
|
+
end
|
13
17
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Skiptrace
|
2
|
+
module CustomErrorFixture
|
3
|
+
Error = Class.new(StandardError)
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def self.call
|
6
|
+
raise Error
|
7
|
+
rescue => exc
|
8
|
+
exc
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
@@ -1,13 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module Skiptrace
|
2
|
+
module EvalNestedFixture
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def call
|
6
|
+
tap { raise_an_error_in_eval }
|
7
|
+
rescue => exc
|
8
|
+
exc
|
9
|
+
end
|
7
10
|
|
8
|
-
|
11
|
+
private
|
9
12
|
|
10
13
|
def raise_an_error_in_eval
|
11
14
|
eval 'raise', binding, __FILE__, __LINE__
|
12
15
|
end
|
16
|
+
end
|
13
17
|
end
|
@@ -1,11 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
rescue => exc
|
5
|
-
exc
|
6
|
-
end
|
1
|
+
module Skiptrace
|
2
|
+
module ReraisedFixture
|
3
|
+
extend self
|
7
4
|
|
8
|
-
|
5
|
+
def call
|
6
|
+
reraise_an_error
|
7
|
+
rescue => exc
|
8
|
+
exc
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
9
12
|
|
10
13
|
def raise_an_error_in_eval
|
11
14
|
method_that_raises
|
@@ -16,4 +19,5 @@ class ReraisedFixture
|
|
16
19
|
def method_that_raises
|
17
20
|
raise
|
18
21
|
end
|
22
|
+
end
|
19
23
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Skiptrace
|
4
|
+
class ExceptionTest < Test
|
5
|
+
test 'bindings returns all the bindings of where the error originated' do
|
6
|
+
exc = FlatFixture.()
|
7
|
+
|
8
|
+
assert_equal 4, exc.bindings.first.source_location.last
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'bindings returns all the bindings of where a custom error originate' do
|
12
|
+
exc = CustomErrorFixture.()
|
13
|
+
|
14
|
+
assert_equal 6, exc.bindings.first.source_location.last
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'bindings goes down the stack' do
|
18
|
+
exc = BasicNestedFixture.()
|
19
|
+
|
20
|
+
assert_equal 14, exc.bindings.first.source_location.last
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'bindings inside of an eval' do
|
24
|
+
exc = EvalNestedFixture.()
|
25
|
+
|
26
|
+
assert_equal 14, exc.bindings.first.source_location.last
|
27
|
+
end
|
28
|
+
|
29
|
+
test "re-raising doesn't lose bindings information" do
|
30
|
+
exc = ReraisedFixture.()
|
31
|
+
|
32
|
+
assert_equal 6, exc.bindings.first.source_location.last
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'bindings is empty when exception is still not raised' do
|
36
|
+
exc = RuntimeError.new
|
37
|
+
|
38
|
+
assert_equal [], exc.bindings
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'bindings is empty when set backtrace is badly called' do
|
42
|
+
exc = RuntimeError.new
|
43
|
+
|
44
|
+
# Exception#set_backtrace expects a string or array of strings. If the
|
45
|
+
# input isn't like this it will raise a TypeError.
|
46
|
+
assert_raises(TypeError) do
|
47
|
+
exc.set_backtrace([nil])
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_equal [], exc.bindings
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'binding_locations maps closely to backtrace_locations' do
|
54
|
+
exc = FlatFixture.()
|
55
|
+
|
56
|
+
exc.binding_locations.first.tap do |location|
|
57
|
+
assert_equal 4, location.lineno
|
58
|
+
assert_equal exc, location.binding.eval('exc')
|
59
|
+
end
|
60
|
+
|
61
|
+
exc.binding_locations[1].tap do |location|
|
62
|
+
assert_equal 54, location.lineno
|
63
|
+
assert_equal exc, location.binding.eval('exc')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Skiptrace
|
4
|
+
class LocationTest < Test
|
5
|
+
test 'behaves like Thread::Backtrace::Location' do
|
6
|
+
native_location = caller_locations.first
|
7
|
+
location = Skiptrace::Location.new(native_location, binding)
|
8
|
+
|
9
|
+
assert_equal native_location.absolute_path, location.absolute_path
|
10
|
+
assert_equal native_location.base_label, location.base_label
|
11
|
+
assert_equal native_location.inspect, location.inspect
|
12
|
+
assert_equal native_location.label, location.label
|
13
|
+
assert_equal native_location.to_s, location.to_s
|
14
|
+
|
15
|
+
assert_equal [__FILE__, __LINE__ - 8], location.binding.source_location
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -10,8 +10,10 @@ Dir["#{current_directory}/fixtures/**/*.rb"].each do |fixture|
|
|
10
10
|
require fixture
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
module Skiptrace
|
14
|
+
class Test < MiniTest::Test
|
15
|
+
def self.test(name, &block)
|
16
|
+
define_method("test_#{name}", &block)
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bindex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genadi Samokovarov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -93,18 +93,23 @@ files:
|
|
93
93
|
- ext/skiptrace/extconf.rb
|
94
94
|
- lib/bindex.rb
|
95
95
|
- lib/skiptrace.rb
|
96
|
-
- lib/skiptrace/
|
97
|
-
- lib/skiptrace/
|
98
|
-
- lib/skiptrace/
|
96
|
+
- lib/skiptrace/binding_ext.rb
|
97
|
+
- lib/skiptrace/binding_locations.rb
|
98
|
+
- lib/skiptrace/exception_ext.rb
|
99
|
+
- lib/skiptrace/internal/jruby.rb
|
100
|
+
- lib/skiptrace/internal/jruby_internals.jar
|
101
|
+
- lib/skiptrace/internal/rubinius.rb
|
102
|
+
- lib/skiptrace/location.rb
|
99
103
|
- lib/skiptrace/version.rb
|
100
104
|
- skiptrace.gemspec
|
101
|
-
- test/current_bindings_test.rb
|
102
|
-
- test/exception_test.rb
|
103
105
|
- test/fixtures/basic_nested_fixture.rb
|
104
106
|
- test/fixtures/custom_error_fixture.rb
|
105
107
|
- test/fixtures/eval_nested_fixture.rb
|
106
108
|
- test/fixtures/flat_fixture.rb
|
107
109
|
- test/fixtures/reraised_fixture.rb
|
110
|
+
- test/skiptrace/current_bindings_test.rb
|
111
|
+
- test/skiptrace/exception_test.rb
|
112
|
+
- test/skiptrace/location_test.rb
|
108
113
|
- test/test_helper.rb
|
109
114
|
homepage: https://github.com/gsamokovarov/bindex
|
110
115
|
licenses:
|
@@ -130,11 +135,12 @@ signing_key:
|
|
130
135
|
specification_version: 4
|
131
136
|
summary: Bindings for your Ruby exceptions
|
132
137
|
test_files:
|
133
|
-
- test/current_bindings_test.rb
|
134
|
-
- test/exception_test.rb
|
135
138
|
- test/fixtures/basic_nested_fixture.rb
|
136
139
|
- test/fixtures/custom_error_fixture.rb
|
137
140
|
- test/fixtures/eval_nested_fixture.rb
|
138
141
|
- test/fixtures/flat_fixture.rb
|
139
142
|
- test/fixtures/reraised_fixture.rb
|
143
|
+
- test/skiptrace/current_bindings_test.rb
|
144
|
+
- test/skiptrace/exception_test.rb
|
145
|
+
- test/skiptrace/location_test.rb
|
140
146
|
- test/test_helper.rb
|
data/lib/skiptrace/jruby.rb
DELETED
data/test/exception_test.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ExceptionTest < BaseTest
|
4
|
-
test 'bindings returns all the bindings of where the error originated' do
|
5
|
-
exc = FlatFixture.new.call
|
6
|
-
|
7
|
-
assert_equal 3, exc.bindings.first.eval('__LINE__')
|
8
|
-
end
|
9
|
-
|
10
|
-
test 'bindings returns all the bindings of where a custom error originate' do
|
11
|
-
exc = CustomErrorFixture.new.call
|
12
|
-
|
13
|
-
assert_equal 5, exc.bindings.first.eval('__LINE__')
|
14
|
-
end
|
15
|
-
|
16
|
-
test 'bindings goes down the_stack' do
|
17
|
-
exc = BasicNestedFixture.new.call
|
18
|
-
|
19
|
-
assert_equal 11, exc.bindings.first.eval('__LINE__')
|
20
|
-
end
|
21
|
-
|
22
|
-
test 'bindings inside_of_an_eval' do
|
23
|
-
exc = EvalNestedFixture.new.call
|
24
|
-
|
25
|
-
assert_equal 11, exc.bindings.first.eval('__LINE__')
|
26
|
-
end
|
27
|
-
|
28
|
-
test "re-raising doesn't lose bindings information" do
|
29
|
-
exc = ReraisedFixture.new.call
|
30
|
-
|
31
|
-
assert_equal 3, exc.bindings.first.eval('__LINE__')
|
32
|
-
end
|
33
|
-
|
34
|
-
test 'bindings is_empty_when_exception_is_still_not_raised' do
|
35
|
-
exc = RuntimeError.new
|
36
|
-
|
37
|
-
assert_equal [], exc.bindings
|
38
|
-
end
|
39
|
-
|
40
|
-
test 'bindings is_empty_when_set_backtrace_is_badly_called' do
|
41
|
-
exc = RuntimeError.new
|
42
|
-
|
43
|
-
# Exception#set_backtrace expects a string or array of strings. If the
|
44
|
-
# input isn't like this it will raise a TypeError.
|
45
|
-
assert_raises(TypeError) do
|
46
|
-
exc.set_backtrace([nil])
|
47
|
-
end
|
48
|
-
|
49
|
-
assert_equal [], exc.bindings
|
50
|
-
end
|
51
|
-
end
|