minitest-ci 3.2.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7df74b27d06a7fc3c130ff4948fa7409006fffd9
4
- data.tar.gz: 0f475b81387862ff375e1de9e790239c6bbcd656
3
+ metadata.gz: a89fdbe89e6a7888a4bd89af927b956760cbd5cd
4
+ data.tar.gz: d98276bb6a0356e48e64ed9dbced315c2cb43af5
5
5
  SHA512:
6
- metadata.gz: f3602c8752a1b60b63b4c403d572c6e45932d56fd8014efb578298c4df55890721baaad6bf66a94ce2f985b30eee8adee285d1464adf0bebab88b08b5b909eaf
7
- data.tar.gz: faf0bbac59b3b69b0c38b917defd428fddd7189cd65aef264100d223eb55dcec9d41211c444e9233ae16d92d954eb75cde83267cdccd1e085e6b388e2cb3b84d
6
+ metadata.gz: d5fe3944ec63ec15e9aa93954160cd2ac08dc7b06e326d201c369d354c1224b276f8bd44306dfecbdb46d7412c30c74fbb77299bfc0564b36ca3c3fbfc4f60db
7
+ data.tar.gz: 3e79116f6edd9bae67c7566bed0b3d6c6a7966a2c6e4dddf1c11ea2431fd512128fd2c55b3cfb02ab920535d364e45e97800f5644824f9f7ca0e7648e2f77984
@@ -80,6 +80,18 @@ Alternatively, you can add the following code to your test runner setup:
80
80
  end
81
81
  task :test => %w[ci_cleanup test:one test:two]
82
82
 
83
+ To configure report filename, use the `report_name` option like
84
+
85
+ Minitest::Ci.new $ci_io, { :report_name => :sha1 }
86
+
87
+ or like
88
+
89
+ machine:
90
+ environment:
91
+ TESTOPTS: "--report-name=sha1"
92
+
93
+ Supported options are: `:test_name` (default), `:sha1`, or a `Proc` (not supported through ENV var)
94
+
83
95
  == REQUIREMENTS:
84
96
 
85
97
  * Minitest > version 5
@@ -1,136 +1,2 @@
1
- require 'fileutils'
2
- require 'cgi'
3
-
4
- module Minitest
5
- class Ci < Reporter
6
- class << self
7
-
8
- ##
9
- # Change the report directory. (defaults to "test/reports")
10
-
11
- attr_accessor :report_dir
12
-
13
- ##
14
- # Clean the report_dir between test runs? (defaults to true)
15
-
16
- attr_accessor :clean
17
-
18
- ##
19
- # Change the working directory. (defaults to `$PWD`)
20
- attr_accessor :working_dir
21
- end
22
-
23
- self.report_dir = 'test/reports'
24
- self.clean = true
25
- self.working_dir = Dir.pwd
26
-
27
- attr_accessor :io
28
- attr_accessor :options
29
- attr_accessor :results
30
-
31
- def initialize io = $stdout, options = {}
32
- self.io = io
33
- self.options = options
34
- self.results = Hash.new {|h,k| h[k] = []}
35
- end
36
-
37
- def passed?
38
- true # don't care?
39
- end
40
-
41
- def start # clean
42
- FileUtils.rm_rf report_dir if clean?
43
- FileUtils.mkdir_p report_dir
44
- end
45
-
46
- def record result
47
- results[result.class] << result
48
- end
49
-
50
- ##
51
- # Generate test report
52
- def report
53
- io.puts
54
- io.puts '[Minitest::CI] Generating test report in JUnit XML format...'
55
-
56
- Dir.chdir report_dir do
57
- results.each do |name, result|
58
- File.open(report_name(name), "w") do |f|
59
- f.puts( generate_results(name, result) )
60
- end
61
- end
62
- end
63
- end
64
-
65
- private
66
-
67
- def escape o
68
- CGI.escapeHTML(o.to_s)
69
- end
70
-
71
- def generate_results name, results
72
- total_time = assertions = errors = failures = skips = 0
73
- results.each do |result|
74
- total_time += result.time
75
- assertions += result.assertions
76
-
77
- case result.failure
78
- when Skip
79
- skips += 1
80
- when UnexpectedError
81
- errors += 1
82
- when Assertion
83
- failures += 1
84
- end
85
- end
86
-
87
- base = working_dir + '/'
88
- xml = []
89
-
90
- xml << '<?xml version="1.0" encoding="UTF-8"?>'
91
- xml << "<testsuite time='%6f' skipped='%d' failures='%d' errors='%d' name=%p assertions='%d' tests='%d'>" %
92
- [total_time, skips, failures, errors, escape(name), assertions, results.count]
93
-
94
- results.each do |result|
95
- xml << " <testcase time='%6f' file=%p name=%p assertions='%s'>" %
96
- [result.time, escape(result.method(result.name).source_location[0].gsub(base, '')), escape(result.name), result.assertions]
97
- if failure = result.failure
98
- label = failure.result_label.downcase
99
-
100
- if failure.is_a?(UnexpectedError)
101
- failure = failure.error
102
- end
103
-
104
- klass = failure.class
105
- msg = failure.message
106
- bt = Minitest::filter_backtrace failure.backtrace
107
-
108
- xml << " <%s type='%s' message=%s>%s" %
109
- [label, escape(klass), escape(msg).inspect.gsub('\n', "&#13;&#10;"), escape(bt.join("\n"))]
110
- xml << " </%s>" % label
111
- end
112
- xml << " </testcase>"
113
- end
114
-
115
- xml << "</testsuite>"
116
-
117
- xml
118
- end
119
-
120
- def working_dir
121
- options.fetch(:working_dir, self.class.working_dir)
122
- end
123
-
124
- def report_dir
125
- options.fetch(:ci_dir, self.class.report_dir)
126
- end
127
-
128
- def clean?
129
- options.fetch(:ci_clean, self.class.clean)
130
- end
131
-
132
- def report_name(name)
133
- "TEST-#{CGI.escape(name.to_s.gsub(/\W+/, '_'))}.xml"[0, 255]
134
- end
135
- end
136
- end
1
+ require 'minitest/ci_plugin'
2
+ Minitest::Ci.report!
@@ -1,12 +1,13 @@
1
- require 'minitest/ci'
1
+ require 'fileutils'
2
+ require 'cgi'
3
+ require 'time'
2
4
 
3
5
  module Minitest
4
-
5
- def self.plugin_ci_init options
6
- self.reporter << Ci.new(options[:io], options)
7
- end
8
-
9
6
  def self.plugin_ci_options opts, options
7
+ opts.on "--ci-report", "Enable Minitest::Ci Reporting." do |dir|
8
+ Ci.report!
9
+ end
10
+
10
11
  opts.on "--ci-dir DIR", "Set the CI report dir. Default to #{Ci.report_dir}" do |dir|
11
12
  options[:ci_dir] = dir
12
13
  end
@@ -18,6 +19,168 @@ module Minitest
18
19
  opts.on "--working-dir DIR", "Set the working dir. Default to #{Ci.working_dir}" do |dir|
19
20
  options[:working_dir] = dir
20
21
  end
22
+
23
+ opts.on "--report-name REPORT_NAME_OPTION", "Set report name option. Default to :test_name" do |report_name_option|
24
+ options[:report_name] = report_name_option
25
+ end
21
26
  end
22
27
 
28
+ def self.plugin_ci_init options
29
+ if Ci.report?
30
+ self.reporter << Ci.new(options[:io], options)
31
+ end
32
+ end
33
+
34
+ class Ci < Reporter
35
+ class << self
36
+ ##
37
+ # Activates minitest/ci plugin as a Minitest reporter
38
+ def report!
39
+ @report = true
40
+ end
41
+
42
+ ##
43
+ # Is minitest/ci activated as a Minitest reporter?
44
+ def report?
45
+ @report ||= false
46
+ end
47
+
48
+ ##
49
+ # Change the report directory. (defaults to "test/reports")
50
+ attr_accessor :report_dir
51
+
52
+ ##
53
+ # Clean the report_dir between test runs? (defaults to true)
54
+ attr_accessor :clean
55
+
56
+ ##
57
+ # Change the working directory. (defaults to `$PWD`)
58
+ attr_accessor :working_dir
59
+ end
60
+
61
+ self.report_dir = 'test/reports'
62
+ self.clean = true
63
+ self.working_dir = Dir.pwd
64
+
65
+ attr_accessor :io
66
+ attr_accessor :options
67
+ attr_accessor :results
68
+
69
+ def initialize io = $stdout, options = {}
70
+ self.io = io
71
+ self.options = options
72
+ self.results = Hash.new {|h,k| h[k] = []}
73
+ end
74
+
75
+ def passed?
76
+ true # don't care?
77
+ end
78
+
79
+ def start # clean
80
+ FileUtils.rm_rf report_dir if clean?
81
+ FileUtils.mkdir_p report_dir
82
+ end
83
+
84
+ def record result
85
+ results[result.class] << result
86
+ end
87
+
88
+ ##
89
+ # Generate test report
90
+ def report
91
+ io.puts
92
+ io.puts '[Minitest::CI] Generating test report in JUnit XML format...'
93
+
94
+ Dir.chdir report_dir do
95
+ results.each do |name, result|
96
+ File.open(report_name(name), "w") do |f|
97
+ f.puts( generate_results(name, result) )
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ private
104
+
105
+ def escape o
106
+ CGI.escapeHTML(o.to_s)
107
+ end
108
+
109
+ def generate_results name, results
110
+ total_time = assertions = errors = failures = skips = 0
111
+ timestamp = Time.now.iso8601
112
+ results.each do |result|
113
+ total_time += result.time
114
+ assertions += result.assertions
115
+
116
+ case result.failure
117
+ when Skip
118
+ skips += 1
119
+ when UnexpectedError
120
+ errors += 1
121
+ when Assertion
122
+ failures += 1
123
+ end
124
+ end
125
+
126
+ base = working_dir + '/'
127
+ xml = []
128
+
129
+ xml << '<?xml version="1.0" encoding="UTF-8"?>'
130
+ xml << "<testsuite time='%6f' skipped='%d' failures='%d' errors='%d' name=%p assertions='%d' tests='%d' timestamp=%p>" %
131
+ [total_time, skips, failures, errors, escape(name), assertions, results.count, timestamp]
132
+
133
+ results.each do |result|
134
+ xml << " <testcase time='%6f' file=%p name=%p assertions='%s'>" %
135
+ [result.time, escape(result.method(result.name).source_location[0].gsub(base, '')), escape(result.name), result.assertions]
136
+ if failure = result.failure
137
+ label = failure.result_label.downcase
138
+
139
+ if failure.is_a?(UnexpectedError)
140
+ failure = failure.error
141
+ end
142
+
143
+ klass = failure.class
144
+ msg = failure.message
145
+ bt = Minitest::filter_backtrace failure.backtrace
146
+
147
+ xml << " <%s type='%s' message=%s>%s" %
148
+ [label, escape(klass), escape(msg).inspect.gsub('\n', "&#13;&#10;"), escape(bt.join("\n"))]
149
+ xml << " </%s>" % label
150
+ end
151
+ xml << " </testcase>"
152
+ end
153
+
154
+ xml << "</testsuite>"
155
+
156
+ xml
157
+ end
158
+
159
+ def working_dir
160
+ options.fetch(:working_dir, self.class.working_dir)
161
+ end
162
+
163
+ def report_dir
164
+ options.fetch(:ci_dir, self.class.report_dir)
165
+ end
166
+
167
+ def clean?
168
+ options.fetch(:ci_clean, self.class.clean)
169
+ end
170
+
171
+ def report_name(name)
172
+ report_name_opt = options.fetch(:report_name, :test_name)
173
+ return report_name_opt.call(name) if report_name_opt.is_a? Proc
174
+ return sha1_report_name(name) if report_name_opt.to_sym == :sha1
175
+ test_name_report_name(name)
176
+ end
177
+
178
+ def sha1_report_name(name)
179
+ "TEST-#{Digest::SHA1.hexdigest(name.to_s)}.xml"
180
+ end
181
+
182
+ def test_name_report_name(name)
183
+ "TEST-#{CGI.escape(name.to_s.gsub(/\W+/, '_'))[0, 246]}.xml"
184
+ end
185
+ end
23
186
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-ci
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - zzak
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-03-14 00:00:00.000000000 Z
13
+ date: 2017-09-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: minitest
@@ -32,42 +32,42 @@ dependencies:
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '1.13'
35
+ version: '1.14'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '1.13'
42
+ version: '1.14'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rake
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: 11.1.2
49
+ version: 12.0.0
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: 11.1.2
56
+ version: 12.0.0
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: nokogiri
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: 1.5.0
63
+ version: 1.7.1
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: 1.5.0
70
+ version: 1.7.1
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rdoc
73
73
  requirement: !ruby/object:Gem::Requirement
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  version: 1.3.6
142
142
  requirements: []
143
143
  rubyforge_project:
144
- rubygems_version: 2.6.8
144
+ rubygems_version: 2.6.11
145
145
  signing_key:
146
146
  specification_version: 4
147
147
  summary: Minitest JUnit XML formatter