Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/rake/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def initialize
@loaders = {}
@default_loader = Rake::DefaultLoader.new
@original_dir = Dir.pwd
@running = false
@top_level_tasks = []
add_loader("rb", DefaultLoader.new)
add_loader("rf", DefaultLoader.new)
Expand All @@ -77,11 +78,13 @@ def initialize
# +init+ on your application. Then define any tasks. Finally,
# call +top_level+ to run your top level tasks.
def run(argv = ARGV)
@running = true
standard_exception_handling do
init "rake", argv
load_rakefile
top_level
end
@running = false
Copy link
Member

@yuki24 yuki24 Dec 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be wrapped with an ensure block:

def run(...)
  ..
ensure
  @running = false
end

end

# Initialize the command line parameters and app name.
Expand Down Expand Up @@ -151,6 +154,12 @@ def thread_pool # :nodoc:
@thread_pool ||= ThreadPool.new(options.thread_pool_size || Rake.suggested_thread_count-1)
end

# Is true, if the Rake application is currently running
# (in other words, that the +rake+ command line script was invoked)
def running?
@running
end

# internal ----------------------------------------------------------------

# Invokes a task with arguments that are extracted from +task_string+
Expand Down
18 changes: 18 additions & 0 deletions test/test_rake_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,22 @@ def loader.make_dummy
loader
end

def test_running
was_running = false

@app.instance_eval do
app = self
intern(Rake::Task, "default").enhance do
was_running = app.running?
end
end

rakefile_default

assert [email protected]?
@app.run %w[--rakelib=""]
assert [email protected]?
assert was_running
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test case where the task execution fails but it correctly sets @running back to false after failure?

end