Class: Fastlane::Actions::GcovrAction

Inherits:
Fastlane::Action show all
Defined in:
lib/fastlane/actions/gcovr.rb

Overview

–object-directory=OBJDIR Specify the directory that contains the gcov data files. -o OUTPUT, –output=OUTPUT Print output to this filename Keep the temporary *.gcov files generated by gcov. -k, –keep Keep the temporary *.gcov files generated by gcov. -d, –delete Delete the coverage files after they are processed. -f FILTER, –filter=FILTER Keep only the data files that match this regular expression -e EXCLUDE, –exclude=EXCLUDE Exclude data files that match this regular expression –gcov-filter=GCOV_FILTER Keep only gcov data files that match this regular expression –gcov-exclude=GCOV_EXCLUDE Exclude gcov data files that match this regular expression -r ROOT, –root=ROOT Defines the root directory for source files. -x, –xml Generate XML instead of the normal tabular output. –xml-pretty Generate pretty XML instead of the normal dense format. –html Generate HTML instead of the normal tabular output. –html-details Generate HTML output for source file coverage. –html-absolute-paths Set the paths in the HTML report to be absolute instead of relative -b, –branches Tabulate the branch coverage instead of the line coverage. -u, –sort-uncovered Sort entries by increasing number of uncovered lines. -p, –sort-percentage Sort entries by decreasing percentage of covered lines. –gcov-executable=GCOV_CMD Defines the name/path to the gcov executable [defaults to the GCOV environment variable, if present; else ‘gcov’]. –exclude-unreachable-branches Exclude from coverage branches which are marked to be excluded by LCOV/GCOV markers or are determined to be from lines containing only compiler-generated “dead” code. -g, –use-gcov-files Use preprocessed gcov files for analysis. -s, –print-summary Prints a small report to stdout with line & branch percentage coverage

Constant Summary collapse

ARGS_MAP =
{
  object_directory: "--object-directory",
  output: "-o",
  keep: "-k",
  delete: "-d",
  filter: "-f",
  exclude: "-e",
  gcov_filter: "--gcov-filter",
  gcov_exclude: "--gcov-exclude",
  root: "-r",
  xml: "-x",
  xml_pretty: "--xml-pretty",
  html: "--html",
  html_details: "--html-details",
  html_absolute_paths: "--html-absolute-paths",
  branches: "-b",
  sort_uncovered: "-u",
  sort_percentage: "-p",
  gcov_executable: "--gcov-executable",
  exclude_unreachable_branches: "--exclude-unreachable-branches",
  use_gcov_files: "-g",
  print_summary: "-s"
}

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, lane_context, method_missing, other_action, output, return_value, sample_return_value, sh, step_text

Class Method Details

.authorObject



140
141
142
# File 'lib/fastlane/actions/gcovr.rb', line 140

def self.author
  "dtrenz"
end

.available_optionsObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/fastlane/actions/gcovr.rb', line 114

def self.available_options
  [
    ['object_directory', 'Specify the directory that contains the gcov data files.'],
    ['output', 'Print output to this filename Keep the temporary *.gcov files generated by gcov.'],
    ['keep', 'Keep the temporary *.gcov files generated by gcov.'],
    ['delete', 'Delete the coverage files after they are processed.'],
    ['filter', 'Keep only the data files that match this regular expression'],
    ['exclude', 'Exclude data files that match this regular expression'],
    ['gcov_filter', 'Keep only gcov data files that match this regular expression'],
    ['gcov_exclude', 'Exclude gcov data files that match this regular expression'],
    ['root', 'Defines the root directory for source files.'],
    ['xml', 'Generate XML instead of the normal tabular output.'],
    ['xml_pretty', 'Generate pretty XML instead of the normal dense format.'],
    ['html', 'Generate HTML instead of the normal tabular output.'],
    ['html_details', 'Generate HTML output for source file coverage.'],
    ['html_absolute_paths', 'Set the paths in the HTML report to be absolute instead of relative'],
    ['branches', 'Tabulate the branch coverage instead of the line coverage.'],
    ['sort_uncovered', 'Sort entries by increasing number of uncovered lines.'],
    ['sort_percentage', 'Sort entries by decreasing percentage of covered lines.'],
    ['gcov_executable', 'Defines the name/path to the gcov executable].'],
    ['exclude_unreachable_branches', 'Exclude from coverage branches which are marked to be excluded by LCOV/GCOV markers'],
    ['use_gcov_files', 'Use preprocessed gcov files for analysis.'],
    ['print_summary', 'Prints a small report to stdout with line & branch percentage coverage']
  ]
end

.categoryObject



158
159
160
# File 'lib/fastlane/actions/gcovr.rb', line 158

def self.category
  :testing
end

.create_output_dir_if_not_exists(output_path) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/fastlane/actions/gcovr.rb', line 86

def self.create_output_dir_if_not_exists(output_path)
  output_dir = File.dirname(output_path)

  # If the output directory doesn't exist, create it
  unless Dir.exist? output_dir
    FileUtils.mkpath output_dir
  end
end

.descriptionObject



110
111
112
# File 'lib/fastlane/actions/gcovr.rb', line 110

def self.description
  "Runs test coverage reports for your Xcode project"
end

.detailsObject



154
155
156
# File 'lib/fastlane/actions/gcovr.rb', line 154

def self.details
  "Generate summarized code coverage reports using [gcovr](http://gcovr.com/)"
end

.example_codeObject



144
145
146
147
148
149
150
151
152
# File 'lib/fastlane/actions/gcovr.rb', line 144

def self.example_code
  [
    'gcovr(
      html: true,
      html_details: true,
      output: "./code-coverage/report.html"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/fastlane/actions/gcovr.rb', line 50

def self.is_supported?(platform)
  platform == :ios
end

.params_hash_to_cli_args(params) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/fastlane/actions/gcovr.rb', line 95

def self.params_hash_to_cli_args(params)
  # Remove nil value params
  params = params.delete_if { |_, v| v.nil? }

  # Maps nice developer param names to CLI arguments
  params.map do |k, v|
    v ||= ""
    args = ARGS_MAP[k]
    if args
      value = (v != true && v.to_s.length > 0 ? "\"#{v}\"" : "")
      "#{args} #{value}".strip
    end
  end.compact
end

.run(params) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fastlane/actions/gcovr.rb', line 54

def self.run(params)
  unless Helper.test?
    UI.user_error!("gcovr not installed") if `which gcovr`.length == 0
  end

  # The args we will build with
  gcovr_args = nil

  # Allows for a whole variety of configurations
  if params.kind_of? Hash
    params_hash = params

    # Check if an output path was given
    if params_hash.key? :output
      create_output_dir_if_not_exists(params_hash[:output])
    end

    # Maps parameter hash to CLI args
    gcovr_args = params_hash_to_cli_args(params_hash)
  else
    gcovr_args = params
  end

  # Joins args into space delimited string
  gcovr_args = gcovr_args.join(" ")

  command = "gcovr #{gcovr_args}"
  UI.success("Generating code coverage.")
  UI.verbose(command)
  Actions.sh command
end