summaryrefslogtreecommitdiff
path: root/test/rake/test_rake_backtrace.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-15 21:59:37 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-15 21:59:37 +0000
commit9c66bad9f3d522d50d4a45ef8a3a92abbf93229f (patch)
tree8fc1ae219e41bdd711442b1d35149da4f45dfa8a /test/rake/test_rake_backtrace.rb
parentbfc95c6e1639edc909338ef4d20d990caf6f630e (diff)
* lib/rake*: Updated to rake 0.9.3
* test/rake*: ditto * bin/rake: ditto * NEWS: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37664 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rake/test_rake_backtrace.rb')
-rw-r--r--test/rake/test_rake_backtrace.rb81
1 files changed, 81 insertions, 0 deletions
diff --git a/test/rake/test_rake_backtrace.rb b/test/rake/test_rake_backtrace.rb
new file mode 100644
index 0000000..4d84bec
--- /dev/null
+++ b/test/rake/test_rake_backtrace.rb
@@ -0,0 +1,81 @@
+require File.expand_path('../helper', __FILE__)
+require 'open3'
+
+class TestRakeBacktrace < Rake::TestCase
+ # TODO: factor out similar code in test_rake_functional.rb
+ def rake(*args)
+ lib = File.join(@orig_PWD, "lib")
+ bin_rake = File.join(@orig_PWD, "bin", "rake")
+ Open3.popen3(RUBY, "-I", lib, bin_rake, *args) { |_, _, err, _| err.read }
+ end
+
+ def invoke(task_name)
+ rake task_name.to_s
+ end
+
+ def test_single_collapse
+ rakefile %q{
+ task :foo do
+ raise "foooo!"
+ end
+ }
+
+ lines = invoke(:foo).split("\n")
+
+ 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
+ }
+
+ lines = invoke(:foo).split("\n")
+
+ 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
+ }
+
+ lines = rake("baz").split("\n")
+ assert_equal "rake aborted!", lines[0]
+ assert_equal "bazzz!", lines[1]
+ assert_something_matches %r!Rakefile!i, lines
+
+ lines = rake("--suppress-backtrace", ".ak.file", "baz").split("\n")
+ 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
+ flunk "expected #{pattern.inspect} to match something in:\n #{lines.join("\n ")}"
+ end
+
+end