Class: RakeDotNet::XUnitTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/rake_dotnet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) {|_self| ... } ⇒ XUnitTask

:yield: self

Yields:

  • (_self)

Yield Parameters:



1223
1224
1225
1226
1227
1228
1229
1230
1231
# File 'lib/rake_dotnet.rb', line 1223

def initialize(params={}) # :yield: self

  @suites_dir = params[:suites_dir] || File.join(OUT_DIR, 'bin')
  @reports_dir = params[:reports_dir] || File.join(OUT_DIR, 'reports', 'tests')
  @options = params[:options] || {}
  @deps = params[:deps] || []

  yield self if block_given?
  define
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



1221
1222
1223
# File 'lib/rake_dotnet.rb', line 1221

def options
  @options
end

#reports_dirObject

Returns the value of attribute reports_dir.



1221
1222
1223
# File 'lib/rake_dotnet.rb', line 1221

def reports_dir
  @reports_dir
end

#suites_dirObject

Returns the value of attribute suites_dir.



1221
1222
1223
# File 'lib/rake_dotnet.rb', line 1221

def suites_dir
  @suites_dir
end

Instance Method Details

#defineObject

Create the tasks defined by this task lib.



1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
# File 'lib/rake_dotnet.rb', line 1234

def define
  @deps.each do |d|
    task :xunit => d
  end

  rule(/#{@reports_dir}\/.*Tests.*\//) do |r|
    suite = r.name.match(/.*\/(.*Tests)\//)[1]
    run(suite)
  end

  rule(/xt-.*Tests.*/) do |r|
    suite = r.name.match(/xunit-(.*Tests)/)[1]
    run(suite)
  end

  def run(suite)
    tests_dll = File.join(@suites_dir, suite + '.dll')
    out_dir = File.join(@reports_dir, suite)
    unless File.exist?(out_dir) && uptodate?(tests_dll, out_dir)
      mkdir_p(out_dir) unless File.exist?(out_dir)
      x = XUnitConsoleCmd.new(tests_dll, out_dir, nil, options=@options)
      x.run
    end
  end
  directory @reports_dir

  desc "Generate test reports (which ones, depends on the content of XUNIT_OPTS) inside of each directory specified, where each directory matches a test-suite name (give relative paths) (otherwise, all matching #{@suites_dir}/*Tests.*.dll) and write reports to #{@reports_dir}"
  task :xunit, [:reports] => [@reports_dir] do |t, args|
    reports_list = FileList.new("#{@suites_dir}/**/*Tests*.dll").pathmap("#{@reports_dir}/%n/")
    args.with_defaults(:reports => reports_list)
    args.reports.each do |r|
      Rake::FileTask[r].invoke
    end
  end

  task :xunit_clobber do
    rm_rf(@reports_dir)
  end

  self
end

#run(suite) ⇒ Object



1249
1250
1251
1252
1253
1254
1255
1256
1257
# File 'lib/rake_dotnet.rb', line 1249

def run(suite)
  tests_dll = File.join(@suites_dir, suite + '.dll')
  out_dir = File.join(@reports_dir, suite)
  unless File.exist?(out_dir) && uptodate?(tests_dll, out_dir)
    mkdir_p(out_dir) unless File.exist?(out_dir)
    x = XUnitConsoleCmd.new(tests_dll, out_dir, nil, options=@options)
    x.run
  end
end