Class: RakeDotNet::NCoverTask

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| ... } ⇒ NCoverTask

Returns a new instance of NCoverTask.

Yields:

  • (_self)

Yield Parameters:



767
768
769
770
771
772
773
774
775
776
777
778
779
# File 'lib/rake_dotnet.rb', line 767

def initialize(params={})
	@product_name = params[:product_name] || PRODUCT_NAME
	@bin_dir = params[:bin_dir] || File.join(OUT_DIR, 'bin')
	@report_dir = params[:report_dir] || File.join(OUT_DIR, 'reports', 'ncover')
	@deps = params[:deps] || []
	tool_defaults = {:arch => ENV['PROCESSOR_ARCHITECTURE']}
	@allow_iis_profiling = params[:allow_iis_profiling] || false
	@profile_options = tool_defaults.merge(params[:profile_options] || {})
	@reporting_options = tool_defaults.merge(params[:reporting_options] || {})

	yield self if block_given?
	define
end

Instance Attribute Details

#profile_optionsObject

Returns the value of attribute profile_options.



765
766
767
# File 'lib/rake_dotnet.rb', line 765

def profile_options
  @profile_options
end

#reporting_optionsObject

Returns the value of attribute reporting_options.



765
766
767
# File 'lib/rake_dotnet.rb', line 765

def reporting_options
  @reporting_options
end

Instance Method Details

#defineObject



781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
# File 'lib/rake_dotnet.rb', line 781

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

	directory @report_dir

	reports_dir_regex = RakeDotNet::regexify(@report_dir)
	rule(/#{reports_dir_regex}\/.*\.coverage\.xml/) do |r|
		dll_to_execute = r.name.sub(/#{@report_dir}\/(.*)\.coverage\.xml/, "#{@bin_dir}/\\1.dll")
		if (shouldProfileIis(dll_to_execute))
			@profile_options[:profile_iis] = @allow_iis_profiling
		end
		nc = NCoverConsoleCmd.new(@report_dir, dll_to_execute, @profile_options)
		nc.run
	end

	def shouldProfileIis(dll)
		dll = dll.downcase
		return true if dll.include? 'functional'
		return true if dll.include? 'browser'
		return true if dll.include? 'selenium'
		return true if dll.include? 'watin'
		return false
	end

	desc "Generate ncover coverage XML, one file per test-suite that exercises your product"
	task :ncover_profile, [:dlls_to_run] => [@report_dir] do |t, args|
		dlls_to_run_list = FileList.new
		dlls_to_run_list.include("#{@bin_dir}/**/*#{@product_name}*Tests*.dll")
		dlls_to_run_list.include("#{@bin_dir}/**/*#{@product_name}*Tests*.exe")
		args.with_defaults(:dlls_to_run => dlls_to_run_list)
		args.dlls_to_run.each do |d|
			dll_to_run = Pathname.new(d)
			cf_name = dll_to_run.basename.sub(dll_to_run.extname, '.coverage.xml')
			coverage_file = File.join(@report_dir, cf_name)
			Rake::FileTask[coverage_file].invoke
		end
	end

	rule(/#{reports_dir_regex}\/.*\//) do |report_set|
		set_name = report_set.name.match(/#{reports_dir_regex}\/(.*)\//)[1]
		profile_xml = File.join(@report_dir, "#{set_name}.coverage.xml")
		mkdir_p report_set.name
		@reporting_options[:project_name] = set_name
		ncr = NCoverReportingCmd.new(report_set.name, profile_xml, @reporting_options)
		ncr.run
	end

	desc "Generate ncover coverage report(s), on all coverage files"
	task :ncover_reports => [:ncover_profile] do
		report_sets = FileList.new("#{@report_dir}/**/*.coverage.xml")
		report_sets.each do |set|
			cov_report = set.sub('.coverage.xml', '/')
			Rake::FileTask[cov_report].invoke
		end
	end

	task :clobber_ncover do
		rm_rf @report_dir
	end

	self
end

#shouldProfileIis(dll) ⇒ Object



798
799
800
801
802
803
804
805
# File 'lib/rake_dotnet.rb', line 798

def shouldProfileIis(dll)
	dll = dll.downcase
	return true if dll.include? 'functional'
	return true if dll.include? 'browser'
	return true if dll.include? 'selenium'
	return true if dll.include? 'watin'
	return false
end