bindex 0.5.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +2 -11
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +1 -1
- data/README.md +10 -5
- data/Rakefile +12 -6
- data/bindex.gemspec +4 -4
- data/ext/{bindex/com/gsamokovarov/bindex → skiptrace/com/gsamokovarov/skiptrace}/BindingBuilder.java +1 -1
- data/ext/{bindex/com/gsamokovarov/bindex → skiptrace/com/gsamokovarov/skiptrace}/CurrentBindingsIterator.java +1 -1
- data/ext/{bindex/com/gsamokovarov/bindex → skiptrace/com/gsamokovarov/skiptrace}/JRubyIntegration.java +4 -4
- data/ext/{bindex/com/gsamokovarov/bindex → skiptrace/com/gsamokovarov/skiptrace}/RubyBindingsCollector.java +1 -1
- data/ext/{bindex/com/gsamokovarov/bindex → skiptrace/com/gsamokovarov/skiptrace}/SetExceptionBindingsEventHook.java +1 -1
- data/ext/{bindex/com/gsamokovarov/bindex → skiptrace/com/gsamokovarov/skiptrace}/ThreadContextInterfaceException.java +1 -1
- data/ext/{bindex/com/gsamokovarov/bindex → skiptrace/com/gsamokovarov/skiptrace}/ThreadContextInternals.java +1 -1
- data/ext/{bindex → skiptrace}/cruby.c +8 -8
- data/ext/{bindex → skiptrace}/extconf.rb +1 -1
- data/lib/bindex.rb +3 -9
- data/lib/skiptrace.rb +14 -0
- 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/internal/jruby_internals.jar +0 -0
- data/lib/{bindex → skiptrace/internal}/rubinius.rb +5 -5
- data/lib/skiptrace/location.rb +34 -0
- data/lib/skiptrace/version.rb +3 -0
- data/skiptrace.gemspec +27 -0
- 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 +6 -4
- metadata +41 -34
- data/lib/bindex/jruby.rb +0 -5
- data/lib/bindex/jruby_internals.jar +0 -0
- data/lib/bindex/version.rb +0 -3
- 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
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2afa6fd9add9be18fcc18af31351373180952abb3b62ed5cda648fad1e8ab5e9
|
4
|
+
data.tar.gz: afbd2740d00847f74a2fbea09565680b72015af4096213fca2f5fb639d3c0f71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c8c2e671de5f1c198ef603c6c8a65a918f98601c167f0a3abdb5aa93f7951c6b44435a7ac598098b107dd4612d6684da761c8a19fabb5680eff2ca421fda1a1
|
7
|
+
data.tar.gz: 8196d2b2fbc90a8c9b2dc30eb3e8f45c8774610094487642c416dc31dda9c5f8be73b7482cdd5e8a7a475516d2627c95580cd2220614c5538c071a52f7cd1d3f
|
data/.travis.yml
CHANGED
@@ -1,17 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
- ruby-2.
|
5
|
-
- ruby-2.
|
6
|
-
- ruby-2.1.0
|
7
|
-
- ruby-2.2.6
|
8
|
-
- ruby-2.3.3
|
9
|
-
- ruby-2.4.0
|
4
|
+
- ruby-2.5
|
5
|
+
- ruby-2.6
|
10
6
|
- ruby-head
|
11
7
|
|
12
|
-
- jruby-9.1.8.0
|
13
|
-
- jruby-head
|
14
|
-
|
15
8
|
allow_failures:
|
16
9
|
- rvm: ruby-head
|
17
10
|
- rvm: jruby-head
|
@@ -22,6 +15,4 @@ env:
|
|
22
15
|
|
23
16
|
before_install: gem install bundler
|
24
17
|
|
25
|
-
sudo: false
|
26
|
-
|
27
18
|
cache: bundler
|
data/CONTRIBUTING.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Contributing
|
2
2
|
|
3
|
-
1. Fork it ( https://github.com/gsamokovarov/
|
3
|
+
1. Fork it ( https://github.com/gsamokovarov/skiptrace/fork )
|
4
4
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
5
5
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
6
6
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
#
|
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
|
-
where did the exception originated in.
|
4
|
+
where did the exception originated in. Skiptrace gives you the bindings as well.
|
5
5
|
This can help you introspect the state of the Ruby program when at the point
|
6
6
|
the exception occurred.
|
7
7
|
|
@@ -12,13 +12,18 @@ worth it anywhere outside of development.
|
|
12
12
|
|
13
13
|
### API
|
14
14
|
|
15
|
-
|
15
|
+
Skiptrace defines the following API:
|
16
16
|
|
17
17
|
#### Exception#bindings
|
18
18
|
|
19
19
|
Returns all the bindings up to the one in which the exception originated in.
|
20
20
|
|
21
|
-
####
|
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
|
+
|
26
|
+
#### Skiptrace.current_bindings
|
22
27
|
|
23
28
|
Returns all of the current Ruby execution state bindings. The first one is the
|
24
29
|
current one, the second is the caller one, the third is the caller of 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
@@ -1,9 +1,13 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
2
1
|
require 'rake/testtask'
|
2
|
+
require "rake/clean"
|
3
|
+
|
4
|
+
CLOBBER.include "pkg"
|
5
|
+
|
6
|
+
Bundler::GemHelper.install_tasks name: ENV.fetch('GEM_NAME', 'skiptrace')
|
3
7
|
|
4
8
|
Rake::TestTask.new do |t|
|
5
9
|
t.libs << 'test'
|
6
|
-
t.test_files = FileList['test
|
10
|
+
t.test_files = FileList['test/**/*_test.rb']
|
7
11
|
t.verbose = true
|
8
12
|
end
|
9
13
|
|
@@ -11,18 +15,20 @@ case RUBY_ENGINE
|
|
11
15
|
when 'ruby'
|
12
16
|
require 'rake/extensiontask'
|
13
17
|
|
14
|
-
Rake::ExtensionTask.new('
|
18
|
+
Rake::ExtensionTask.new('skiptrace') do |ext|
|
15
19
|
ext.name = 'cruby'
|
16
|
-
ext.lib_dir = 'lib/
|
20
|
+
ext.lib_dir = 'lib/skiptrace/internal'
|
17
21
|
end
|
18
22
|
|
19
23
|
task default: [:clean, :compile, :test]
|
20
24
|
when 'jruby'
|
21
25
|
require 'rake/javaextensiontask'
|
22
26
|
|
23
|
-
Rake::JavaExtensionTask.new('
|
27
|
+
Rake::JavaExtensionTask.new('skiptrace') do |ext|
|
24
28
|
ext.name = 'jruby_internals'
|
25
|
-
ext.lib_dir = 'lib/
|
29
|
+
ext.lib_dir = 'lib/skiptrace/internal'
|
30
|
+
ext.source_version = '1.8'
|
31
|
+
ext.target_version = '1.8'
|
26
32
|
end
|
27
33
|
|
28
34
|
task default: [:clean, :compile, :test]
|
data/bindex.gemspec
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
$LOAD_PATH << File.expand_path('../lib', __FILE__)
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'skiptrace/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "bindex"
|
7
|
-
spec.version =
|
7
|
+
spec.version = Skiptrace::VERSION
|
8
8
|
spec.authors = ["Genadi Samokovarov"]
|
9
9
|
spec.email = ["gsamokovarov@gmail.com"]
|
10
|
-
spec.extensions = ["ext/
|
10
|
+
spec.extensions = ["ext/skiptrace/extconf.rb"]
|
11
11
|
spec.summary = "Bindings for your Ruby exceptions"
|
12
12
|
spec.homepage = "https://github.com/gsamokovarov/bindex"
|
13
13
|
spec.license = "MIT"
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
|
-
spec.extensions = ["ext/
|
21
|
+
spec.extensions = ["ext/skiptrace/extconf.rb"]
|
22
22
|
|
23
23
|
spec.add_development_dependency "minitest", "~> 5.4"
|
24
24
|
spec.add_development_dependency "bundler"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
package com.gsamokovarov.
|
1
|
+
package com.gsamokovarov.skiptrace;
|
2
2
|
|
3
3
|
import org.jruby.Ruby;
|
4
4
|
import org.jruby.RubyArray;
|
@@ -11,8 +11,8 @@ import org.jruby.anno.JRubyMethod;
|
|
11
11
|
|
12
12
|
public class JRubyIntegration {
|
13
13
|
public static void setup(Ruby runtime) {
|
14
|
-
RubyModule
|
15
|
-
|
14
|
+
RubyModule skiptrace = runtime.defineModule("Skiptrace");
|
15
|
+
skiptrace.defineAnnotatedMethods(SkiptraceMethods.class);
|
16
16
|
|
17
17
|
RubyClass exception = runtime.getException();
|
18
18
|
exception.defineAnnotatedMethods(ExceptionExtensionMethods.class);
|
@@ -26,7 +26,7 @@ public class JRubyIntegration {
|
|
26
26
|
}
|
27
27
|
}
|
28
28
|
|
29
|
-
public static class
|
29
|
+
public static class SkiptraceMethods {
|
30
30
|
@JRubyMethod(name = "current_bindings", meta = true)
|
31
31
|
public static IRubyObject currentBindings(ThreadContext context, IRubyObject self) {
|
32
32
|
return RubyBindingsCollector.collectCurrentFor(context);
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
#include <ruby/debug.h>
|
3
3
|
|
4
|
-
VALUE
|
4
|
+
static VALUE st_mSkiptrace;
|
5
5
|
static ID id_bindings;
|
6
6
|
|
7
7
|
static VALUE
|
@@ -22,7 +22,7 @@ current_bindings_callback(const rb_debug_inspector_t *context, void *data)
|
|
22
22
|
return bindings;
|
23
23
|
}
|
24
24
|
|
25
|
-
VALUE
|
25
|
+
static VALUE
|
26
26
|
current_bindings(void)
|
27
27
|
{
|
28
28
|
return rb_debug_inspector_open(current_bindings_callback, NULL);
|
@@ -42,7 +42,7 @@ set_exception_bindings_callback(VALUE tpval, void *data)
|
|
42
42
|
}
|
43
43
|
}
|
44
44
|
|
45
|
-
void
|
45
|
+
static void
|
46
46
|
set_exception_bindings_on_raise(void)
|
47
47
|
{
|
48
48
|
VALUE tpval = rb_tracepoint_new(0, RUBY_EVENT_RAISE, set_exception_bindings_callback, 0);
|
@@ -50,13 +50,13 @@ set_exception_bindings_on_raise(void)
|
|
50
50
|
}
|
51
51
|
|
52
52
|
static VALUE
|
53
|
-
|
53
|
+
st_current_bindings(VALUE self)
|
54
54
|
{
|
55
55
|
return current_bindings();
|
56
56
|
}
|
57
57
|
|
58
58
|
static VALUE
|
59
|
-
|
59
|
+
st_exc_bindings(VALUE self)
|
60
60
|
{
|
61
61
|
VALUE bindings = rb_attr_get(self, id_bindings);
|
62
62
|
|
@@ -70,11 +70,11 @@ bx_exc_bindings(VALUE self)
|
|
70
70
|
void
|
71
71
|
Init_cruby(void)
|
72
72
|
{
|
73
|
-
|
73
|
+
st_mSkiptrace = rb_define_module("Skiptrace");
|
74
74
|
id_bindings = rb_intern("bindings");
|
75
75
|
|
76
|
-
rb_define_singleton_method(
|
77
|
-
rb_define_method(rb_eException, "bindings",
|
76
|
+
rb_define_singleton_method(st_mSkiptrace, "current_bindings", st_current_bindings, 0);
|
77
|
+
rb_define_method(rb_eException, "bindings", st_exc_bindings, 0);
|
78
78
|
|
79
79
|
set_exception_bindings_on_raise();
|
80
80
|
}
|
@@ -5,7 +5,7 @@ when "ruby"
|
|
5
5
|
$CFLAGS << " -Wall"
|
6
6
|
$CFLAGS << " -g3 -O0" if ENV["DEBUG"]
|
7
7
|
|
8
|
-
create_makefile("
|
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
|
data/lib/bindex.rb
CHANGED
@@ -1,10 +1,4 @@
|
|
1
|
-
|
2
|
-
when 'rbx'
|
3
|
-
require 'bindex/rubinius'
|
4
|
-
when 'jruby'
|
5
|
-
require 'bindex/jruby'
|
6
|
-
when 'ruby'
|
7
|
-
require 'bindex/cruby'
|
8
|
-
end
|
1
|
+
require_relative "skiptrace"
|
9
2
|
|
10
|
-
|
3
|
+
# Keep backwards compatibility with the previous name.
|
4
|
+
Bindex = Skiptrace
|
data/lib/skiptrace.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
case RUBY_ENGINE
|
2
|
+
when 'rbx'
|
3
|
+
require 'skiptrace/internal/rubinius'
|
4
|
+
when 'jruby'
|
5
|
+
require 'skiptrace/internal/jruby'
|
6
|
+
when 'ruby'
|
7
|
+
require 'skiptrace/internal/cruby'
|
8
|
+
end
|
9
|
+
|
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
|
Binary file
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Skiptrace
|
2
2
|
module Rubinius
|
3
3
|
# Filters internal Rubinius locations.
|
4
4
|
#
|
@@ -32,11 +32,11 @@ end
|
|
32
32
|
|
33
33
|
# Gets the current bindings for all available Ruby frames.
|
34
34
|
#
|
35
|
-
# Filters the internal Rubinius and
|
36
|
-
def
|
35
|
+
# Filters the internal Rubinius and Skiptrace frames.
|
36
|
+
def Skiptrace.current_bindings
|
37
37
|
locations = ::Rubinius::VM.backtrace(1, true)
|
38
38
|
|
39
|
-
|
39
|
+
Skiptrace::Rubinius::InternalLocationFilter.new(locations).filter.map do |location|
|
40
40
|
Binding.setup(
|
41
41
|
location.variables,
|
42
42
|
location.variables.method,
|
@@ -58,7 +58,7 @@ end
|
|
58
58
|
|
59
59
|
define_method(:raise_exception) do |exc|
|
60
60
|
if exc.bindings.empty?
|
61
|
-
exc.instance_variable_set(:@bindings,
|
61
|
+
exc.instance_variable_set(:@bindings, Skiptrace.current_bindings)
|
62
62
|
end
|
63
63
|
|
64
64
|
raise_exception.bind(self).call(exc)
|
@@ -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/skiptrace.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'skiptrace/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "skiptrace"
|
7
|
+
spec.version = Skiptrace::VERSION
|
8
|
+
spec.authors = ["Genadi Samokovarov"]
|
9
|
+
spec.email = ["gsamokovarov@gmail.com"]
|
10
|
+
spec.extensions = ["ext/skiptrace/extconf.rb"]
|
11
|
+
spec.summary = "Bindings for your Ruby exceptions"
|
12
|
+
spec.homepage = "https://github.com/gsamokovarov/skiptrace"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.required_ruby_version = ">= 2.5.0"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
spec.extensions = ["ext/skiptrace/extconf.rb"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "minitest", "~> 5.4"
|
24
|
+
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rake-compiler"
|
27
|
+
end
|
@@ -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
@@ -1,7 +1,7 @@
|
|
1
1
|
$LOAD_PATH << File.expand_path('../lib', __FILE__)
|
2
2
|
|
3
3
|
require 'minitest/autorun'
|
4
|
-
require '
|
4
|
+
require 'skiptrace'
|
5
5
|
|
6
6
|
current_directory = File.dirname(File.expand_path(__FILE__))
|
7
7
|
|
@@ -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,77 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bindex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genadi Samokovarov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
14
15
|
requirement: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
17
|
- - "~>"
|
17
18
|
- !ruby/object:Gem::Version
|
18
19
|
version: '5.4'
|
19
|
-
name: minitest
|
20
|
-
prerelease: false
|
21
20
|
type: :development
|
21
|
+
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
28
29
|
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
31
|
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
|
-
name: bundler
|
34
|
-
prerelease: false
|
35
34
|
type: :development
|
35
|
+
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
42
43
|
requirement: !ruby/object:Gem::Requirement
|
43
44
|
requirements:
|
44
45
|
- - ">="
|
45
46
|
- !ruby/object:Gem::Version
|
46
47
|
version: '0'
|
47
|
-
name: rake
|
48
|
-
prerelease: false
|
49
48
|
type: :development
|
49
|
+
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake-compiler
|
56
57
|
requirement: !ruby/object:Gem::Requirement
|
57
58
|
requirements:
|
58
59
|
- - ">="
|
59
60
|
- !ruby/object:Gem::Version
|
60
61
|
version: '0'
|
61
|
-
name: rake-compiler
|
62
|
-
prerelease: false
|
63
62
|
type: :development
|
63
|
+
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description:
|
70
70
|
email:
|
71
71
|
- gsamokovarov@gmail.com
|
72
72
|
executables: []
|
73
73
|
extensions:
|
74
|
-
- ext/
|
74
|
+
- ext/skiptrace/extconf.rb
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- ".gitignore"
|
@@ -82,33 +82,40 @@ files:
|
|
82
82
|
- README.md
|
83
83
|
- Rakefile
|
84
84
|
- bindex.gemspec
|
85
|
-
- ext/
|
86
|
-
- ext/
|
87
|
-
- ext/
|
88
|
-
- ext/
|
89
|
-
- ext/
|
90
|
-
- ext/
|
91
|
-
- ext/
|
92
|
-
- ext/
|
93
|
-
- ext/
|
85
|
+
- ext/skiptrace/com/gsamokovarov/skiptrace/BindingBuilder.java
|
86
|
+
- ext/skiptrace/com/gsamokovarov/skiptrace/CurrentBindingsIterator.java
|
87
|
+
- ext/skiptrace/com/gsamokovarov/skiptrace/JRubyIntegration.java
|
88
|
+
- ext/skiptrace/com/gsamokovarov/skiptrace/RubyBindingsCollector.java
|
89
|
+
- ext/skiptrace/com/gsamokovarov/skiptrace/SetExceptionBindingsEventHook.java
|
90
|
+
- ext/skiptrace/com/gsamokovarov/skiptrace/ThreadContextInterfaceException.java
|
91
|
+
- ext/skiptrace/com/gsamokovarov/skiptrace/ThreadContextInternals.java
|
92
|
+
- ext/skiptrace/cruby.c
|
93
|
+
- ext/skiptrace/extconf.rb
|
94
94
|
- lib/bindex.rb
|
95
|
-
- lib/
|
96
|
-
- lib/
|
97
|
-
- lib/
|
98
|
-
- lib/
|
99
|
-
-
|
100
|
-
-
|
95
|
+
- lib/skiptrace.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
|
103
|
+
- lib/skiptrace/version.rb
|
104
|
+
- skiptrace.gemspec
|
101
105
|
- test/fixtures/basic_nested_fixture.rb
|
102
106
|
- test/fixtures/custom_error_fixture.rb
|
103
107
|
- test/fixtures/eval_nested_fixture.rb
|
104
108
|
- test/fixtures/flat_fixture.rb
|
105
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
|
106
113
|
- test/test_helper.rb
|
107
114
|
homepage: https://github.com/gsamokovarov/bindex
|
108
115
|
licenses:
|
109
116
|
- MIT
|
110
117
|
metadata: {}
|
111
|
-
post_install_message:
|
118
|
+
post_install_message:
|
112
119
|
rdoc_options: []
|
113
120
|
require_paths:
|
114
121
|
- lib
|
@@ -123,17 +130,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
130
|
- !ruby/object:Gem::Version
|
124
131
|
version: '0'
|
125
132
|
requirements: []
|
126
|
-
|
127
|
-
|
128
|
-
signing_key:
|
133
|
+
rubygems_version: 3.0.3
|
134
|
+
signing_key:
|
129
135
|
specification_version: 4
|
130
136
|
summary: Bindings for your Ruby exceptions
|
131
137
|
test_files:
|
132
|
-
- test/current_bindings_test.rb
|
133
|
-
- test/exception_test.rb
|
134
138
|
- test/fixtures/basic_nested_fixture.rb
|
135
139
|
- test/fixtures/custom_error_fixture.rb
|
136
140
|
- test/fixtures/eval_nested_fixture.rb
|
137
141
|
- test/fixtures/flat_fixture.rb
|
138
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
|
139
146
|
- test/test_helper.rb
|
data/lib/bindex/jruby.rb
DELETED
Binary file
|
data/lib/bindex/version.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
|