ci-queue 0.19.0 → 0.20.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
  SHA256:
3
- metadata.gz: 436b1f0bca2725e6f532cbd4a4df9a880e6b1dd2e11a80b9587178d213fe6137
4
- data.tar.gz: 93fe3b4055e7c99e6c61af1f106e63157e79dd2fe3717d5b1cfc74e096195e9a
3
+ metadata.gz: 020e4e1012b0be90bc94deac97a2fb6e00a11aeed0c35e1cffba506145f0b2aa
4
+ data.tar.gz: 86a96759c23bacf51457b1a24c0284e40dba6904e16ac6a8bc52fdf83fd4243e
5
5
  SHA512:
6
- metadata.gz: 2bc328cd567173a875bc8273a812d2ad48ea32bad0eb0f7b0a586b279a80c4eaf08eede41a15e98d71929776dc1a5d59e7fee94b844b55a1924b3f1aa0be4272
7
- data.tar.gz: fab60979f729dd77fbf8661d8e1b644deb7e9c126a5ea27a97537e0fb960416b71c69b2b01b4123e6f19216b6a764a136079412875686c93f949a6323ebf0a63
6
+ metadata.gz: a77b0ee4af5f570ef8a398377049afdd88ce611ac9c16319decb9b627c265ef7f2efa773317e9ae04a5472d88d595471e2384fc7bfd4778c291c59d8fa79a08b
7
+ data.tar.gz: ba72651f0072f98167131617a2635b05260d343108ac4d073a5dba56bcb9e5f7980b14abe66ac10d88662967a86b8cd682d549cf8a22f37dad3b5ea94aa82018
@@ -2,7 +2,7 @@
2
2
 
3
3
  module CI
4
4
  module Queue
5
- VERSION = '0.19.0'
5
+ VERSION = '0.20.0'
6
6
  DEV_SCRIPTS_ROOT = ::File.expand_path('../../../../../redis', __FILE__)
7
7
  RELEASE_SCRIPTS_ROOT = ::File.expand_path('../redis', __FILE__)
8
8
  end
@@ -1,78 +1,106 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'minitest/reporters'
3
- require 'builder'
4
+ require 'rexml/document'
4
5
  require 'fileutils'
5
6
 
6
7
  module Minitest
7
8
  module Queue
8
9
  class JUnitReporter < Minitest::Reporters::BaseReporter
9
- class XmlMarkup < ::Builder::XmlMarkup
10
- def trunc!(txt)
11
- txt.sub(/\n.*/m, '...')
12
- end
13
- end
14
-
15
10
  def initialize(report_path = 'log/junit.xml', options = {})
16
11
  super({})
17
12
  @report_path = File.absolute_path(report_path)
18
13
  @base_path = options[:base_path] || Dir.pwd
19
14
  end
20
15
 
21
- def report
22
- super
23
-
16
+ def generate_document
24
17
  suites = tests.group_by { |test| test.klass }
25
18
 
26
- xml = Builder::XmlMarkup.new(indent: 2)
27
- xml.instruct!
28
- xml.testsuites do
29
- suites.each do |suite, tests|
30
- add_tests_to(xml, suite, tests)
31
- end
19
+ doc = REXML::Document.new
20
+ testsuites = doc.add_element('testsuites')
21
+ suites.each do |suite, tests|
22
+ add_tests_to(testsuites, suite, tests)
32
23
  end
24
+ doc
25
+ end
26
+
27
+ def format_document(doc, io)
28
+ io << "<?xml version='1.0' encoding='UTF-8'?>\n"
29
+ formatter = REXML::Formatters::Pretty.new
30
+ formatter.write(doc, io)
31
+ io << "\n"
32
+ end
33
+
34
+ def report
35
+ super
36
+
33
37
  FileUtils.mkdir_p(File.dirname(@report_path))
34
- File.open(@report_path, 'w+') { |file| file << xml.target! }
38
+ File.open(@report_path, 'w+') do |file|
39
+ format_document(generate_document, file)
40
+ end
35
41
  end
36
42
 
37
43
  private
38
44
 
39
- def add_tests_to(xml, suite, tests)
45
+ def add_tests_to(testsuites, suite, tests)
40
46
  suite_result = analyze_suite(tests)
41
- file_path = Pathname.new(tests.first.source_location.first)
42
- base_path = Pathname.new(@base_path)
43
- relative_path = file_path.relative_path_from(base_path)
44
-
45
- xml.testsuite(name: suite, filepath: relative_path,
46
- skipped: suite_result[:skip_count], failures: suite_result[:fail_count],
47
- errors: suite_result[:error_count], tests: suite_result[:test_count],
48
- assertions: suite_result[:assertion_count], time: suite_result[:time]) do
49
- tests.each do |test|
50
- lineno = test.source_location.last
51
- xml.testcase(name: test.name, lineno: lineno, classname: suite, assertions: test.assertions,
52
- time: test.time, flaky_test: test.flaked?) do
53
- xml << xml_message_for(test) unless test.passed?
54
- end
47
+ relative_path = if tests.first.source_location.first == 'unknown'
48
+ Pathname.new('')
49
+ else
50
+ file_path = Pathname.new(tests.first.source_location.first)
51
+ if file_path.relative?
52
+ file_path
53
+ else
54
+ base_path = Pathname.new(@base_path)
55
+ file_path.relative_path_from(base_path)
55
56
  end
56
57
  end
58
+
59
+ testsuite = testsuites.add_element(
60
+ 'testsuite',
61
+ 'name' => suite,
62
+ 'filepath' => relative_path,
63
+ 'skipped' => suite_result[:skip_count],
64
+ 'failures' => suite_result[:fail_count],
65
+ 'errors' => suite_result[:error_count],
66
+ 'tests' => suite_result[:test_count],
67
+ 'assertions' => suite_result[:assertion_count],
68
+ 'time' => suite_result[:time],
69
+ )
70
+
71
+ tests.each do |test|
72
+ lineno = tests.first.source_location.last
73
+ attributes = {
74
+ 'name' => test.name,
75
+ 'classname' => suite,
76
+ 'assertions' => test.assertions,
77
+ 'time' => test.time,
78
+ 'flaky_test' => test.flaked?
79
+ }
80
+ attributes['lineno'] = lineno if lineno != -1
81
+
82
+ testcase = testsuite.add_element('testcase', attributes)
83
+ add_xml_message_for(testcase, test) unless test.passed?
84
+ end
57
85
  end
58
86
 
59
- def xml_message_for(test)
60
- xml = XmlMarkup.new(indent: 2, margin: 2)
87
+ def add_xml_message_for(testcase, test)
61
88
  failure = test.failure
62
-
63
89
  if test.skipped? && !test.flaked?
64
- xml.skipped(type: failure.error.class.name)
90
+ testcase.add_element('skipped', 'type' => failure.error.class.name)
65
91
  elsif test.error?
66
- xml.error(type: failure.error.class.name, message: xml.trunc!(failure.message)) do
67
- xml.text!(message_for(test))
68
- end
92
+ error = testcase.add_element('error', 'type' => failure.error.class.name, 'message' => truncate_message(failure.message))
93
+ error.add_text(REXML::CData.new(message_for(test)))
69
94
  elsif failure
70
- xml.failure(type: failure.error.class.name, message: xml.trunc!(failure.message)) do
71
- xml.text!(message_for(test))
72
- end
95
+ failure = testcase.add_element('failure', 'type' => failure.error.class.name, 'message' => truncate_message(failure.message))
96
+ failure.add_text(REXML::CData.new(message_for(test)))
73
97
  end
74
98
  end
75
99
 
100
+ def truncate_message(message)
101
+ message.lines.first.chomp.gsub(/\e\[[^m]+m/, '')
102
+ end
103
+
76
104
  def message_for(test)
77
105
  suite = test.klass
78
106
  name = test.name
@@ -81,17 +109,17 @@ module Minitest
81
109
  if test.passed?
82
110
  nil
83
111
  elsif test.skipped?
84
- "Skipped:\n#{name}(#{suite}) [#{location(error)}]:\n#{error.message}\n"
112
+ "\nSkipped:\n#{name}(#{suite}) [#{location(error)}]:\n#{error.message}\n"
85
113
  elsif test.failure
86
- "Failure:\n#{name}(#{suite}) [#{location(error)}]:\n#{error.message}\n"
114
+ "\nFailure:\n#{name}(#{suite}) [#{location(error)}]:\n#{error.message}\n"
87
115
  elsif test.error?
88
- "Error:\n#{name}(#{suite}):\n#{error.message}"
116
+ "\nError:\n#{name}(#{suite}) [#{location(error)}]:\n#{error.message}\n"
89
117
  end
90
118
  end
91
119
 
92
120
  def location(exception)
93
121
  last_before_assertion = ''
94
- exception.backtrace.reverse_each do |s|
122
+ (exception.backtrace || []).reverse_each do |s|
95
123
  break if s =~ /in .(assert|refute|flunk|pass|fail|raise|must|wont)/
96
124
  last_before_assertion = s
97
125
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ci-queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.0
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-27 00:00:00.000000000 Z
11
+ date: 2020-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler