Created
February 20, 2017 11:21
-
-
Save olleolleolle/2a9ba37a0fe774bd484929c0e0f155bb to your computer and use it in GitHub Desktop.
Test script for issue 47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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