Skip to content

Commit

Permalink
fix backtrace suppression for rubinius
Browse files Browse the repository at this point in the history
  • Loading branch information
jimweirich committed Nov 9, 2012
1 parent de88a99 commit 7c841a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/rake/backtrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ module Backtrace
keys.grep(/(prefix|libdir)/)) + [
File.join(File.dirname(__FILE__), ".."),
].map { |f| Regexp.quote(File.expand_path(f)) }
SUPPRESSED_PATHS.reject! { |s| s.nil? || s =~ /^ *$/ }

SUPPRESS_PATTERN = %r!(\A#{SUPPRESSED_PATHS.join('|')}|bin/rake:\d+)!
SUPPRESS_PATTERN = %r!(\A#{SUPPRESSED_PATHS.join('|')}|bin/rake:\d+)!i

def self.collapse(backtrace)
pattern = Rake.application.options.suppress_backtrace_pattern ||
Expand Down
1 change: 0 additions & 1 deletion test/test_rake_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,3 @@ def loader.make_dummy
end

end

30 changes: 22 additions & 8 deletions test/test_rake_backtrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def test_single_collapse

assert_equal "rake aborted!", lines[0]
assert_equal "foooo!", lines[1]
assert_match %r!\A#{Regexp.quote Dir.pwd}/Rakefile:3!, lines[2]
assert_match %r!\ATasks:!, lines[3]
assert_something_matches %r!\A#{Regexp.quote Dir.pwd}/Rakefile:3!i, lines
assert_something_matches %r!\ATasks:!, lines
end

def test_multi_collapse
Expand All @@ -42,9 +42,9 @@ def test_multi_collapse

assert_equal "rake aborted!", lines[0]
assert_equal "barrr!", lines[1]
assert_match %r!\A#{Regexp.quote Dir.pwd}/Rakefile:6!, lines[2]
assert_match %r!\A#{Regexp.quote Dir.pwd}/Rakefile:3!, lines[3]
assert_match %r!\ATasks:!, lines[4]
assert_something_matches %r!\A#{Regexp.quote Dir.pwd}/Rakefile:6!i, lines
assert_something_matches %r!\A#{Regexp.quote Dir.pwd}/Rakefile:3!i, lines
assert_something_matches %r!\ATasks:!, lines
end

def test_suppress_option
Expand All @@ -57,11 +57,25 @@ def test_suppress_option
lines = rake("baz").split("\n")
assert_equal "rake aborted!", lines[0]
assert_equal "bazzz!", lines[1]
assert_match %r!Rakefile!, lines[2]
assert_something_matches %r!Rakefile!i, lines

lines = rake("--suppress-backtrace", "R.k.file", "baz").split("\n")
lines = rake("--suppress-backtrace", ".ak.file", "baz").split("\n")
assert_equal "rake aborted!", lines[0]
assert_equal "bazzz!", lines[1]
refute_match %r!Rakefile!, lines[2]
refute_match %r!Rakefile!i, lines[2]
end

private

# Assert that the pattern matches at least one line in +lines+.
def assert_something_matches(pattern, lines)
lines.each do |ln|
if pattern =~ ln
assert_match pattern, ln
return
end
end
flunk "expected #{pattern.inspect} to match something in:\n #{lines.join("\n ")}"
end

end

0 comments on commit 7c841a3

Please sign in to comment.