Class: Autobuild::TestUtility
- Defined in:
- lib/autobuild/test_utility.rb
Overview
Control of the test facility for a package
Instance Attribute Summary collapse
-
#coverage_enabled ⇒ Object
writeonly
Controls whether code coverage should be measured.
-
#coverage_source_dir ⇒ String
The full path to the coverage information.
-
#coverage_target_dir ⇒ String
Where the coverage information should be installed.
Attributes inherited from Utility
#available, #enabled, #name, #no_results, #package, #source_dir, #source_ref_dir, #target_dir
Class Method Summary collapse
-
.coverage_enabled=(flag) ⇒ Object
Enable code coverage for all tests.
-
.coverage_enabled? ⇒ Boolean
Whether coverage is enabled for all tests.
Instance Method Summary collapse
- #coverage_available? ⇒ Boolean
-
#coverage_enabled? ⇒ Boolean
Whether code coverage should be generated for these tests.
-
#initialize(name, package, install_on_error: true) ⇒ TestUtility
constructor
A new instance of TestUtility.
- #install ⇒ Object
Methods inherited from Utility
#available?, #call_task_block, #disabled, #enabled?, #has_task?, #install_on_error?, #installed?, #invoked?, #no_results?, #success?, #task, #task_name
Constructor Details
#initialize(name, package, install_on_error: true) ⇒ TestUtility
Returns a new instance of TestUtility.
16 17 18 19 20 21 |
# File 'lib/autobuild/test_utility.rb', line 16 def initialize(name, package, install_on_error: true) super(name, package, install_on_error: install_on_error) @coverage_enabled = nil @coverage_source_dir = nil @coverage_target_dir = nil end |
Instance Attribute Details
#coverage_enabled=(value) ⇒ Object (writeonly)
Controls whether code coverage should be measured
40 41 42 |
# File 'lib/autobuild/test_utility.rb', line 40 def coverage_enabled=(value) @coverage_enabled = value end |
#coverage_source_dir ⇒ String
The full path to the coverage information
It cannot be a subdirectory of Utility#source_dir
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/autobuild/test_utility.rb', line 53 def coverage_source_dir if @coverage_source_dir relative = if package.respond_to?(:builddir) package.builddir else package.srcdir end File.(@coverage_source_dir, relative) end end |
#coverage_target_dir ⇒ String
Where the coverage information should be installed
It is the same than Utility#target_dir/coverage by default
75 76 77 78 79 80 81 |
# File 'lib/autobuild/test_utility.rb', line 75 def coverage_target_dir if @coverage_target_dir File.(@coverage_target_dir, package.prefix) elsif (target_dir = self.target_dir) File.join(target_dir, 'coverage') end end |
Class Method Details
.coverage_enabled=(flag) ⇒ Object
Enable code coverage for all tests
12 13 14 |
# File 'lib/autobuild/test_utility.rb', line 12 def self.coverage_enabled=(flag) @coverage_enabled = flag end |
.coverage_enabled? ⇒ Boolean
Whether coverage is enabled for all tests
7 8 9 |
# File 'lib/autobuild/test_utility.rb', line 7 def self.coverage_enabled? @coverage_enabled end |
Instance Method Details
#coverage_available? ⇒ Boolean
32 33 34 |
# File 'lib/autobuild/test_utility.rb', line 32 def coverage_available? @coverage_source_dir end |
#coverage_enabled? ⇒ Boolean
Whether code coverage should be generated for these tests
24 25 26 27 28 29 30 |
# File 'lib/autobuild/test_utility.rb', line 24 def coverage_enabled? if @coverage_enabled.nil? TestUtility.coverage_enabled? else @coverage_enabled end end |
#install ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/autobuild/test_utility.rb', line 83 def install super if !coverage_enabled? return elsif !coverage_available? package.warn "%s: #coverage_source_dir not set on #test_utility, "\ "skipping installation of the code coverage results" end coverage_target_dir = self.coverage_target_dir coverage_source_dir = self.coverage_source_dir if "#{coverage_source_dir}/".start_with?("#{source_dir}/") raise ArgumentError, "#coverage_source_dir cannot be a subdirectory "\ "of #source_dir in #{package.name}" elsif target_dir == coverage_target_dir raise ArgumentError, "#coverage_target_dir cannot be the same than of "\ "#target_dir in #{package.name}" end FileUtils.mkdir_p File.dirname(coverage_target_dir) FileUtils.cp_r coverage_source_dir, coverage_target_dir package. "%s: copied test coverage results for #{package.name} from "\ "#{coverage_source_dir} to #{coverage_target_dir}" end |