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 || 'junit'
  @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?('junit')
    FastlaneCore::UI.important('Scan output types missing \'junit\', adding it')
    @output_types = @output_types.split(',').push('junit').join(',')
    if @output_types.split(',').size == @output_files.split(',').size + 1
      @output_files = @output_files.split(',').push('report.xml').join(',')
      FastlaneCore::UI.message('As output files has one less than the new number of output types, assumming the filename for the junit 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



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

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)


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

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



112
113
114
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 112

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

#html_filextensionObject



108
109
110
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 108

def html_filextension
  File.extname(html_reportname)
end

#html_last_reportnameObject



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

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



116
117
118
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 116

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

#html_reportname(suffix = '') ⇒ Object



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

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)


91
92
93
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 91

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

#includes_json?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 120

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

#includes_xcresult?Boolean

Returns:

  • (Boolean)


165
166
167
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 165

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

#incrementObject



194
195
196
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 194

def increment
  @report_count += 1
end

#json_fileglobObject



141
142
143
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 141

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

#json_filextensionObject



137
138
139
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 137

def json_filextension
  File.extname(json_reportname)
end

#json_last_reportnameObject



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

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



145
146
147
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 145

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

#json_reportname(suffix = '') ⇒ Object



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

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



83
84
85
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 83

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

#junit_filextensionObject



79
80
81
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 79

def junit_filextension
  File.extname(junit_reportname)
end

#junit_last_reportnameObject



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

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



87
88
89
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 87

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

#junit_reportname(suffix = '') ⇒ Object



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

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
# 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

  options.merge(
    output_types: types.join(','),
    output_files: files.join(',')
  )
end

#xcresult_bundlename(suffix = '') ⇒ Object



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

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



186
187
188
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 186

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

#xcresult_filextensionObject



182
183
184
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 182

def xcresult_filextension
  File.extname(xcresult_bundlename)
end

#xcresult_last_bundlenameObject



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

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



190
191
192
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 190

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