I'm bumping into unpredictable behaviour related to the call chain handling. It seems invoke_with_call_chain doesn't restore the call chain correctly after calling invoke. Since this is in the core of buildr I wanted to just check with you guys before creating an issue in jira.

invoke_with_call_chain currently does
begin
old_chain, Thread.current[:rake_chain] = Thread.current[:rake_chain], new_chain
  execute(task_args) if needed?
ensure
  Thread.current[:rake_chain] = nil
end

The ensure block seems obviously incorrect. Shouldn't this be Thread.current[:rake_chain] = old_chain?

The following spec shows when this causes things to go wrong:
describe Buildr do
  it 'should restore call chain when invoke is called' do
    task1 = Rake::Task.define_task('task1') do
    end

    task2 = Rake::Task.define_task('task2') do
      chain1 = Thread.current[:rake_chain]
      task1.invoke
      chain2 = Thread.current[:rake_chain]
      chain2.should == chain1
    end

    task2.invoke
  end
end

So is this an issue or intentional?

Regards,

Pepijn

Reply via email to