Skip to content

Instantly share code, notes, and snippets.

@mikeobrien
Created June 30, 2011 04:18
Show Gist options
  • Save mikeobrien/1055632 to your computer and use it in GitHub Desktop.
Save mikeobrien/1055632 to your computer and use it in GitHub Desktop.
Gallio Rake Task
class Gallio
attr_accessor :verbosity, :noResults, :noProgress, :noLogo, :doNotRun,
:ignoreAnnotations, :runtimeLimit, :runnerType, :runnerExtensions,
:runnerProperties, :filter, :reportDirectory, :reportNameFormat,
:reportArchive, :reportTypes, :reportFormatterProperties, :showReports,
:testAssemblies, :hintDirectories, :pluginDirectories, :applicationBaseDirectory,
:workingDirectory, :shadowCopy, :debug, :runtimeVersion, :echoCommandLine
def initialize()
@testAssemblies = Array.new
@hintDirectories = Array.new
@pluginDirectories = Array.new
@runtimeLimit = -1
@runnerExtensions = Array.new
@runnerProperties = Array.new
@reportTypes = Array.new
@reportFormatterProperties = Array.new
end
def addTestAssembly(assembly)
testAssemblies.push(assembly)
end
def addHintDirectory(directory)
hintDirectories.push(directory)
end
def addPluginDirectory(directory)
pluginDirectories.push(directory)
end
def addRunnerExtension(extension)
runnerExtensions.push(extension)
end
def addRunnerProperty(property)
runnerProperties.push(property)
end
def addReportType(type)
reportTypes.push(type)
end
def addReportFormatterProperty(property)
reportFormatterProperties.push(property)
end
def run()
gallio = "gallio.echo "
if testAssemblies.count > 0 then gallio += "#{testAssemblies.collect{|x| "\"#{x}\"" }.join(" ")} " end
if hintDirectories.count > 0 then gallio += "#{hintDirectories.collect{|x| "\"/hd:#{x}\"" }.join(" ")} " end
if pluginDirectories.count > 0 then gallio += "#{pluginDirectories.collect{|x| "\"/pd:#{x}\"" }.join(" ")} " end
if applicationBaseDirectory != nil then gallio += "\"/abd:#{applicationBaseDirectory}\" " end
if workingDirectory != nil then gallio += "\"/wd:#{workingDirectory}\" " end
if shadowCopy == true then gallio += "/sc " end
if debug == true then gallio += "/d " end
if runtimeVersion != nil then gallio += "\"/rv:#{runtimeVersion}\" " end
# Quiet, Normal, Verbose, Debug
if verbosity != nil then gallio += "/v:#{verbosity} " end
if noResults == true then gallio += "/ne " end
if noProgress == true then gallio += "/np " end
if noLogo == true then gallio += "/nl " end
if doNotRun == true then gallio += "/dnr " end
if ignoreAnnotations == true then gallio += "/ia " end
if runtimeLimit > -1 then gallio += "/rtl:#{runtimeLimit} " end
# IsolatedProcess, IsolatedAppDomain, Local
if runnerType != nil then gallio += "/r:#{runnerType} " end
if runnerExtensions.count > 0 then gallio += "#{runnerExtensions.collect{|x| "\"/re:#{x}\"" }.join(" ")} " end
if runnerProperties.count > 0 then gallio += "#{runnerProperties.collect{|x| "\"/rp:#{x}\"" }.join(" ")} " end
if filter != nil then gallio += "\"/f:#{filter}\" " end
if reportDirectory != nil then gallio += "\"/rd:#{reportDirectory}\" " end
if reportNameFormat != nil then gallio += "\"/rnf:#{reportNameFormat}\" " end
if reportArchive != nil then gallio += "/ra:#{reportArchive} " end
# Xml, Xml-Inline, Text, Text-Condensed, Html, Html-Condensed, XHtml, XHtml-Condensed, MHtml, MHtml-Condensed
if reportTypes.count > 0 then gallio += "#{reportTypes.collect{|x| "/rt:#{x}" }.join(" ")} " end
if reportFormatterProperties.count > 0 then gallio += "#{reportFormatterProperties.collect{|x| "\"/rfp:#{x}\"" }.join(" ")} " end
if showReports == true then gallio += "/sr " end
errorHandler = \
lambda do |ok, res|
raise "Gallio failed with exit " \
"code #{res.exitstatus}." \
if res.exitstatus > 0
end
if echoCommandLine = true then puts gallio end
sh gallio, &errorHandler
end
end
def gallio(*args, &block)
body = lambda { |*args|
rc = Gallio.new
block.call(rc)
rc.run
}
Rake::Task.define_task(*args, &body)
end
require "./gallio"
task :default => [:gallio]
desc "Gallio"
gallio :gallio do |o|
o.addTestAssembly("SomeTests.dll")
o.addHintDirectory("d:\\folder1")
o.addPluginDirectory("d:\\somefolder")
o.applicationBaseDirectory = "d:\\basedirectory"
o.workingDirectory = "d:\\working directory"
o.shadowCopy = true
o.debug = true
o.runtimeVersion = "v2.0.50727"
# http://www.gallio.org/wiki/doku.php?id=tools:gallio_logging_-_verbosity
# Quiet, Normal, Verbose, Debug
o.verbosity = "Normal"
o.noResults = true
o.noProgress = true
o.noLogo = true
o.doNotRun = true
o.ignoreAnnotations = true
o.runtimeLimit = 50
# http://www.gallio.org/wiki/doku.php?id=tools:gallio_test_runners
# IsolatedProcess, IsolatedAppDomain, Local
o.runnerType = "IsolatedAppDomain"
o.addRunnerExtension("SomeExtension,SomeExtensions.dll;Param1,Param2")
o.addRunnerProperty("SomeArgument='/name Gallio'")
# http://www.gallio.org/wiki/doku.php?id=tools:gallio_test_selection_filters
# Id, Name, Assembly, Namespace, Type, ExactType, Member
o.filter = "Namespace: /MyApp.Tests.Unit.*/"
o.reportDirectory = "d:\\reports"
o.reportNameFormat = "test-report-{0}-{1}"
o.reportArchive = "zip" # normal, zip
# http://www.gallio.org/wiki/doku.php?id=tools:gallio_report_types
# Xml, Xml-Inline, Text, Text-Condensed, Html, Html-Condensed, XHtml, XHtml-Condensed, MHtml, MHtml-Condensed
o.addReportType("Html")
o.addReportFormatterProperty("key1=value1")
o.showReports = true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment