2012-11-15 16:59:37 -05:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
|
|
|
require 'open3'
|
|
|
|
|
2013-10-11 17:35:01 -04:00
|
|
|
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
|
|
|
|
|
2012-11-15 16:59:37 -05:00
|
|
|
class TestRakeBacktrace < Rake::TestCase
|
2013-10-11 17:35:01 -04:00
|
|
|
include RubyRunner
|
2012-11-29 22:21:06 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
skip 'tmpdir is suppressed in backtrace' if
|
|
|
|
Dir.pwd =~ Rake::Backtrace::SUPPRESS_PATTERN
|
|
|
|
end
|
|
|
|
|
2013-10-11 17:35:01 -04:00
|
|
|
def invoke(*args)
|
|
|
|
rake(*args)
|
|
|
|
@err
|
2012-11-15 16:59:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_single_collapse
|
|
|
|
rakefile %q{
|
|
|
|
task :foo do
|
|
|
|
raise "foooo!"
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:35:01 -04:00
|
|
|
lines = invoke("foo").split("\n")
|
2012-11-15 16:59:37 -05:00
|
|
|
|
|
|
|
assert_equal "rake aborted!", lines[0]
|
|
|
|
assert_equal "foooo!", lines[1]
|
|
|
|
assert_something_matches %r!\A#{Regexp.quote Dir.pwd}/Rakefile:3!i, lines
|
|
|
|
assert_something_matches %r!\ATasks:!, lines
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_multi_collapse
|
|
|
|
rakefile %q{
|
|
|
|
task :foo do
|
|
|
|
Rake.application.invoke_task(:bar)
|
|
|
|
end
|
|
|
|
task :bar do
|
|
|
|
raise "barrr!"
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:35:01 -04:00
|
|
|
lines = invoke("foo").split("\n")
|
2012-11-15 16:59:37 -05:00
|
|
|
|
|
|
|
assert_equal "rake aborted!", lines[0]
|
|
|
|
assert_equal "barrr!", lines[1]
|
|
|
|
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
|
|
|
|
rakefile %q{
|
|
|
|
task :baz do
|
|
|
|
raise "bazzz!"
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:35:01 -04:00
|
|
|
lines = invoke("baz").split("\n")
|
2012-11-15 16:59:37 -05:00
|
|
|
assert_equal "rake aborted!", lines[0]
|
|
|
|
assert_equal "bazzz!", lines[1]
|
|
|
|
assert_something_matches %r!Rakefile!i, lines
|
|
|
|
|
2013-10-11 17:35:01 -04:00
|
|
|
lines = invoke("--suppress-backtrace", ".ak.file", "baz").split("\n")
|
2012-11-15 16:59:37 -05:00
|
|
|
assert_equal "rake aborted!", lines[0]
|
|
|
|
assert_equal "bazzz!", lines[1]
|
|
|
|
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
|
2013-10-11 17:35:01 -04:00
|
|
|
flunk "expected #{pattern.inspect} to match something in:\n" +
|
|
|
|
"#{lines.join("\n ")}"
|
2012-11-15 16:59:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|