test-unit 3.2.5 → 3.4.7

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 (82) hide show
  1. checksums.yaml +5 -5
  2. data/BSDL +24 -0
  3. data/COPYING +41 -44
  4. data/README.md +8 -11
  5. data/Rakefile +0 -23
  6. data/doc/text/getting-started.md +1 -1
  7. data/doc/text/news.md +366 -0
  8. data/lib/test/unit/assertion-failed-error.rb +35 -0
  9. data/lib/test/unit/assertions.rb +312 -112
  10. data/lib/test/unit/attribute.rb +7 -2
  11. data/lib/test/unit/autorunner.rb +79 -31
  12. data/lib/test/unit/code-snippet-fetcher.rb +7 -7
  13. data/lib/test/unit/collector/descendant.rb +1 -0
  14. data/lib/test/unit/collector/dir.rb +4 -2
  15. data/lib/test/unit/collector/load.rb +10 -13
  16. data/lib/test/unit/collector/objectspace.rb +1 -0
  17. data/lib/test/unit/collector.rb +31 -0
  18. data/lib/test/unit/color-scheme.rb +20 -2
  19. data/lib/test/unit/data-sets.rb +116 -0
  20. data/lib/test/unit/data.rb +121 -12
  21. data/lib/test/unit/diff.rb +2 -3
  22. data/lib/test/unit/fixture.rb +6 -0
  23. data/lib/test/unit/notification.rb +9 -7
  24. data/lib/test/unit/omission.rb +34 -31
  25. data/lib/test/unit/pending.rb +12 -11
  26. data/lib/test/unit/priority.rb +7 -3
  27. data/lib/test/unit/runner/console.rb +8 -0
  28. data/lib/test/unit/test-suite-creator.rb +22 -8
  29. data/lib/test/unit/testcase.rb +216 -146
  30. data/lib/test/unit/testsuite.rb +1 -1
  31. data/lib/test/unit/ui/console/testrunner.rb +92 -32
  32. data/lib/test/unit/util/memory-usage.rb +47 -0
  33. data/lib/test/unit/util/observable.rb +2 -2
  34. data/lib/test/unit/util/output.rb +5 -4
  35. data/lib/test/unit/util/procwrapper.rb +4 -4
  36. data/lib/test/unit/version.rb +1 -1
  37. data/lib/test/unit/warning.rb +3 -0
  38. data/lib/test/unit.rb +177 -161
  39. data/lib/test-unit.rb +2 -17
  40. metadata +13 -88
  41. data/GPL +0 -339
  42. data/LGPL +0 -502
  43. data/test/collector/test-descendant.rb +0 -182
  44. data/test/collector/test-load.rb +0 -442
  45. data/test/collector/test_dir.rb +0 -407
  46. data/test/collector/test_objectspace.rb +0 -102
  47. data/test/fixtures/header-label.csv +0 -3
  48. data/test/fixtures/header-label.tsv +0 -3
  49. data/test/fixtures/header.csv +0 -3
  50. data/test/fixtures/header.tsv +0 -3
  51. data/test/fixtures/no-header.csv +0 -2
  52. data/test/fixtures/no-header.tsv +0 -2
  53. data/test/fixtures/plus.csv +0 -3
  54. data/test/run-test.rb +0 -22
  55. data/test/test-assertions.rb +0 -2180
  56. data/test/test-attribute-matcher.rb +0 -38
  57. data/test/test-attribute.rb +0 -123
  58. data/test/test-code-snippet.rb +0 -37
  59. data/test/test-color-scheme.rb +0 -82
  60. data/test/test-color.rb +0 -47
  61. data/test/test-data.rb +0 -303
  62. data/test/test-diff.rb +0 -518
  63. data/test/test-emacs-runner.rb +0 -60
  64. data/test/test-error.rb +0 -26
  65. data/test/test-failure.rb +0 -33
  66. data/test/test-fault-location-detector.rb +0 -163
  67. data/test/test-fixture.rb +0 -713
  68. data/test/test-notification.rb +0 -33
  69. data/test/test-omission.rb +0 -81
  70. data/test/test-pending.rb +0 -70
  71. data/test/test-priority.rb +0 -173
  72. data/test/test-test-case.rb +0 -1278
  73. data/test/test-test-result.rb +0 -113
  74. data/test/test-test-suite-creator.rb +0 -97
  75. data/test/test-test-suite.rb +0 -151
  76. data/test/testunit-test-util.rb +0 -31
  77. data/test/ui/test_testrunmediator.rb +0 -20
  78. data/test/util/test-method-owner-finder.rb +0 -38
  79. data/test/util/test-output.rb +0 -11
  80. data/test/util/test_backtracefilter.rb +0 -52
  81. data/test/util/test_observable.rb +0 -102
  82. data/test/util/test_procwrapper.rb +0 -36
@@ -3,7 +3,7 @@
3
3
  # Author:: Nathaniel Talbott.
4
4
  # Copyright::
5
5
  # * Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
6
- # * Copyright (c) 2008-2013 Kouhei Sutou <kou@clear-code.com>
6
+ # * Copyright (c) 2008-2017 Kouhei Sutou <kou@clear-code.com>
7
7
  # License:: Ruby license.
8
8
 
9
9
  begin
@@ -110,8 +110,10 @@ module Test
110
110
  end
111
111
 
112
112
  def finished(elapsed_time)
113
- nl if output?(NORMAL) and !output?(VERBOSE)
114
- output_faults unless @show_detail_immediately
113
+ unless @show_detail_immediately
114
+ nl if output?(NORMAL) and !output?(VERBOSE)
115
+ output_faults
116
+ end
115
117
  nl(PROGRESS_ONLY)
116
118
  change_output_level(IMPORTANT_FAULTS_ONLY) do
117
119
  output_statistics(elapsed_time)
@@ -178,21 +180,16 @@ module Test
178
180
 
179
181
  def output_fault_in_detail(fault)
180
182
  if fault.is_a?(Failure) and
181
- fault.inspected_expected and fault.inspected_actual
183
+ fault.inspected_expected and
184
+ fault.inspected_actual
182
185
  output_single("#{fault.label}: ")
183
186
  output(fault.test_name, fault_color(fault))
184
187
  output_fault_backtrace(fault)
185
188
  output_failure_message(fault)
186
189
  else
187
- if fault.is_a?(Error)
188
- output_single("#{fault.label}: ")
189
- output_single(fault.test_name, fault_color(fault))
190
- output_fault_message(fault)
191
- else
192
- output_single(fault.label, fault_color(fault))
193
- output_fault_message(fault)
194
- output(fault.test_name)
195
- end
190
+ output_single("#{fault.label}: ")
191
+ output_single(fault.test_name, fault_color(fault))
192
+ output_fault_message(fault)
196
193
  output_fault_backtrace(fault)
197
194
  end
198
195
  end
@@ -212,26 +209,38 @@ module Test
212
209
  end
213
210
 
214
211
  def output_fault_backtrace(fault)
215
- snippet_is_shown = false
216
212
  detector = FaultLocationDetector.new(fault, @code_snippet_fetcher)
217
213
  backtrace = fault.location
218
214
  # workaround for test-spec. :<
219
215
  # see also GitHub:#22
220
216
  backtrace ||= []
217
+
218
+ code_snippet_backtrace_index = nil
219
+ code_snippet_lines = nil
221
220
  backtrace.each_with_index do |entry, i|
222
- output(entry)
223
- next if snippet_is_shown
224
221
  next unless detector.target?(entry)
225
222
  file, line_number, = detector.split_backtrace_entry(entry)
226
- snippet_is_shown = output_code_snippet(file, line_number,
227
- fault_color(fault))
223
+ lines = fetch_code_snippet(file, line_number)
224
+ unless lines.empty?
225
+ code_snippet_backtrace_index = i
226
+ code_snippet_lines = lines
227
+ break
228
+ end
229
+ end
230
+
231
+ backtrace.each_with_index do |entry, i|
232
+ output(entry)
233
+ if i == code_snippet_backtrace_index
234
+ output_code_snippet(code_snippet_lines, fault_color(fault))
235
+ end
228
236
  end
229
237
  end
230
238
 
231
- def output_code_snippet(file, line_number, target_line_color=nil)
232
- lines = @code_snippet_fetcher.fetch(file, line_number)
233
- return false if lines.empty?
239
+ def fetch_code_snippet(file, line_number)
240
+ @code_snippet_fetcher.fetch(file, line_number)
241
+ end
234
242
 
243
+ def output_code_snippet(lines, target_line_color=nil)
235
244
  max_n = lines.collect {|n, line, attributes| n}.max
236
245
  digits = (Math.log10(max_n) + 1).truncate
237
246
  lines.each do |n, line, attributes|
@@ -245,7 +254,6 @@ module Test
245
254
  output(" %2s %*d: %s" % [current_line_mark, digits, n, line],
246
255
  line_color)
247
256
  end
248
- true
249
257
  end
250
258
 
251
259
  def output_failure_message(failure)
@@ -303,6 +311,7 @@ module Test
303
311
  end
304
312
 
305
313
  def output_fault_in_short(fault)
314
+ output_single("#{fault.label}: ")
306
315
  output_single(fault.message, fault_color(fault))
307
316
  output(" [#{fault.test_name}]")
308
317
  output(fault.location.first)
@@ -330,24 +339,34 @@ module Test
330
339
  end
331
340
 
332
341
  def output_summary_marker
333
- term_width = guess_term_width
334
- if term_width.zero?
335
- marker_width = 6
342
+ if @progress_row_max > 0
343
+ output("-" * @progress_row_max, summary_marker_color)
336
344
  else
337
- marker_width = term_width
345
+ nl
338
346
  end
339
- output("-" * marker_width, summary_marker_color)
340
347
  end
341
348
 
342
349
  def test_started(test)
343
350
  return unless output?(VERBOSE)
344
351
 
352
+ tab_width = 8
345
353
  name = test.local_name
346
- right_space = 8 * 2
354
+ separator = ":"
355
+ left_used = indent.size + name.size + separator.size
356
+ right_space = tab_width * 2
347
357
  left_space = @progress_row_max - right_space
348
- left_space = left_space - indent.size - name.size
349
- tab_stop = "\t" * ([left_space - 1, 0].max / 8)
350
- output_single("#{indent}#{name}:#{tab_stop}", nil, VERBOSE)
358
+ if (left_used % tab_width).zero?
359
+ left_space -= left_used
360
+ n_tabs = 0
361
+ else
362
+ left_space -= ((left_used / tab_width) + 1) * tab_width
363
+ n_tabs = 1
364
+ end
365
+ n_tabs += [left_space, 0].max / tab_width
366
+ tab_stop = "\t" * n_tabs
367
+ output_single("#{indent}#{name}#{separator}#{tab_stop}",
368
+ nil,
369
+ VERBOSE)
351
370
  @test_start = Time.now
352
371
  end
353
372
 
@@ -489,13 +508,28 @@ module Test
489
508
  color("#{@result.status}-marker")
490
509
  end
491
510
 
511
+ TERM_COLOR_SUPPORT = /
512
+ color| # explicitly claims color support in the name
513
+ direct| # explicitly claims "direct color" (24 bit) support
514
+ #{ColorScheme::TERM_256}|
515
+ \Acygwin|
516
+ \Alinux|
517
+ \Ansterm-bce|
518
+ \Ansterm-c-|
519
+ \Aputty|
520
+ \Arxvt|
521
+ \Ascreen|
522
+ \Atmux|
523
+ \Axterm
524
+ /x
525
+
492
526
  def guess_color_availability
493
527
  return false unless @output.tty?
494
528
  return true if windows? and ruby_2_0_or_later?
495
529
  case ENV["TERM"]
496
530
  when /(?:term|screen)(?:-(?:256)?color)?\z/
497
531
  true
498
- when /\Arxvt/
532
+ when TERM_COLOR_SUPPORT
499
533
  true
500
534
  else
501
535
  return true if ENV["EMACS"] == "t"
@@ -626,6 +660,7 @@ module Test
626
660
 
627
661
  def diff_line(from_line, to_line)
628
662
  to_operations = []
663
+ mark_operations = []
629
664
  from_line, to_line, _operations = line_operations(from_line, to_line)
630
665
 
631
666
  no_replace = true
@@ -655,11 +690,22 @@ module Test
655
690
  output_single(" " * (from_width - to_width))
656
691
  end
657
692
  end
693
+ mark_operations << Proc.new do
694
+ output_single("?" * from_width,
695
+ color("diff-difference-tag"))
696
+ if (to_width < from_width)
697
+ output_single(" " * (from_width - to_width))
698
+ end
699
+ end
658
700
  when :delete
659
701
  output_single(from_line[from_start...from_end],
660
702
  color("diff-deleted"))
661
703
  unless no_replace
662
704
  to_operations << Proc.new {output_single(" " * from_width)}
705
+ mark_operations << Proc.new do
706
+ output_single("-" * from_width,
707
+ color("diff-deleted"))
708
+ end
663
709
  end
664
710
  when :insert
665
711
  if no_replace
@@ -671,11 +717,16 @@ module Test
671
717
  output_single(to_line[to_start...to_end],
672
718
  color("diff-inserted"))
673
719
  end
720
+ mark_operations << Proc.new do
721
+ output_single("+" * to_width,
722
+ color("diff-inserted"))
723
+ end
674
724
  end
675
725
  when :equal
676
726
  output_single(from_line[from_start...from_end])
677
727
  unless no_replace
678
728
  to_operations << Proc.new {output_single(" " * to_width)}
729
+ mark_operations << Proc.new {output_single(" " * to_width)}
679
730
  end
680
731
  else
681
732
  raise "unknown tag: #{tag}"
@@ -691,6 +742,15 @@ module Test
691
742
  end
692
743
  output("")
693
744
  end
745
+
746
+ unless mark_operations.empty?
747
+ output_single("?", color("diff-difference-tag"))
748
+ output_single(" ")
749
+ mark_operations.each do |operation|
750
+ operation.call
751
+ end
752
+ output("")
753
+ end
694
754
  end
695
755
  end
696
756
  end
@@ -0,0 +1,47 @@
1
+ module Test
2
+ module Unit
3
+ module Util
4
+ class MemoryUsage
5
+ attr_reader :virtual
6
+ attr_reader :physical
7
+ def initialize
8
+ @virtual = nil
9
+ @physical = nil
10
+ collect_data
11
+ end
12
+
13
+ def collected?
14
+ return false if @virtual.nil?
15
+ return false if @physical.nil?
16
+ true
17
+ end
18
+
19
+ private
20
+ def collect_data
21
+ collect_data_proc
22
+ end
23
+
24
+ def collect_data_proc
25
+ status_file = "/proc/self/status"
26
+ return false unless File.exist?(status_file)
27
+
28
+ data = File.binread(status_file)
29
+ data.each_line do |line|
30
+ case line
31
+ when /\AVm(Size|RSS):\s*(\d+)\s*kB/
32
+ name = $1
33
+ value = Integer($2, 10) * 1024
34
+ case name
35
+ when "Size"
36
+ @virtual = value
37
+ when "RSS"
38
+ @physical = value
39
+ end
40
+ end
41
+ end
42
+ collected?
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -26,8 +26,8 @@ module Test
26
26
  # returned, making it very easy to use the proc
27
27
  # itself as the listener_key:
28
28
  #
29
- # listener = add_listener("Channel") { ... }
30
- # remove_listener("Channel", listener)
29
+ # listener = add_listener("Channel") { ... }
30
+ # remove_listener("Channel", listener)
31
31
  def add_listener(channel_name, listener_key=NOTHING, &listener) # :yields: value
32
32
  unless(block_given?)
33
33
  raise ArgumentError.new("No callback was passed as a listener")
@@ -7,10 +7,11 @@ module Test
7
7
  # error as string.
8
8
  #
9
9
  # Example:
10
- # capture_output do
11
- # puts("stdout")
12
- # warn("stderr")
13
- # end # -> ["stdout\n", "stderr\n"]
10
+ #
11
+ # capture_output do
12
+ # puts("stdout")
13
+ # warn("stderr")
14
+ # end # -> ["stdout\n", "stderr\n"]
14
15
  def capture_output
15
16
  require 'stringio'
16
17
 
@@ -31,10 +31,10 @@ module Test
31
31
 
32
32
  def ==(other)
33
33
  case(other)
34
- when ProcWrapper
35
- return @a_proc == other.to_proc
36
- else
37
- return super
34
+ when ProcWrapper
35
+ return @a_proc == other.to_proc
36
+ else
37
+ return super
38
38
  end
39
39
  end
40
40
  alias :eql? :==
@@ -1,5 +1,5 @@
1
1
  module Test
2
2
  module Unit
3
- VERSION = "3.2.5"
3
+ VERSION = "3.4.7"
4
4
  end
5
5
  end
@@ -0,0 +1,3 @@
1
+ if defined?(Warning) and Warning.respond_to?(:[]=)
2
+ Warning[:deprecated] = true
3
+ end