Skip to content

Instantly share code, notes, and snippets.

@olleolleolle
Created February 20, 2017 11:21
Show Gist options
  • Select an option

  • Save olleolleolle/2a9ba37a0fe774bd484929c0e0f155bb to your computer and use it in GitHub Desktop.

Select an option

Save olleolleolle/2a9ba37a0fe774bd484929c0e0f155bb to your computer and use it in GitHub Desktop.
Test script for issue 47
#!/usr/bin/env ruby -w
# Implementation
BACKTRACE_REGEX = /^(.+?):(\d+)(?::in `(.+?)')?$/.freeze
def strip_load_path path
prefix = $:
.map(&:to_s)
.select { |s| path.start_with?(s) }
.sort_by { |s| s.length }
.last
return path unless prefix
path[prefix.chomp(File::SEPARATOR).length + 1..-1]
end
# Test scaffolding
def make_java_exception
require 'java'
java_import 'java.lang.ClassNotFoundException'
java::lang::Class.forName("foo.Bar")
rescue ClassNotFoundException => e
e
end
# Using it
ex = make_java_exception
ex.backtrace.reverse.map {|line|
_, abs_path, lineno, function = line.match(BACKTRACE_REGEX).to_a
filename = strip_load_path(abs_path)
}
puts 'Passed the test.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment