Class: Autobuild::TestUtility

Inherits:
Utility
  • Object
show all
Defined in:
lib/autobuild/test_utility.rb

Overview

Control of the test facility for a package

Instance Attribute Summary collapse

Attributes inherited from Utility

#available, #enabled, #name, #no_results, #package, #source_dir, #source_ref_dir, #target_dir

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:

  • flag (Boolean, nil)

    enable or disable code coverage. If set to nil, will use the default from TestUtility.coverage?



40
41
42
# File 'lib/autobuild/test_utility.rb', line 40

def coverage_enabled=(value)
  @coverage_enabled = value
end

#coverage_source_dirString

The full path to the coverage information

It cannot be a subdirectory of Utility#source_dir

Returns:

  • (String)


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.expand_path(@coverage_source_dir, relative)
    end
end

#coverage_target_dirString

Where the coverage information should be installed

It is the same than Utility#target_dir/coverage by default

Returns:

  • (String)


75
76
77
78
79
80
81
# File 'lib/autobuild/test_utility.rb', line 75

def coverage_target_dir
    if @coverage_target_dir
        File.expand_path(@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

Returns:

  • (Boolean)


7
8
9
# File 'lib/autobuild/test_utility.rb', line 7

def self.coverage_enabled?
    @coverage_enabled
end

Instance Method Details

#coverage_available?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


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

#installObject



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.message "%s: copied test coverage results for #{package.name} from "\
        "#{coverage_source_dir} to #{coverage_target_dir}"
end