Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add specific trace testing.

  • Loading branch information...
commit 1bf04e191173caa5ca142a67af5799310b6f5aa6 1 parent 24fb9f3
@jimweirich authored
Showing with 52 additions and 17 deletions.
  1. +7 −13 lib/rake/application.rb
  2. +45 −4 test/test_rake_application.rb
View
20 lib/rake/application.rb
@@ -176,7 +176,7 @@ def display_error_message(ex)
if options.backtrace
trace ex.backtrace.join("\n")
else
- trace Backtrace.collapse(ex.backtrace)
+ trace Backtrace.collapse(ex.backtrace).join("\n")
end
trace "Tasks: #{ex.chain}" if has_chain?(ex)
trace "(See full trace by running task with --trace)" unless options.backtrace
@@ -314,21 +314,15 @@ def display_prerequisites
end
end
- def trace(*str)
+ def trace(*strings)
options.trace_output ||= $stderr
-
- # use the same semantics as puts, but use print and append a CR to the end to
- # make sure the entire string is output as a single unit.
- sep = ($\||"\n")
- if str.empty?
- options.trace_output.print sep
+ sep = $\ || "\n"
+ if strings.empty?
+ output = sep
else
- msgs = str.flatten.collect do |m|
- next m + sep if m.is_a?(String) && !m.end_with?("\n")
- m
- end
- options.trace_output.print(*msgs)
+ output = strings.map { |s| s.end_with?(sep) ? s : s + sep }.join
end
+ options.trace_output.print(output)
end
def sort_options(options)
View
49 test/test_rake_application.rb
@@ -1,4 +1,5 @@
require File.expand_path('../helper', __FILE__)
+require 'stringio'
class TestRakeApplication < Rake::TestCase
@@ -340,6 +341,46 @@ def test_handle_options_trace_does_not_eat_following_task_names
assert @app.options.trace
end
+ class PrintSpy
+ attr_reader :result, :calls
+ def initialize
+ @result = ""
+ @calls = 0
+ end
+ def print(string)
+ @result << string
+ @calls += 1
+ end
+ end
+
+ def test_trace_issues_single_io_for_args_with_empty_args
+ spy = PrintSpy.new
+ @app.options.trace_output = spy
+ @app.trace
+ assert_equal "\n", spy.result
+ assert_equal 1, spy.calls
+ end
+
+ def test_trace_issues_single_io_for_args_multiple_strings
+ spy = PrintSpy.new
+ @app.options.trace_output = spy
+ @app.trace("HI\n", "LO")
+ assert_equal "HI\nLO\n", spy.result
+ assert_equal 1, spy.calls
+ end
+
+ def test_trace_issues_single_io_for_args_multiple_strings_and_alternate_sep
+ old_sep = $\
+ $\ = "\r"
+ spy = PrintSpy.new
+ @app.options.trace_output = spy
+ @app.trace("HI\r", "LO")
+ assert_equal "HI\rLO\r", spy.result
+ assert_equal 1, spy.calls
+ ensure
+ $\ = old_sep
+ end
+
def test_trace_output_does_not_combine_messages_on_a_single_line
assert !@app.options.trace
@app.options.trace = true
@@ -357,13 +398,13 @@ def write (*args)
@app.options.trace_output = output
assert_equal output, @app.options.trace_output
-
+
(1..100).to_a.each do |i|
task i.to_s do
end
multitask :doit => i.to_s
end
-
+
# invoke all tasks simultaneously, if it behaves exactly
# like #puts, the trace will write a message and then before
# it writes the \n, another thread will
@@ -372,9 +413,9 @@ def write (*args)
# ** Execute 56** Execute 72 << We regex for number followed by **
#
# ** Execute 74
-
+
Rake::Task[:doit].invoke
-
+
refute( /[\d]+\*\*/ =~ output.string, "trace does not write single, atomic lines!")
end
Please sign in to comment.
Something went wrong with that request. Please try again.