support "next" calls in tasks
from Mike Nichols, via the albacoredev list:
My understanding is doing a 'break' or 'next' within a rake task is effectively and early return. This is handy in case an environment parameter should keep the task from executing but it is invoked through a :needs arg (dependency).
Albacore tasks aren't abiding by this, though and execute the task anyways, throwing in the event of missing properties.
An example is if ENV["run_tests"] is nil, then the tests should not be executed, so:
xunit :my_test_task do
if !ENV["run_tests] then
next
end
#xunit setup stuff here
end
I recognize I can call Rake:Task["my_test:task"].invoke but would prefer avoiding this.
The following does work, but the outcome is not ideal.
# in your Rake setup...
RUN_TESTS = ENV['run_tests'] || 'true'
nunit :test do |nunit|
nunit.command = NUNIT_PATH
next unless RUN_TESTS == 'true'
nunit.assemblies << TEST_PROJECT
end
You end up with an NUnit error (no assigned assemblies). This isn't ideal, because it gets interpreted as an NUnit failure, instead of a skip.
NUnit version 2.5.7.10213
Copyright (C) 2002-2009 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.
Runtime Environment -
OS Version: Microsoft Windows NT 6.1.7600.0
CLR Version: 2.0.50727.4952 ( Net 2.0 )
fatal error: no inputs specified
that's why this ticket has never been tackled... any time you call next from an albacore task definition, this happens.
is there a need for something like this? do we need to support the ability to cancel a task, or prevent it from executing?
When put that way, I don't see why we need this. It's Rake. I can just as easily make task definition like this and get the exact same thing.
task :build_notest => [:clean, :compile]
task :build => [:build_notest, :test]
I have a similar issue. I have a bunch of tests that are integration tests with external APIs. I want this to run at specific times (just at night). These tests have been marked with a certain category, so these tests are by default excluded.
I was then hoping to have an optional parameter to include certain test categories.
With nUnit, you can't have both include and exclude options. And a separate nUnit task would fail if the optional parameter wasn't passed in.
It felt like I wanted to do:
nunit :runSpecificIntegrationTestCategories do |nunit|
patterns = []
INTEGRATION_TEST_LIB_PATTERNS.each { |p| patterns.push "#{env_buildfolderpath}/Binaries/" + p }
tests = FileList[patterns]
if tests.count == 0
next
end
end