Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug: Reenabled task raises previous exception on second invokation #271

Merged
merged 2 commits into from Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rake/task.rb
Expand Up @@ -141,7 +141,8 @@ def arg_names
# Reenable the task, allowing its tasks to be executed if the task
# is invoked again.
def reenable
@already_invoked = false
@already_invoked = false
Copy link
Member

Choose a reason for hiding this comment

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

I’m not super opinionated about this change, but this would slightly mess up git blame and sometimes it may be more annoying than just looking nice.

@invocation_exception = nil
end

# Clear the existing prerequisites, actions, comments, and arguments of a rake task.
Expand Down
27 changes: 27 additions & 0 deletions test/test_rake_task.rb
Expand Up @@ -117,6 +117,33 @@ def test_can_double_invoke_with_reenable
assert_equal ["t1", "t1"], runlist
end

def test_can_triple_invoke_after_exception_with_reenable
raise_exception = true
invoked = 0

t1 = task(:t1) do |t|
invoked += 1
next if !raise_exception

raise_exception = false
raise 'Some error'
end

assert_raises(RuntimeError) { t1.invoke }
assert_equal 1, invoked

t1.reenable

# actually invoke second time
t1.invoke
assert_equal 2, invoked

# recognize already invoked and
# don't raise pre-reenable exception
t1.invoke
assert_equal 2, invoked
end

def test_clear
desc "a task"
t = task("t", ["b"] => "a") {}
Expand Down