Class: TestCenter::Helper::ReportNameHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/test_center/helper/reportname_helper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_types = nil, output_files = nil, custom_report_file_name = nil) ⇒ ReportNameHelper

Returns a new instance of ReportNameHelper.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 8

def initialize(output_types = nil, output_files = nil, custom_report_file_name = nil)
  @output_types = output_types || 'xcresult'
  @output_files = output_files || custom_report_file_name
  @report_count = 0

  if @output_types && @output_files.nil?
    @output_files = @output_types.split(',').map { |type| "report.#{type}" }.join(',')
  end
  unless @output_types.include?('xcresult')
    FastlaneCore::UI.important('Scan output types missing \'xcresult\', adding it')
    @output_types = @output_types.split(',').push('xcresult').join(',')
    if @output_types.split(',').size == @output_files.split(',').size + 1
      @output_files = @output_files.split(',').push('report.xcresult').join(',')
      FastlaneCore::UI.message('As output files has one less than the new number of output types, assumming the filename for the xcresult was missing and added it')
    end
  end

  types = @output_types.split(',').each(&:chomp)
  files = @output_files.split(',').each(&:chomp)
  unless files.size == types.size
    raise ArgumentError, "Error: count of :output_types, #{types}, does not match the output filename(s) #{files}"
  end
end

Instance Attribute Details

#report_countObject (readonly)

Returns the value of attribute report_count.



6
7
8
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 6

def report_count
  @report_count
end

Class Method Details

.ensure_output_includes_xcresult(output_types, output_files) ⇒ Object



151
152
153
154
155
156
157
158
159
160
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 151

def self.ensure_output_includes_xcresult(output_types, output_files)
  return [output_types, output_files] if includes_xcresult?(output_types) || output_types.nil?

  output_types = output_types.split(',').push('xcresult').join(',')
  if output_files
    output_files = output_files.split(',').push('report.xcresult').join(',')
  end

  [output_types, output_files]
end

.includes_xcresult?(output_types) ⇒ Boolean

Returns:

  • (Boolean)


162
163
164
165
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 162

def self.includes_xcresult?(output_types)
 return false unless ::FastlaneCore::Helper.xcode_at_least?('11.0.0')
 output_types && output_types.split(',').find_index('xcresult') != nil
end

Instance Method Details

#html_fileglobObject



114
115
116
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 114

def html_fileglob
  "#{File.basename(html_reportname, '.*')}*#{html_filextension}"
end

#html_filextensionObject



110
111
112
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 110

def html_filextension
  File.extname(html_reportname)
end

#html_last_reportnameObject



97
98
99
100
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 97

def html_last_reportname
  html_index = @output_types.split(',').find_index('html')
  numbered_filename(@output_files.to_s.split(',')[html_index])
end

#html_numbered_fileglobObject



118
119
120
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 118

def html_numbered_fileglob
  "#{File.basename(html_reportname, '.*')}-[1-9]*#{html_filextension}"
end

#html_reportname(suffix = '') ⇒ Object



102
103
104
105
106
107
108
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 102

def html_reportname(suffix = '')
  html_index = @output_types.split(',').find_index('html')
  report_name = @output_files.to_s.split(',')[html_index]
  return report_name if suffix.empty?

  "#{File.basename(report_name, '.*')}-#{suffix}#{html_filextension}"
end

#includes_html?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 93

def includes_html?
  @output_types.split(',').find_index('html') != nil
end

#includes_json?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 122

def includes_json?
  @output_types.split(',').find_index('json') != nil
end

#includes_xcresult?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 167

def includes_xcresult?
  self.class.includes_xcresult?(@output_types)
end

#incrementObject



196
197
198
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 196

def increment
  @report_count += 1
end

#json_fileglobObject



143
144
145
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 143

def json_fileglob
  "#{File.basename(json_reportname, '.*')}*#{json_filextension}"
end

#json_filextensionObject



139
140
141
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 139

def json_filextension
  File.extname(json_reportname)
end

#json_last_reportnameObject



126
127
128
129
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 126

def json_last_reportname
  json_index = @output_types.split(',').find_index('json')
  numbered_filename(@output_files.to_s.split(',')[json_index])
end

#json_numbered_fileglobObject



147
148
149
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 147

def json_numbered_fileglob
  "#{File.basename(json_reportname, '.*')}-[1-9]*#{json_filextension}"
end

#json_reportname(suffix = '') ⇒ Object



131
132
133
134
135
136
137
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 131

def json_reportname(suffix = '')
  json_index = @output_types.split(',').find_index('json')
  report_name = @output_files.to_s.split(',')[json_index]
  return report_name if suffix.empty?

  "#{File.basename(report_name, '.*')}-#{suffix}#{json_filextension}"
end

#junit_fileglobObject



85
86
87
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 85

def junit_fileglob
  "#{File.basename(junit_reportname, '.*')}*#{junit_filextension}"
end

#junit_filextensionObject



81
82
83
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 81

def junit_filextension
  File.extname(junit_reportname)
end

#junit_last_reportnameObject



68
69
70
71
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 68

def junit_last_reportname
  junit_index = @output_types.split(',').find_index('junit')
  numbered_filename(@output_files.to_s.split(',')[junit_index])
end

#junit_numbered_fileglobObject



89
90
91
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 89

def junit_numbered_fileglob
  "#{File.basename(junit_reportname, '.*')}-[1-9]*#{junit_filextension}"
end

#junit_reportname(suffix = '') ⇒ Object



73
74
75
76
77
78
79
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 73

def junit_reportname(suffix = '')
  junit_index = @output_types.split(',').find_index('junit')
  report_name = @output_files.to_s.split(',')[junit_index]
  return report_name if suffix.empty?

  "#{File.basename(report_name, '.*')}-#{suffix}#{junit_filextension}"
end

#numbered_filename(filename) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 32

def numbered_filename(filename)
  if @report_count > 0
    basename = File.basename(filename, '.*')
    extension = File.extname(filename)
    filename = "#{basename}-#{@report_count + 1}#{extension}"
  end
  filename
end

#scan_optionsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 41

def scan_options
  options = {}

  types = @output_types.split(',').each(&:chomp)
  files = @output_files.split(',').each(&:chomp)
  if (json_index = types.find_index('json'))
    options[:formatter] = 'xcpretty-json-formatter'
    files.delete_at(json_index)
    types.delete_at(json_index)
  end
  if (xcresult_index = types.find_index('xcresult'))
    files.delete_at(xcresult_index)
    types.delete_at(xcresult_index)
  end
  files.map! do |filename|
    filename.chomp
    numbered_filename(filename)
  end

  output_types = types.join(',') unless types.empty?
  output_files = files.join(',') unless files.empty?
  options.merge(
    output_types: output_types,
    output_files: output_files
  )
end

#xcresult_bundlename(suffix = '') ⇒ Object



176
177
178
179
180
181
182
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 176

def xcresult_bundlename(suffix = '')
  xcresult_index = @output_types.split(',').find_index('xcresult')
  report_name = @output_files.to_s.split(',')[xcresult_index]
  return report_name if suffix.empty?

  "#{File.basename(report_name, '.*')}-#{suffix}#{xcresult_filextension}"
end

#xcresult_fileglobObject



188
189
190
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 188

def xcresult_fileglob
  "#{File.basename(xcresult_bundlename, '.*')}*#{xcresult_filextension}"
end

#xcresult_filextensionObject



184
185
186
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 184

def xcresult_filextension
  File.extname(xcresult_bundlename)
end

#xcresult_last_bundlenameObject



171
172
173
174
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 171

def xcresult_last_bundlename
  xcresult_index = @output_types.split(',').find_index('xcresult')
  numbered_filename(@output_files.to_s.split(',')[xcresult_index])
end

#xcresult_numbered_fileglobObject



192
193
194
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 192

def xcresult_numbered_fileglob
  "#{File.basename(xcresult_bundlename, '.*')}-[1-9]*#{xcresult_filextension}"
end