bindex 0.7.0 → 0.8.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a529d393523162bc2f77aba87dba5b0f40296e83275ad974f8daf3e153647860
4
- data.tar.gz: d3de0fc8593a6b60e373471b57ec39d5198e7cb76a65c90d7d1ce06d5d173955
3
+ metadata.gz: 2afa6fd9add9be18fcc18af31351373180952abb3b62ed5cda648fad1e8ab5e9
4
+ data.tar.gz: afbd2740d00847f74a2fbea09565680b72015af4096213fca2f5fb639d3c0f71
5
5
  SHA512:
6
- metadata.gz: bd8a0e928378ccaab83e4bd9225c2332145269ff5a0f1337b8b126f40ec97e8356243c297ba71117685e1c3e8ec45d87708647fca2cfc3e32cded3fbc8858872
7
- data.tar.gz: 7ddc6e5758b5010190dad749349fb815ca681f251ffdae3fc0be215e1a15d76ad61ae43636ecbeb58c2fe87b2253d14d1fe9cf55bf7ed22aa1f805e5ca1ffb4f
6
+ metadata.gz: 9c8c2e671de5f1c198ef603c6c8a65a918f98601c167f0a3abdb5aa93f7951c6b44435a7ac598098b107dd4612d6684da761c8a19fabb5680eff2ca421fda1a1
7
+ data.tar.gz: 8196d2b2fbc90a8c9b2dc30eb3e8f45c8774610094487642c416dc31dda9c5f8be73b7482cdd5e8a7a475516d2627c95580cd2220614c5538c071a52f7cd1d3f
@@ -1,13 +1,10 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - ruby-2.3.3
5
- - ruby-2.4.0
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/bindex.svg?branch=master)](https://travis-ci.org/gsamokovarov/bindex)
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.0.0 and above is supported.
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/*_test.rb']
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
@@ -5,7 +5,7 @@ when "ruby"
5
5
  $CFLAGS << " -Wall"
6
6
  $CFLAGS << " -g3 -O0" if ENV["DEBUG"]
7
7
 
8
- create_makefile("skiptrace/cruby")
8
+ create_makefile("skiptrace/internal/cruby")
9
9
  else
10
10
  IO.write(File.expand_path("../Makefile", __FILE__), <<-END)
11
11
  all install static install-so install-rb: Makefile
@@ -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 "skiptrace/version"
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,5 @@
1
+ class Binding
2
+ def source_location
3
+ eval '[__FILE__, __LINE__.to_i]'
4
+ end unless method_defined?(:source_location)
5
+ end
@@ -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
@@ -0,0 +1,5 @@
1
+ class Exception
2
+ def binding_locations
3
+ @binding_locations ||= Skiptrace::BindingLocations.new(backtrace_locations, bindings)
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'skiptrace/internal/jruby_internals'
2
+
3
+ module Skiptrace
4
+ java_import com.gsamokovarov.skiptrace.JRubyIntegration
5
+
6
+ JRubyIntegration.setup(JRuby.runtime)
7
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Skiptrace
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.1"
3
3
  end
@@ -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.0.0"
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
- class BasicNestedFixture
2
- def call
3
- raise_an_error
4
- rescue => exc
5
- exc
6
- end
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
- private
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
- class CustomErrorFixture
2
- Error = Class.new(StandardError)
1
+ module Skiptrace
2
+ module CustomErrorFixture
3
+ Error = Class.new(StandardError)
3
4
 
4
- def call
5
- raise Error
6
- rescue => exc
7
- exc
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
- class EvalNestedFixture
2
- def call
3
- tap { raise_an_error_in_eval }
4
- rescue => exc
5
- exc
6
- end
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
- private
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,7 +1,9 @@
1
- class FlatFixture
2
- def call
3
- raise
4
- rescue => exc
5
- exc
1
+ module Skiptrace
2
+ module FlatFixture
3
+ def self.call
4
+ raise
5
+ rescue => exc
6
+ exc
7
+ end
6
8
  end
7
9
  end
@@ -1,11 +1,14 @@
1
- class ReraisedFixture
2
- def call
3
- reraise_an_error
4
- rescue => exc
5
- exc
6
- end
1
+ module Skiptrace
2
+ module ReraisedFixture
3
+ extend self
7
4
 
8
- private
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,11 @@
1
+ require 'test_helper'
2
+
3
+ module Skiptrace
4
+ class CurrentBindingsTest < Test
5
+ test 'first binding returned is the current one' do
6
+ _, lineno = Skiptrace.current_bindings.first.source_location
7
+
8
+ assert_equal __LINE__ - 2, lineno
9
+ end
10
+ end
11
+ 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
@@ -10,8 +10,10 @@ Dir["#{current_directory}/fixtures/**/*.rb"].each do |fixture|
10
10
  require fixture
11
11
  end
12
12
 
13
- class BaseTest < MiniTest::Test
14
- def self.test(name, &block)
15
- define_method("test_#{name}", &block)
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.7.0
4
+ version: 0.8.1
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-04-08 00:00:00.000000000 Z
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/jruby.rb
97
- - lib/skiptrace/jruby_internals.jar
98
- - lib/skiptrace/rubinius.rb
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
@@ -1,5 +0,0 @@
1
- require 'skiptrace/jruby_internals'
2
-
3
- java_import com.gsamokovarov.skiptrace.JRubyIntegration
4
-
5
- JRubyIntegration.setup(JRuby.runtime)
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CurrentBindingsTest < BaseTest
4
- test 'first binding returned is the current one' do
5
- assert_equal __LINE__, Skiptrace.current_bindings.first.eval('__LINE__')
6
- end
7
- end
@@ -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