Skip to content

Commit

Permalink
Fix backslash replacement on suppressed backtrace patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimweirich committed Apr 26, 2013
1 parent b77ca0f commit 301216a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/rake/backtrace.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module Rake
module Backtrace
SUPPRESSED_PATHS =
RbConfig::CONFIG.values_at(*RbConfig::CONFIG.
keys.grep(/(prefix|libdir)/)).uniq + [
File.join(File.dirname(__FILE__), ".."),
].map { |f| Regexp.quote(File.expand_path(f)) }
SUPPRESSED_PATHS.map! { |s| s.gsub("\\", "/") }
SUPPRESSED_PATHS.reject! { |s| s.nil? || s =~ /^ *$/ }
SYS_KEYS = RbConfig::CONFIG.keys.grep(/(prefix|libdir)/)
SYS_PATHS = RbConfig::CONFIG.values_at(*SYS_KEYS).uniq +
[ File.join(File.dirname(__FILE__), "..") ]

SUPPRESS_PATTERN = %r!(\A#{SUPPRESSED_PATHS.join('|')}|bin/rake:\d+)!i
SUPPRESSED_PATHS = SYS_PATHS.
map { |s| s.gsub("\\", "/") }.
map { |f| File.expand_path(f) }.
reject { |s| s.nil? || s =~ /^ *$/ }
SUPPRESSED_PATHS_RE = SUPPRESSED_PATHS.map { |f| Regexp.quote(f) }.join("|")
SUPPRESS_PATTERN = %r!(\A(#{SUPPRESSED_PATHS_RE})|bin/rake:\d+)!i

def self.collapse(backtrace)
pattern = Rake.application.options.suppress_backtrace_pattern ||
Expand Down
28 changes: 28 additions & 0 deletions test/test_rake_backtrace.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
require File.expand_path('../helper', __FILE__)
require 'open3'

class TestBacktraceSuppression < Rake::TestCase
def test_bin_rake_suppressed
paths = ["something/bin/rake:12"]

actual = Rake::Backtrace.collapse(paths)

assert_equal [], actual
end

def test_system_dir_suppressed
path = RbConfig::CONFIG['rubylibprefix']
paths = [path + ":12"]

actual = Rake::Backtrace.collapse(paths)

assert_equal [], actual
end

def test_near_system_dir_isnt_suppressed
path = RbConfig::CONFIG['rubylibprefix']
paths = [" " + path + ":12"]

actual = Rake::Backtrace.collapse(paths)

assert_equal paths, actual
end
end

class TestRakeBacktrace < Rake::TestCase

def setup
Expand Down

0 comments on commit 301216a

Please sign in to comment.