Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding support to output full descriptions when not outputting to a T…

…TY. Also fixing an exception that will be given if a task name is longer than the TTY output (due to description truncation)
  • Loading branch information...
commit fba0457be6c7d0df118f6ffbfea63574d075d284 1 parent 2d1ac84
Gavin Stark authored
Showing with 58 additions and 4 deletions.
  1. +14 −3 lib/rake.rb
  2. +44 −1 test/test_application.rb
View
17 lib/rake.rb
@@ -1877,6 +1877,7 @@ def initialize
@top_level_tasks = []
add_loader('rf', DefaultLoader.new)
add_loader('rake', DefaultLoader.new)
+ @tty_output = STDOUT.tty?
end
# Run the Rake application. The run method performs the following three steps:
@@ -1991,6 +1992,16 @@ def have_rakefile
return false
end
+ # True if we are outputting to TTY, false otherwise
+ def tty_output?
+ @tty_output
+ end
+
+ # Override the detected TTY output state (mostly for testing)
+ def tty_output=( tty_output_state )
+ @tty_output = tty_output_state
+ end
+
# Display the tasks and dependencies.
def display_tasks_and_comments
displayable_tasks = tasks.select { |t|
@@ -2006,10 +2017,10 @@ def display_tasks_and_comments
end
else
width = displayable_tasks.collect { |t| t.name_with_args.length }.max || 10
- max_column = terminal_width - name.size - width - 7
+ max_column = tty_output? ? terminal_width - name.size - width - 7 : nil
displayable_tasks.each do |t|
printf "#{name} %-#{width}s # %s\n",
- t.name_with_args, truncate(t.comment, max_column)
+ t.name_with_args, max_column ? truncate(t.comment, max_column) : t.comment
end
end
end
@@ -2046,7 +2057,7 @@ def truncate(string, width)
if string.length <= width
string
else
- string[0, width-3] + "..."
+ ( string[0, width-3] || "" ) + "..."
end
end
View
45 test/test_application.rb
@@ -41,7 +41,7 @@ def test_display_tasks
def test_display_tasks_with_long_comments
ENV['RAKE_COLUMNS'] = '80'
@app.options.show_task_pattern = //
- @app.last_description = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
+ @app.last_description = "1234567890" * 8
@app.define_task(Rake::Task, "t")
out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
assert_match(/^rake t/, out)
@@ -50,6 +50,49 @@ def test_display_tasks_with_long_comments
ENV['RAKE_COLUMNS'] = nil
end
+ def test_display_tasks_with_task_name_wider_than_tty_display
+ ENV['RAKE_COLUMNS'] = '80'
+ @app.options.show_task_pattern = //
+ description = "something short"
+ task_name = "task name" * 80
+ @app.last_description = "something short"
+ @app.define_task(Rake::Task, task_name )
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
+ # Ensure the entire task name is output and we end up showing no description
+ assert_match(/rake #{task_name} # .../, out)
+ ensure
+ ENV['RAKE_COLUMNS'] = nil
+ end
+
+ def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comment
+
+ ENV['RAKE_COLUMNS'] = '80'
+ @app.options.show_task_pattern = //
+ @app.tty_output = false
+ description = "something short"
+ task_name = "task name" * 80
+ @app.last_description = "something short"
+ @app.define_task(Rake::Task, task_name )
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
+ # Ensure the entire task name is output and we end up showing no description
+ assert_match(/rake #{task_name} # #{description}/, out)
+ ensure
+ ENV['RAKE_COLUMNS'] = nil
+ end
+
+ def test_display_tasks_with_long_comments_to_a_non_tty_shows_entire_comment
+ ENV['RAKE_COLUMNS'] = '80'
+ @app.options.show_task_pattern = //
+ @app.tty_output = false
+ @app.last_description = "1234567890" * 8
+ @app.define_task(Rake::Task, "t")
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
+ assert_match(/^rake t/, out)
+ assert_match(/# #{@app.last_description}/, out)
+ ensure
+ ENV['RAKE_COLUMNS'] = nil
+ end
+
def test_display_tasks_with_full_descriptions
@app.options.show_task_pattern = //
@app.options.full_description = true
Please sign in to comment.
Something went wrong with that request. Please try again.