minitest_log 1.0.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 236b57c783822edbb9a07679686b08149677797e5a7a047ec73fc093185fb1ba
4
- data.tar.gz: 868cc374fad37e8da78356faa0a8d637203132964c47c8ad6b6af6d572175772
3
+ metadata.gz: 2f0a05214c679b2851776f4f5cabea520b673112759f45cb7bf8788a50887361
4
+ data.tar.gz: 1c83fcd0f14dfe379bb76a384a46369862c1be5016b24ff889edf5ef025943ce
5
5
  SHA512:
6
- metadata.gz: a671ea26b34d7aa17791d9bdef45c0162bc5bd21f1645b47ee100ff1ebfe31e4f9e8f78aecd107453e425864600f98c86f306e78cf721e6ed7ce4a39443f3eb0
7
- data.tar.gz: 07caf2ac34f7ef71875eb9167a4b55b3107004665f118d3b563b153c11f21d3b4441510b918cd199d6c60b1c19cdc070e63e31f562b935f099a7fd96229141ac
6
+ metadata.gz: 13f1b174112581541efdc28a8747914f4a426d7c6251f7e1d3f1e69755efe14dc405647bead3ac39a7a1e2f8e62f59593fbc82398dafb65dd05188a4c47e11a6
7
+ data.tar.gz: 57f373a87eb5a6a5479d18be5ec02466ed6b0e6bf31fb1befa53adcf8de21530dfe64be6acd4c6ac85b39f6b40c441fb336f14ae5284218e3ce153cbd67c8dae
data/.gitignore CHANGED
@@ -1,2 +1,4 @@
1
1
  /.idea
2
2
  /pkg/
3
+ /test/actual/
4
+
@@ -1,26 +1,26 @@
1
- PATH
2
- remote: .
3
- specs:
4
- minitest_log (1.0.0)
5
- diff-lcs (~> 1.3)
6
- minitest (~> 5.0)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- diff-lcs (1.3)
12
- markdown_helper (2.1.0)
13
- minitest (5.11.3)
14
- rake (10.5.0)
15
-
16
- PLATFORMS
17
- x64-mingw32
18
-
19
- DEPENDENCIES
20
- bundler (~> 1.7)
21
- markdown_helper (~> 2.0)
22
- minitest_log!
23
- rake (~> 10.0)
24
-
25
- BUNDLED WITH
26
- 1.17.3
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ minitest_log (1.0.1)
5
+ diff-lcs (~> 1.3)
6
+ minitest (~> 5.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.3)
12
+ markdown_helper (2.1.0)
13
+ minitest (5.11.3)
14
+ rake (10.5.0)
15
+
16
+ PLATFORMS
17
+ x64-mingw32
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.7)
21
+ markdown_helper (~> 2.0)
22
+ minitest_log!
23
+ rake (~> 10.0)
24
+
25
+ BUNDLED WITH
26
+ 1.17.3
data/README.md CHANGED
@@ -286,13 +286,13 @@ end
286
286
  ```log.xml```:
287
287
  ```xml
288
288
  <log>
289
- <section_ name='My section with timestamp' timestamp='2019-05-09-Thu-10.32.53.066'>
289
+ <section_ name='My section with timestamp' timestamp='2019-06-01-Sat-15.07.07.469'>
290
290
  Section with timestamp.
291
291
  </section_>
292
- <section_ name='My section with duration' duration_seconds='0.501'>
292
+ <section_ name='My section with duration' duration_seconds='0.503'>
293
293
  Section with duration.
294
294
  </section_>
295
- <section_ name='My section with both' timestamp='2019-05-09-Thu-10.32.53.568' duration_seconds='0.501'>
295
+ <section_ name='My section with both' timestamp='2019-06-01-Sat-15.07.07.974' duration_seconds='0.514'>
296
296
  Section with both.
297
297
  </section_>
298
298
  </log>
@@ -364,7 +364,7 @@ end
364
364
  ```xml
365
365
  <log>
366
366
  <section_ name='My unrescued section'>
367
- <uncaught_exception_ timestamp='2019-05-09-Thu-10.32.54.471' class='RuntimeError'>
367
+ <uncaught_exception_ timestamp='2019-06-01-Sat-15.07.08.960' class='RuntimeError'>
368
368
  <message_>
369
369
  Boo!
370
370
  </message_>
@@ -421,7 +421,7 @@ end
421
421
  ```log.xml```:
422
422
  ```xml
423
423
  <log>
424
- <section_ name='Section with potpourri of arguments' a='0' b='1' timestamp='2019-05-09-Thu-10.32.51.426' c='2' d='3' duration_seconds='0.501'>
424
+ <section_ name='Section with potpourri of arguments' a='0' b='1' timestamp='2019-06-01-Sat-15.07.05.791' c='2' d='3' duration_seconds='0.513'>
425
425
  Word More words
426
426
  <rescued_exception_ class='Exception' message='Boo!'>
427
427
  <backtrace_>
@@ -824,7 +824,7 @@ error_verdict.rb:9:in `test_demo'
824
824
  <verdict_ method='verdict_assert_equal?' outcome='failed' id='error_count'>
825
825
  <expected_ class='Integer' value='0'/>
826
826
  <actual_ class='Integer' value='1'/>
827
- <exception_ class='Minitest::Assertion' message='Expected: 0'>
827
+ <exception_ class='Minitest::Assertion' message='Expected: 0\n Actual: 1'>
828
828
  <backtrace_>
829
829
  <![CDATA[
830
830
  error_verdict.rb:9:in `new'
@@ -860,7 +860,7 @@ end
860
860
  ```default_backtrace_filter.xml```:
861
861
  ```xml
862
862
  <log>
863
- <uncaught_exception_ timestamp='2019-05-09-Thu-10.32.49.597' class='RuntimeError'>
863
+ <uncaught_exception_ timestamp='2019-06-01-Sat-15.07.03.608' class='RuntimeError'>
864
864
  <message_>
865
865
  Boo!
866
866
  </message_>
@@ -878,14 +878,16 @@ backtrace_filter.rb:4:in `test_demo'
878
878
  ```custom_backtrace_filter.xml```:
879
879
  ```xml
880
880
  <log>
881
- <uncaught_exception_ timestamp='2019-05-09-Thu-10.32.49.599' class='RuntimeError'>
881
+ <uncaught_exception_ timestamp='2019-06-01-Sat-15.07.03.610' class='RuntimeError'>
882
882
  <message_>
883
883
  Boo!
884
884
  </message_>
885
885
  <backtrace_>
886
886
  <![CDATA[
887
887
  backtrace_filter.rb:8:in `block in test_demo'
888
- C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/minitest_log-0.2.0/lib/minitest_log.rb:59:in `initialize'
888
+ C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/minitest_log-1.0.0/lib/minitest_log.rb:39:in `block in initialize'
889
+ C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/minitest_log-1.0.0/lib/minitest_log.rb:186:in `do_log'
890
+ C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/minitest_log-1.0.0/lib/minitest_log.rb:37:in `initialize'
889
891
  backtrace_filter.rb:7:in `new'
890
892
  backtrace_filter.rb:7:in `test_demo'
891
893
  C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/minitest-5.11.3/lib/minitest/test.rb:98:in `block (3 levels) in run'
@@ -1113,7 +1115,7 @@ end
1113
1115
  (?-mix:Bar)
1114
1116
  </data_>
1115
1117
  <data_ name='My time' class='Time' method=':to_s'>
1116
- 2019-05-09 10:32:47 -0500
1118
+ 2019-06-01 15:07:01 -0500
1117
1119
  </data_>
1118
1120
  <data_ name='My uri,' class='URI::HTTPS' method=':to_s'>
1119
1121
  https://www.github.com
@@ -1286,7 +1288,7 @@ end
1286
1288
  <verdict_ method='verdict_assert_equal?' outcome='failed' id='another_id' message='Another message'>
1287
1289
  <expected_ class='Integer' value='0'/>
1288
1290
  <actual_ class='Integer' value='1'/>
1289
- <exception_ class='Minitest::Assertion' message='Expected: 0'>
1291
+ <exception_ class='Minitest::Assertion' message='Expected: 0\n Actual: 1'>
1290
1292
  <backtrace_>
1291
1293
  <![CDATA[
1292
1294
  verdict_assert_equal.rb:6:in `block in test_demo_verdict'
@@ -1470,7 +1472,7 @@ end
1470
1472
  <verdict_ method='verdict_assert_instance_of?' outcome='failed' id='another_id' message='another message'>
1471
1473
  <expected_ class='Class' value='Integer'/>
1472
1474
  <actual_ class='String' value='&quot;my_string&quot;'/>
1473
- <exception_ class='Minitest::Assertion' message='Expected &quot;my_string&quot; to be an instance of Integer, not String.'>
1475
+ <exception_ class='Minitest::Assertion' message='Expected # encoding: UTF-8\n&quot;my_string&quot; to be an instance of Integer, not String.'>
1474
1476
  <backtrace_>
1475
1477
  <![CDATA[
1476
1478
  verdict_assert_instance_of.rb:6:in `block in test_demo_verdict'
@@ -1560,7 +1562,7 @@ end
1560
1562
  <verdict_ method='verdict_assert_match?' outcome='failed' id='another_id' message='Another message'>
1561
1563
  <expected_ class='Regexp' value='/foo/'/>
1562
1564
  <actual_ class='String' value='&quot;feed&quot;'/>
1563
- <exception_ class='Minitest::Assertion' message='Expected /foo/ to match &quot;feed&quot;.'>
1565
+ <exception_ class='Minitest::Assertion' message='Expected /foo/ to match # encoding: UTF-8\n&quot;feed&quot;.'>
1564
1566
  <backtrace_>
1565
1567
  <![CDATA[
1566
1568
  verdict_assert_match.rb:6:in `block in test_demo_verdict'
@@ -1703,7 +1705,7 @@ end
1703
1705
  <verdict_ method='verdict_assert_output?' outcome='failed' id='another_id'>
1704
1706
  <stdout_ class='String' value='&quot;Bar&quot;'/>
1705
1707
  <stderr_ class='String' value='&quot;Foo&quot;'/>
1706
- <exception_ class='Minitest::Assertion' message='In stderr.'>
1708
+ <exception_ class='Minitest::Assertion' message='In stderr.\n--- expected\n+++ actual\n@@ -1,2 +1 @@\n-# encoding: UTF-8\n-&quot;Foo&quot;\n+&quot;Bar&quot;\n'>
1707
1709
  <backtrace_>
1708
1710
  <![CDATA[
1709
1711
  verdict_assert_output.rb:9:in `block in test_demo_verdict'
@@ -1748,7 +1750,7 @@ end
1748
1750
  <verdict_ method='verdict_assert_predicate?' outcome='failed' id='another_id' message='Another message'>
1749
1751
  <object_ class='String' value='&quot;x&quot;'/>
1750
1752
  <operator_ class='Symbol' value=':empty?'/>
1751
- <exception_ class='Minitest::Assertion' message='Expected &quot;x&quot; to be empty?.'>
1753
+ <exception_ class='Minitest::Assertion' message='Expected # encoding: UTF-8\n&quot;x&quot; to be empty?.'>
1752
1754
  <backtrace_>
1753
1755
  <![CDATA[
1754
1756
  verdict_assert_predicate.rb:6:in `block in test_demo_verdict'
@@ -1795,7 +1797,7 @@ end
1795
1797
  </verdict_>
1796
1798
  <verdict_ method='verdict_assert_raises?' outcome='failed' id='another_id' message='Another message'>
1797
1799
  <error_class_ class='Class' value='RuntimeError'/>
1798
- <exception_ class='Minitest::Assertion' message='[RuntimeError] exception expected, not'>
1800
+ <exception_ class='Minitest::Assertion' message='[RuntimeError] exception expected, not\nClass: &lt;Exception&gt;\nMessage: &lt;&quot;Boo!&quot;&gt;\n---Backtrace---\nverdict_assert_raises.rb:9:in `block (2 levels) in test_demo_verdict&apos;\nC:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/minitest_log-1.0.0/lib/verdict_assertion.rb:260:in `block in verdict_assert_raises?&apos;\nC:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/minitest_log-1.0.0/lib/verdict_assertion.rb:272:in `block in _verdict_raises?&apos;\n---------------'>
1799
1801
  <backtrace_>
1800
1802
  <![CDATA[
1801
1803
  verdict_assert_raises.rb:8:in `block in test_demo_verdict'
@@ -1885,7 +1887,7 @@ end
1885
1887
  <verdict_ method='verdict_assert_same?' outcome='failed' id='another_id' message='Another message'>
1886
1888
  <expected_ class='String' value='&quot;foo&quot;'/>
1887
1889
  <actual_ class='String' value='&quot;foo&quot;'/>
1888
- <exception_ class='Minitest::Assertion' message='Expected &quot;foo&quot; (oid=27933780) to be the same as &quot;foo&quot; (oid=27933800).'>
1890
+ <exception_ class='Minitest::Assertion' message='Expected # encoding: UTF-8\n&quot;foo&quot; (oid=28462120) to be the same as # encoding: UTF-8\n&quot;foo&quot; (oid=28462140).'>
1889
1891
  <backtrace_>
1890
1892
  <![CDATA[
1891
1893
  verdict_assert_same.rb:6:in `block in test_demo_verdict'
@@ -1928,7 +1930,7 @@ end
1928
1930
  <log>
1929
1931
  <verdict_ method='verdict_assert_silent?' outcome='passed' id='one_id'/>
1930
1932
  <verdict_ method='verdict_assert_silent?' outcome='failed' id='another_id'>
1931
- <exception_ class='Minitest::Assertion' message='In stdout.'>
1933
+ <exception_ class='Minitest::Assertion' message='In stdout.\n--- expected\n+++ actual\n@@ -1,2 +1 @@\n-# encoding: UTF-8\n-&quot;&quot;\n+&quot;Foo&quot;\n'>
1932
1934
  <backtrace_>
1933
1935
  <![CDATA[
1934
1936
  verdict_assert_silent.rb:7:in `block in test_demo_verdict'
@@ -2294,7 +2296,7 @@ end
2294
2296
  <verdict_ method='verdict_refute_instance_of?' outcome='failed' id='another_id' message='another message'>
2295
2297
  <expected_ class='Class' value='String'/>
2296
2298
  <actual_ class='String' value='&quot;my_string&quot;'/>
2297
- <exception_ class='Minitest::Assertion' message='Expected &quot;my_string&quot; to not be an instance of String.'>
2299
+ <exception_ class='Minitest::Assertion' message='Expected # encoding: UTF-8\n&quot;my_string&quot; to not be an instance of String.'>
2298
2300
  <backtrace_>
2299
2301
  <![CDATA[
2300
2302
  verdict_refute_instance_of.rb:6:in `block in test_demo_verdict'
@@ -2384,7 +2386,7 @@ end
2384
2386
  <verdict_ method='verdict_refute_match?' outcome='failed' id='another_id' message='Another message'>
2385
2387
  <expected_ class='Regexp' value='/foo/'/>
2386
2388
  <actual_ class='String' value='&quot;food&quot;'/>
2387
- <exception_ class='Minitest::Assertion' message='Expected /foo/ to not match &quot;food&quot;.'>
2389
+ <exception_ class='Minitest::Assertion' message='Expected /foo/ to not match # encoding: UTF-8\n&quot;food&quot;.'>
2388
2390
  <backtrace_>
2389
2391
  <![CDATA[
2390
2392
  verdict_refute_match.rb:6:in `block in test_demo_verdict'
@@ -2519,7 +2521,7 @@ end
2519
2521
  <verdict_ method='verdict_refute_predicate?' outcome='failed' id='another_id' message='Another message'>
2520
2522
  <object_ class='String' value='&quot;&quot;'/>
2521
2523
  <operator_ class='Symbol' value=':empty?'/>
2522
- <exception_ class='Minitest::Assertion' message='Expected &quot;&quot; to not be empty?.'>
2524
+ <exception_ class='Minitest::Assertion' message='Expected # encoding: UTF-8\n&quot;&quot; to not be empty?.'>
2523
2525
  <backtrace_>
2524
2526
  <![CDATA[
2525
2527
  verdict_refute_predicate.rb:6:in `block in test_demo_verdict'
@@ -0,0 +1,9 @@
1
+ module Minitest
2
+ module Assertions
3
+ # Minitest uses a platform-dependent program for diff.
4
+ # Here, we already have diff-lcs available, so always use that.
5
+ def self.diff
6
+ 'ldiff -u 0'
7
+ end
8
+ end
9
+ end
@@ -4,9 +4,12 @@ require 'minitest/assertions'
4
4
  require 'diff/lcs'
5
5
 
6
6
  require_relative 'verdict_assertion'
7
+ require_relative 'minitest_assertions_patch'
7
8
 
8
9
  class MinitestLog
9
10
 
11
+ include REXML
12
+ include Minitest::Assertions
10
13
  include VerdictAssertion
11
14
 
12
15
  attr_accessor \
@@ -21,9 +24,6 @@ class MinitestLog
21
24
  :error_verdict,
22
25
  :summary
23
26
 
24
- include REXML
25
- include Minitest::Assertions
26
-
27
27
  class MinitestLogError < Exception; end
28
28
  class NoBlockError < MinitestLogError; end
29
29
  class DuplicateVerdictIdError < MinitestLogError; end
@@ -32,42 +32,16 @@ class MinitestLog
32
32
 
33
33
  def initialize(file_path, options=Hash.new)
34
34
  raise NoBlockError.new('No block given for MinitestLog#new.') unless (block_given?)
35
- default_options = Hash[
36
- :root_name => 'log',
37
- :xml_indentation => 2,
38
- :error_verdict => false,
39
- :summary => false
40
- ]
41
- options = default_options.merge(options)
42
- self.assertions = 0
43
35
  self.file_path = file_path
44
- self.root_name = options[:root_name]
45
- self.xml_indentation = options[:xml_indentation]
46
- self.summary = options[:summary]
47
- self.error_verdict = options[:error_verdict] || false
48
- self.backtrace_filter = options[:backtrace_filter] || /minitest/
49
- self.file = File.open(self.file_path, 'w')
50
- log_puts("REMARK\tThis text log is the precursor for an XML log.")
51
- log_puts("REMARK\tIf the logged process completes, this text will be converted to XML.")
52
- log_puts("BEGIN\t#{self.root_name}")
53
- self.counts = Hash[
54
- :verdict => 0,
55
- :failure => 0,
56
- :error => 0,
57
- ]
58
- begin
59
- yield self
60
- rescue => x
61
- put_element('uncaught_exception', :timestamp, :class => x.class) do
62
- put_element('message', x.message)
63
- put_element('backtrace') do
64
- backtrace = filter_backtrace(x.backtrace)
65
- put_pre(backtrace.join("\n"))
66
- end
36
+ handle_options(options)
37
+ do_log do
38
+ begin
39
+ yield self
40
+ rescue => x
41
+ handle_exception(x)
67
42
  end
68
43
  end
69
- dispose
70
- nil
44
+ create_xml_log
71
45
  end
72
46
 
73
47
  def section(name, *args)
@@ -90,78 +64,12 @@ class MinitestLog
90
64
  end
91
65
 
92
66
  def put_element(element_name = 'element', *args)
93
- if false ||
94
- caller[0].match(/minitest_log.rb/) ||
95
- caller[0].match(/verdict_assertion.rb/)
96
- # Make the element name special.
97
- element_name += '_'
98
- elsif element_name.end_with?('_')
99
- # Don't accept user's special.
100
- message = "Element name should not end with underscore: #{element_name}"
101
- raise IllegalElementNameError.new(message)
102
- else
103
- # Ok.
104
- end
105
- attributes = {}
106
- pcdata = ''
107
- start_time = nil
108
- duration_to_be_included = false
109
- block_to_be_rescued = false
110
- args.each do |arg|
111
- case
112
- when arg.kind_of?(Hash)
113
- attributes.merge!(arg)
114
- when arg.kind_of?(String)
115
- pcdata += arg
116
- when arg == :timestamp
117
- attributes[:timestamp] = MinitestLog.timestamp
118
- when arg == :duration
119
- duration_to_be_included = true
120
- when arg == :rescue
121
- block_to_be_rescued = true
122
- else
123
- pcdata = pcdata + arg.inspect
124
- end
125
- end
126
- log_puts("BEGIN\t#{element_name}")
127
- put_attributes(attributes)
128
- unless pcdata.empty?
129
- # Guard against using a terminator that's a substring of pcdata.
130
- s = 'EOT'
131
- terminator = s
132
- while pcdata.match(terminator) do
133
- terminator += s
134
- end
135
- log_puts("PCDATA\t<<#{terminator}")
136
- log_puts(pcdata)
137
- log_puts(terminator)
138
- end
139
- start_time = Time.new if duration_to_be_included
67
+ conditioned_element_name = condition_element_name(element_name, caller[0])
140
68
  if block_given?
141
- if block_to_be_rescued
142
- begin
143
- yield
144
- rescue Exception => x
145
- put_element('rescued_exception', {:class => x.class, :message => x.message}) do
146
- put_element('backtrace') do
147
- backtrace = filter_backtrace(x.backtrace)
148
- put_pre(backtrace.join("\n"))
149
- end
150
- end
151
- self.counts[:error] += 1
152
- end
153
- else
154
- yield
155
- end
156
- end
157
- if start_time
158
- end_time = Time.now
159
- duration_f = end_time.to_f - start_time.to_f
160
- duration_s = format('%.3f', duration_f)
161
- put_attributes({:duration_seconds => duration_s})
69
+ Element.new(self, conditioned_element_name, *args, &Proc.new)
70
+ else
71
+ Element.new(self, conditioned_element_name, *args)
162
72
  end
163
- log_puts("END\t#{element_name}")
164
- nil
165
73
  end
166
74
 
167
75
  def put_each_with_index(name, obj)
@@ -273,18 +181,34 @@ class MinitestLog
273
181
 
274
182
  private
275
183
 
276
- def dispose
184
+ def do_log
185
+ begin_log
186
+ yield
187
+ end_log
188
+ end
277
189
 
278
- # Add a verdict for the error count, if needed.
190
+ def begin_log
191
+ self.counts = Hash[
192
+ :verdict => 0,
193
+ :failure => 0,
194
+ :error => 0,
195
+ ]
196
+ self.assertions = 0
197
+ self.file = File.open(self.file_path, 'w')
198
+ log_puts("REMARK\tThis text log is the precursor for an XML log.")
199
+ log_puts("REMARK\tIf the logged process completes, this text will be converted to XML.")
200
+ log_puts("BEGIN\t#{self.root_name}")
201
+ end
202
+
203
+ def end_log
279
204
  if self.error_verdict
280
205
  verdict_assert_equal?('error_count', 0, self.counts[:error])
281
206
  end
282
-
283
- # Close the text log.
284
207
  log_puts("END\t#{self.root_name}")
285
208
  self.file.close
209
+ end
286
210
 
287
- # Create the xml log.
211
+ def create_xml_log
288
212
  document = REXML::Document.new
289
213
  File.open(self.file_path, 'r') do |file|
290
214
  element = document
@@ -374,10 +298,7 @@ class MinitestLog
374
298
  end
375
299
  if exception
376
300
  self.counts[:failure] += 1
377
- # If the encoding is not UTF-8, a string will have been added.
378
- # Remove it, so that the message is the same on all platforms.
379
- conditioned_message = exception.message.gsub("# encoding: UTF-8\n", '')
380
- put_element('exception', {:class => exception.class, :message => conditioned_message}) do
301
+ put_element('exception', {:class => exception.class, :message => exception.message}) do
381
302
  put_element('backtrace') do
382
303
  backtrace = filter_backtrace(exception.backtrace)
383
304
  put_pre(backtrace.join("\n"))
@@ -392,7 +313,7 @@ class MinitestLog
392
313
  attributes.each_pair do |name, value|
393
314
  value = case
394
315
  when value.is_a?(String)
395
- value
316
+ value.gsub("\n", "\\n")
396
317
  when value.is_a?(Symbol)
397
318
  value.to_s
398
319
  else
@@ -419,19 +340,27 @@ class MinitestLog
419
340
  nil
420
341
  end
421
342
 
422
- def put_cdata(text)
343
+ def put_cdata_or_pcdata(token, text)
423
344
  # Guard against using a terminator that's a substring of the cdata.
424
345
  s = 'EOT'
425
346
  terminator = s
426
347
  while text.match(terminator) do
427
348
  terminator += s
428
349
  end
429
- log_puts("CDATA\t<<#{terminator}")
350
+ log_puts("#{token}\t<<#{terminator}")
430
351
  log_puts(text)
431
352
  log_puts(terminator)
432
353
  nil
433
354
  end
434
355
 
356
+ def put_cdata(text)
357
+ put_cdata_or_pcdata('CDATA', text)
358
+ end
359
+
360
+ def put_pcdata(text)
361
+ put_cdata_or_pcdata('PCDATA', text)
362
+ end
363
+
435
364
  def get_assertion_outcome(verdict_id, assertion_method, *assertion_args)
436
365
  validate_verdict_id(verdict_id)
437
366
  self.counts[:verdict] += 1
@@ -471,8 +400,7 @@ class MinitestLog
471
400
  while usec_s.length < 3 do
472
401
  usec_s = '0' + usec_s
473
402
  end
474
- # noinspection RubyUnusedLocalVariable
475
- ts += ".#{usec_s}"
403
+ "#{ts}.#{usec_s}"
476
404
  end
477
405
 
478
406
  def assertion_method_for(verdict_method)
@@ -495,4 +423,160 @@ class MinitestLog
495
423
  document
496
424
  end
497
425
 
426
+ def condition_element_name(element_name, caller_0)
427
+ if caller_is_us?(caller_0)
428
+ conditioned_element_name = element_name + '_'
429
+ elsif element_name.end_with?('_')
430
+ message = "Element name should not end with underscore: #{element_name}"
431
+ raise IllegalElementNameError.new(message)
432
+ else
433
+ conditioned_element_name = element_name
434
+ end
435
+ conditioned_element_name
436
+ end
437
+
438
+ def caller_is_us?(caller_0)
439
+ caller_0.match(/minitest_log.rb/) || caller_0.match(/verdict_assertion.rb/)
440
+ end
441
+
442
+ def handle_options(options)
443
+ default_options = Hash[
444
+ :root_name => 'log',
445
+ :xml_indentation => 2,
446
+ :error_verdict => false,
447
+ :summary => false
448
+ ]
449
+ options = default_options.merge(options)
450
+ self.root_name = options[:root_name]
451
+ self.xml_indentation = options[:xml_indentation]
452
+ self.summary = options[:summary]
453
+ self.error_verdict = options[:error_verdict] || false
454
+ self.backtrace_filter = options[:backtrace_filter] || /minitest/
455
+ end
456
+
457
+ def handle_exception(x)
458
+ put_element('uncaught_exception', :timestamp, :class => x.class) do
459
+ put_element('message', x.message)
460
+ put_element('backtrace') do
461
+ backtrace = filter_backtrace(x.backtrace)
462
+ put_pre(backtrace.join("\n"))
463
+ end
464
+ end
465
+ end
466
+
467
+ class Element
468
+
469
+ attr_accessor \
470
+ :args,
471
+ :attributes,
472
+ :block_to_be_rescued,
473
+ :duration_to_be_included,
474
+ :element_name,
475
+ :log,
476
+ :pcdata,
477
+ :start_time
478
+
479
+ def initialize(log, element_name, *args)
480
+
481
+ self.log = log
482
+ self.element_name = element_name
483
+ self.args = args
484
+
485
+ self.attributes = {}
486
+ self.block_to_be_rescued = false
487
+ self.duration_to_be_included = false
488
+ self.pcdata = ''
489
+ self.start_time = nil
490
+
491
+ process_args
492
+ put_element do
493
+ put_attributes
494
+ put_pcdata
495
+ do_duration do
496
+ do_block(&Proc.new) if block_given?
497
+ end
498
+ end
499
+
500
+ end
501
+
502
+ def process_args
503
+ args.each do |arg|
504
+ case
505
+ when arg.kind_of?(Hash)
506
+ self.attributes.merge!(arg)
507
+ when arg.kind_of?(String)
508
+ self.pcdata += arg
509
+ when arg == :timestamp
510
+ self.attributes[:timestamp] = MinitestLog.timestamp
511
+ when arg == :duration
512
+ self.duration_to_be_included = true
513
+ when arg == :rescue
514
+ self.block_to_be_rescued = true
515
+ else
516
+ self.pcdata = self.pcdata + arg.inspect
517
+ end
518
+ end
519
+ end
520
+
521
+ def put_element
522
+ log_puts("BEGIN\t#{element_name}")
523
+ yield
524
+ log_puts("END\t#{element_name}")
525
+ end
526
+
527
+ def put_attributes
528
+ log_put_attributes(attributes)
529
+ end
530
+
531
+ def put_pcdata
532
+ unless pcdata.empty?
533
+ log.send(:put_pcdata, pcdata)
534
+ end
535
+ end
536
+
537
+ def do_duration
538
+ self.start_time = Time.new
539
+ yield
540
+ if duration_to_be_included
541
+ end_time = Time.now
542
+ duration_f = end_time.to_f - start_time.to_f
543
+ duration_s = format('%.3f', duration_f)
544
+ log_put_attributes({:duration_seconds => duration_s})
545
+ end
546
+ end
547
+
548
+ def do_block
549
+ if block_to_be_rescued
550
+ begin
551
+ yield
552
+ rescue Exception => x
553
+ log.put_element('rescued_exception', {:class => x.class, :message => x.message}) do
554
+ log.put_element('backtrace') do
555
+ backtrace = log_filter_backtrace(x.backtrace)
556
+ log.put_pre(backtrace.join("\n"))
557
+ end
558
+ end
559
+ log.counts[:error] += 1
560
+ end
561
+ else
562
+ yield
563
+ end
564
+ end
565
+
566
+ # The called methods are private.
567
+
568
+ def log_puts(s)
569
+ log.send(:log_puts, s)
570
+ end
571
+
572
+ def log_put_attributes(attributes)
573
+ log.send(:put_attributes, attributes)
574
+ end
575
+
576
+ def log_filter_backtrace(backtrace)
577
+ log.send(:filter_backtrace, backtrace)
578
+ end
579
+
580
+ end
581
+
498
582
  end
@@ -1,3 +1,3 @@
1
1
  class MinitestLog
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ['burdettelamar@yahoo.com']
10
10
 
11
11
  spec.summary = %q{Logging for testing with Minitest}
12
- spec.description = "Gem minitest_log uses Minitest, adding structured loging, data explication, and verdicts."
12
+ spec.description = "Gem minitest_log uses Minitest, adding structured logging, data explication, and verdicts."
13
13
  spec.homepage = "https://github.com/BurdetteLamar/minitest_log"
14
14
  spec.license = 'MIT'
15
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burdette Lamar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-09 00:00:00.000000000 Z
11
+ date: 2019-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.3'
83
- description: Gem minitest_log uses Minitest, adding structured loging, data explication,
83
+ description: Gem minitest_log uses Minitest, adding structured logging, data explication,
84
84
  and verdicts.
85
85
  email:
86
86
  - burdettelamar@yahoo.com
@@ -99,6 +99,7 @@ files:
99
99
  - lib/helpers/array_helper.rb
100
100
  - lib/helpers/hash_helper.rb
101
101
  - lib/helpers/set_helper.rb
102
+ - lib/minitest_assertions_patch.rb
102
103
  - lib/minitest_log.rb
103
104
  - lib/minitest_log/version.rb
104
105
  - lib/verdict_assertion.rb
@@ -123,8 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
124
  - !ruby/object:Gem::Version
124
125
  version: '0'
125
126
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.7.6
127
+ rubygems_version: 3.0.3
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: Logging for testing with Minitest