-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
112 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
module Rake | ||
|
||
## | ||
# A TaskAction represents each action of a task. | ||
# | ||
class TaskAction | ||
attr_reader :results | ||
|
||
def initialize(&block) | ||
@block = block | ||
@results = [] | ||
end | ||
|
||
def call(argc, argv, opts) | ||
results << call_block(argc, argv, opts) | ||
rescue => error | ||
results << error | ||
raise error | ||
end | ||
|
||
private | ||
|
||
def call_block(argc, argv, opts) | ||
if opts && !opts.empty? | ||
@block.call(argc, argv, **opts) | ||
else | ||
@block.call(argc, argv) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path("../helper", __FILE__) | ||
|
||
class TestRakeTaskArgumentParsing < Rake::TestCase # :nodoc: | ||
def setup | ||
super | ||
|
||
@app = Rake::Application.new | ||
end | ||
|
||
def test_results_with_a_simple_task_and_a_single_invocation | ||
task = Rake::Task.new("simple", @app) | ||
|
||
task.enhance(nil) { "result" } | ||
task.invoke | ||
|
||
assert_equal ["result"], task.results | ||
end | ||
|
||
def test_results_with_a_simple_task_and_multiple_invocations | ||
task = Rake::Task.new("simple", @app) | ||
|
||
task.enhance(nil) { "result" } | ||
task.invoke | ||
task.reenable | ||
task.invoke | ||
|
||
assert_equal ["result", "result"], task.results | ||
end | ||
|
||
def test_results_with_a_composite_task_and_a_single_invocation | ||
task = Rake::Task.new("composite", @app) | ||
|
||
task.enhance(nil) { "result1" } | ||
task.enhance(nil) { "result2" } | ||
task.invoke | ||
|
||
assert_equal ["result1", "result2"], task.results | ||
end | ||
|
||
def test_results_with_a_composite_task_and_multiple_invocations | ||
task = Rake::Task.new("composite", @app) | ||
|
||
task.enhance(nil) { "result1" } | ||
task.enhance(nil) { "result2" } | ||
|
||
task.invoke | ||
task.reenable | ||
task.invoke | ||
|
||
assert_equal ["result1", "result1", "result2", "result2"], task.results | ||
end | ||
|
||
def test_results_with_an_empty_task | ||
task = Rake::Task.new("empty", @app) | ||
task.invoke | ||
|
||
assert task.results.empty? | ||
end | ||
|
||
def test_results_with_a_composite_task_and_no_invocations | ||
task = Rake::Task.new("composite", @app) | ||
|
||
task.enhance(nil) { "result1" } | ||
task.enhance(nil) { "result2" } | ||
|
||
assert task.results.empty? | ||
end | ||
end |