spectre-reporter-vstest 1.0.8 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/spectre/reporter/vstest.rb +57 -58
  3. metadata +5 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d053b6759cb2f87556b4a4163804f927f3a6b2d9bc68c038953905a99f7a0d27
4
- data.tar.gz: d50e42462846b6832a6f7d7ba6993365861f47ecb9506d91140ebef1b4c67683
3
+ metadata.gz: 4a4186606520095c92be1b5c621e422811fe64da40b892e9e571f008ada86708
4
+ data.tar.gz: e48157c99d11f1f46c5750678fb198a1b8da8e1d0234290d186962b04b659134
5
5
  SHA512:
6
- metadata.gz: bbe6029d5708cd812dd233954f8159bd2c8391965ef111df8b3895f1c113a52575ca37b77fe309b301ffbcca2bda5e7b9b653e4dac4a8393192c25b50d326d3f
7
- data.tar.gz: 634b41c6a50742313d9af6e5435ac0979c0beb8f0ff5a26835a22fffac52b92e8159cf36739de2b6debd0b78de0daf0abdd6897e90176530d6320a0fce021032
6
+ metadata.gz: 465f7af992614df34a4741a60b7b3e2f29c9f0c4e79445397ea94f5050419391ecfd04467481cb6cf1ad1ff862e381db4669c3a4211b20d6b7d32b9231af1203
7
+ data.tar.gz: b53a7cc5c12930566fa2e0bccfac1bf35dd37bdbb4397c2033561dea3f70abf0844c0aefb9031082a44bc9e08126e8705cb2b6ff3583e2cf461385d72a391c82
@@ -1,8 +1,6 @@
1
1
  require 'cgi'
2
2
  require 'socket'
3
3
  require 'securerandom'
4
- require 'spectre'
5
- require 'spectre/reporter'
6
4
 
7
5
  # Azure mappings: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/test/publish-test-results?view=azure-devops&tabs=trx%2Cyaml
8
6
 
@@ -18,72 +16,77 @@ module Spectre
18
16
  now = Time.now.getutc
19
17
 
20
18
  xml_str = '<?xml version="1.0" encoding="UTF-8" ?>'
21
- xml_str += %{<TestRun xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">}
19
+ xml_str += %(<TestRun xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">)
22
20
 
23
21
  started = run_infos[0].started
24
22
  finished = run_infos[-1].finished
25
23
 
26
24
  computer_name = Socket.gethostname
27
25
 
28
- xml_str += %{<Times start="#{started.strftime(@date_format)}" finish="#{finished.strftime(@date_format)}" />}
29
-
26
+ xml_str += %(<Times start="#{started.strftime(@date_format)}" finish="#{finished.strftime(@date_format)}" />)
30
27
 
31
28
  # Write summary with file attachments
32
29
  xml_str += '<ResultSummary>'
33
30
  xml_str += '<ResultFiles>'
34
- xml_str += %{<ResultFile path="#{File.absolute_path(@config['log_file'])}"></ResultFile>} if File.exist? @config['log_file']
31
+ if File.exist? @config['log_file']
32
+ xml_str += %(<ResultFile path="#{File.absolute_path(@config['log_file'])}"></ResultFile>)
33
+ end
35
34
 
36
35
  report_files = Dir[File.join(@config['out_path'], '*')]
37
36
 
38
37
  if report_files.any?
39
38
  report_files.each do |report_file|
40
- xml_str += %{<ResultFile path="#{File.absolute_path(report_file)}"></ResultFile>}
39
+ xml_str += %(<ResultFile path="#{File.absolute_path(report_file)}"></ResultFile>)
41
40
  end
42
41
  end
43
42
 
44
43
  xml_str += '</ResultFiles>'
45
44
  xml_str += '</ResultSummary>'
46
45
 
47
-
48
46
  # Write test definitions
49
47
  test_definitions = run_infos
50
- .sort_by { |x| x.spec.name }
51
- .map { |x| [SecureRandom.uuid(), SecureRandom.uuid(), x] }
48
+ .sort_by { |x| x.parent.name }
49
+ .map { |x| [SecureRandom.uuid, SecureRandom.uuid, x] }
52
50
 
53
51
  xml_str += '<TestDefinitions>'
54
52
  test_definitions.each do |test_id, execution_id, run_info|
55
- xml_str += %{<UnitTest name="#{CGI::escapeHTML get_name(run_info)}" storage="#{CGI::escapeHTML(run_info.spec.file.to_s)}" id="#{test_id}">}
56
- xml_str += %{<Execution id="#{execution_id}" />}
53
+ xml_str += %(<UnitTest name="#{CGI.escapeHTML get_name(run_info)}" \
54
+ storage="#{CGI.escapeHTML(run_info.parent.file.to_s)}" id="#{test_id}">)
55
+ xml_str += %(<Execution id="#{execution_id}" />)
57
56
  xml_str += '</UnitTest>'
58
57
  end
59
58
  xml_str += '</TestDefinitions>'
60
59
 
61
-
62
60
  # Write test results
63
61
  xml_str += '<Results>'
64
62
  test_definitions.each do |test_id, execution_id, run_info|
65
- duration_str = Time.at(run_info.duration).gmtime.strftime('%T.%L')
66
-
67
- if run_info.failed?
68
- outcome = 'Failed'
69
- elsif run_info.error?
70
- outcome = 'Failed'
71
- elsif run_info.skipped?
72
- outcome = 'Skipped'
73
- else
74
- outcome = 'Passed'
75
- end
76
-
77
- xml_str += %{<UnitTestResult executionId="#{execution_id}" testId="#{test_id}" testName="#{CGI::escapeHTML get_name(run_info)}" computerName="#{computer_name}" duration="#{duration_str}" startTime="#{run_info.started.strftime(@date_format)}" endTime="#{run_info.finished.strftime(@date_format)}" outcome="#{outcome}">}
78
-
79
- if run_info.log.any? or run_info.failed? or run_info.error?
63
+ duration_str = Time.at(run_info.finished - run_info.started).gmtime.strftime('%T.%L')
64
+
65
+ outcome = if [:failed, :error].include? run_info.status
66
+ 'Failed'
67
+ elsif run_info.status == :skipped
68
+ 'Skipped'
69
+ else
70
+ 'Passed'
71
+ end
72
+
73
+ xml_str += %(<UnitTestResult executionId="#{execution_id}" \
74
+ testId="#{test_id}" \
75
+ testName="#{CGI.escapeHTML get_name(run_info)}" \
76
+ computerName="#{computer_name}" \
77
+ duration="#{duration_str}" \
78
+ startTime="#{run_info.started.strftime(@date_format)}" \
79
+ endTime="#{run_info.finished.strftime(@date_format)}" \
80
+ outcome="#{outcome}">)
81
+
82
+ if run_info.logs.any?
80
83
  xml_str += '<Output>'
81
84
 
82
85
  # Write log entries
83
86
  xml_str += '<StdOut>'
84
87
  log_str = ''
85
88
 
86
- if run_info.properties.count > 0
89
+ if run_info.properties.count.positive?
87
90
  run_info.properties.each do |key, val|
88
91
  log_str += "#{key}: #{val}\n"
89
92
  end
@@ -95,52 +98,57 @@ module Spectre
95
98
  log_str += "data: #{data_str}\n"
96
99
  end
97
100
 
98
- run_info.log.each do |timestamp, message, level, name|
99
- log_text = ""
101
+ run_info.logs.each do |timestamp, level, progname, _corr_id, message|
102
+ log_text = ''
100
103
  begin
101
104
  log_text = message.dup.to_s
102
- .force_encoding("ISO-8859-1")
103
- .encode!("UTF-8")
104
- rescue
105
+ .gsub(/[^[:print:]\n]/, '<np>') # Replace non printable characters
106
+ .force_encoding('ISO-8859-1')
107
+ .encode!('UTF-8')
108
+ rescue StandardError
105
109
  puts "ERROR in VSTEST - see message : #{message}"
106
110
  end
107
111
 
108
- log_str += %{#{timestamp.strftime(@date_format)} #{level.to_s.upcase} -- #{name}: #{CGI::escapeHTML(log_text)}\n}
112
+ log_str += %(#{timestamp} #{level.to_s.upcase} -- \
113
+ #{progname}: #{CGI.escapeHTML(log_text)}\n)
109
114
  end
110
115
 
111
116
  xml_str += log_str
112
117
  xml_str += '</StdOut>'
113
118
 
114
119
  # Write error information
115
- if run_info.failed? or run_info.error?
120
+ if [:failed, :error].include? run_info.status
116
121
  xml_str += '<ErrorInfo>'
117
122
 
118
- if run_info.failed? and not run_info.failure.cause
123
+ if run_info.status == :failed
119
124
  xml_str += '<Message>'
120
125
 
121
- failure_message = "Expected #{run_info.failure.expectation}"
122
- failure_message += " with #{run_info.data}" if run_info.data
123
- failure_message += " but it failed"
124
- failure_message += " with message: #{run_info.failure.message}" if run_info.failure.message
126
+ failure_message = ''
125
127
 
126
- xml_str += CGI::escapeHTML(failure_message)
128
+ run_info.evaluations.each do |evaluation|
129
+ evaluation.failures.each do |failure|
130
+ failure_message += "#{evaluation.desc}, but #{failure.message} "
131
+ end
132
+ end
133
+
134
+ xml_str += CGI.escapeHTML(failure_message)
127
135
 
128
136
  xml_str += '</Message>'
129
137
  end
130
138
 
131
- if run_info.error or (run_info.failed? and run_info.failure.cause)
132
- error = run_info.error || run_info.failure.cause
139
+ if run_info.status == :error
140
+ error = run_info.error
133
141
 
134
142
  failure_message = error.message
135
143
 
136
144
  xml_str += '<Message>'
137
- xml_str += CGI::escapeHTML(failure_message)
145
+ xml_str += CGI.escapeHTML(failure_message)
138
146
  xml_str += '</Message>'
139
147
 
140
148
  stack_trace = error.backtrace.join "\n"
141
149
 
142
150
  xml_str += '<StackTrace>'
143
- xml_str += CGI::escapeHTML(stack_trace)
151
+ xml_str += CGI.escapeHTML(stack_trace)
144
152
  xml_str += '</StackTrace>'
145
153
  end
146
154
 
@@ -150,17 +158,14 @@ module Spectre
150
158
  xml_str += '</Output>'
151
159
  end
152
160
 
153
-
154
161
  xml_str += '</UnitTestResult>'
155
162
  end
156
163
  xml_str += '</Results>'
157
164
 
158
-
159
165
  # End report
160
166
  xml_str += '</TestRun>'
161
167
 
162
-
163
- Dir.mkdir(@config['out_path']) unless Dir.exist? @config['out_path']
168
+ FileUtils.mkdir_p(@config['out_path'])
164
169
 
165
170
  file_path = File.join(@config['out_path'], "spectre-vstest_#{now.strftime('%s')}.trx")
166
171
 
@@ -170,14 +175,8 @@ module Spectre
170
175
  private
171
176
 
172
177
  def get_name run_info
173
- run_name = "[#{run_info.spec.name}] #{run_info.spec.subject.desc}"
174
- run_name += " - #{run_info.spec.context.__desc} -" unless run_info.spec.context.__desc.nil?
175
- run_name += " #{run_info.spec.desc}"
176
- run_name
177
- end
178
-
179
- Spectre.register do |config|
180
- Spectre::Reporter.add VSTest.new(config)
178
+ parent = run_info.parent
179
+ "[#{parent.name}] #{parent.full_desc}"
181
180
  end
182
181
  end
183
182
  end
metadata CHANGED
@@ -1,29 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectre-reporter-vstest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Neubauer
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-01-20 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: spectre-core
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 1.14.3
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 1.14.3
10
+ date: 2025-03-26 00:00:00.000000000 Z
11
+ dependencies: []
27
12
  description: Writes a VSTest report for spectre test run, which can be used in Azure
28
13
  DevOps
29
14
  email:
@@ -40,7 +25,6 @@ metadata:
40
25
  homepage_uri: https://github.com/ionos-spectre/spectre-reporter-vstest
41
26
  source_code_uri: https://github.com/ionos-spectre/spectre-reporter-vstest
42
27
  changelog_uri: https://github.com/ionos-spectre/spectre-reporter-vstest/blob/master/CHANGELOG.md
43
- post_install_message:
44
28
  rdoc_options: []
45
29
  require_paths:
46
30
  - lib
@@ -48,15 +32,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
32
  requirements:
49
33
  - - ">="
50
34
  - !ruby/object:Gem::Version
51
- version: 3.0.0
35
+ version: '3.4'
52
36
  required_rubygems_version: !ruby/object:Gem::Requirement
53
37
  requirements:
54
38
  - - ">="
55
39
  - !ruby/object:Gem::Version
56
40
  version: '0'
57
41
  requirements: []
58
- rubygems_version: 3.4.19
59
- signing_key:
42
+ rubygems_version: 3.6.2
60
43
  specification_version: 4
61
44
  summary: A VSTest reporter for spectre
62
45
  test_files: []