test-unit 3.1.5 → 3.6.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 +5 -5
- data/BSDL +24 -0
- data/COPYING +41 -41
- data/README.md +24 -17
- data/Rakefile +21 -24
- data/doc/text/getting-started.md +246 -0
- data/doc/text/news.md +797 -56
- data/lib/test/unit/assertion-failed-error.rb +35 -0
- data/lib/test/unit/assertions.rb +542 -220
- data/lib/test/unit/attribute.rb +78 -4
- data/lib/test/unit/auto-runner-loader.rb +17 -0
- data/lib/test/unit/autorunner.rb +175 -78
- data/lib/test/unit/code-snippet-fetcher.rb +7 -7
- data/lib/test/unit/collector/descendant.rb +1 -0
- data/lib/test/unit/collector/dir.rb +4 -2
- data/lib/test/unit/collector/load.rb +25 -15
- data/lib/test/unit/collector/objectspace.rb +1 -0
- data/lib/test/unit/collector.rb +31 -0
- data/lib/test/unit/color-scheme.rb +29 -2
- data/lib/test/unit/data-sets.rb +127 -0
- data/lib/test/unit/data.rb +121 -12
- data/lib/test/unit/diff.rb +10 -11
- data/lib/test/unit/fixture.rb +77 -27
- data/lib/test/unit/notification.rb +9 -7
- data/lib/test/unit/omission.rb +34 -31
- data/lib/test/unit/pending.rb +12 -11
- data/lib/test/unit/priority.rb +7 -5
- data/lib/test/unit/runner/console.rb +20 -1
- data/lib/test/unit/test-suite-creator.rb +30 -9
- data/lib/test/unit/testcase.rb +349 -196
- data/lib/test/unit/testresult.rb +7 -0
- data/lib/test/unit/testsuite.rb +1 -1
- data/lib/test/unit/ui/console/testrunner.rb +171 -60
- data/lib/test/unit/ui/emacs/testrunner.rb +5 -5
- data/lib/test/unit/ui/testrunnermediator.rb +9 -7
- data/lib/test/unit/util/backtracefilter.rb +17 -5
- data/lib/test/unit/util/memory-usage.rb +47 -0
- data/lib/test/unit/util/observable.rb +2 -2
- data/lib/test/unit/util/output.rb +5 -4
- data/lib/test/unit/util/procwrapper.rb +4 -4
- data/lib/test/unit/version.rb +1 -1
- data/lib/test/unit/warning.rb +3 -0
- data/lib/test/unit.rb +177 -161
- data/lib/test-unit.rb +2 -17
- metadata +20 -94
- data/GPL +0 -339
- data/LGPL +0 -502
- data/test/collector/test-descendant.rb +0 -178
- data/test/collector/test-load.rb +0 -442
- data/test/collector/test_dir.rb +0 -406
- data/test/collector/test_objectspace.rb +0 -100
- data/test/fixtures/header-label.csv +0 -3
- data/test/fixtures/header-label.tsv +0 -3
- data/test/fixtures/header.csv +0 -3
- data/test/fixtures/header.tsv +0 -3
- data/test/fixtures/no-header.csv +0 -2
- data/test/fixtures/no-header.tsv +0 -2
- data/test/fixtures/plus.csv +0 -3
- data/test/run-test.rb +0 -22
- data/test/test-assertions.rb +0 -2157
- data/test/test-attribute-matcher.rb +0 -38
- data/test/test-attribute.rb +0 -123
- data/test/test-code-snippet.rb +0 -37
- data/test/test-color-scheme.rb +0 -82
- data/test/test-color.rb +0 -47
- data/test/test-data.rb +0 -281
- data/test/test-diff.rb +0 -518
- data/test/test-emacs-runner.rb +0 -60
- data/test/test-error.rb +0 -26
- data/test/test-failure.rb +0 -33
- data/test/test-fault-location-detector.rb +0 -163
- data/test/test-fixture.rb +0 -659
- data/test/test-notification.rb +0 -33
- data/test/test-omission.rb +0 -81
- data/test/test-pending.rb +0 -70
- data/test/test-priority.rb +0 -173
- data/test/test-test-case.rb +0 -1171
- data/test/test-test-result.rb +0 -113
- data/test/test-test-suite-creator.rb +0 -97
- data/test/test-test-suite.rb +0 -150
- data/test/testunit-test-util.rb +0 -31
- data/test/ui/test_testrunmediator.rb +0 -20
- data/test/util/test-method-owner-finder.rb +0 -38
- data/test/util/test-output.rb +0 -11
- data/test/util/test_backtracefilter.rb +0 -41
- data/test/util/test_observable.rb +0 -102
- data/test/util/test_procwrapper.rb +0 -36
data/lib/test/unit/testresult.rb
CHANGED
@@ -38,12 +38,15 @@ module Test
|
|
38
38
|
|
39
39
|
attr_reader :run_count, :pass_count, :assertion_count, :faults
|
40
40
|
|
41
|
+
attr_accessor :stop_tag
|
42
|
+
|
41
43
|
# Constructs a new, empty TestResult.
|
42
44
|
def initialize
|
43
45
|
@run_count, @pass_count, @assertion_count = 0, 0, 0
|
44
46
|
@summary_generators = []
|
45
47
|
@problem_checkers = []
|
46
48
|
@faults = []
|
49
|
+
@stop_tag = nil
|
47
50
|
initialize_containers
|
48
51
|
end
|
49
52
|
|
@@ -92,6 +95,10 @@ module Test
|
|
92
95
|
end
|
93
96
|
end
|
94
97
|
|
98
|
+
def stop
|
99
|
+
throw @stop_tag
|
100
|
+
end
|
101
|
+
|
95
102
|
def to_s
|
96
103
|
summary
|
97
104
|
end
|
data/lib/test/unit/testsuite.rb
CHANGED
@@ -77,7 +77,7 @@ module Test
|
|
77
77
|
@tests -= tests
|
78
78
|
end
|
79
79
|
|
80
|
-
#
|
80
|
+
# Returns the rolled up number of tests in this suite;
|
81
81
|
# i.e. if the suite contains other suites, it counts the
|
82
82
|
# tests within those suites, not the suites themselves.
|
83
83
|
def size
|
@@ -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-
|
6
|
+
# * Copyright (c) 2008-2023 Sutou Kouhei <kou@clear-code.com>
|
7
7
|
# License:: Ruby license.
|
8
8
|
|
9
9
|
begin
|
@@ -36,12 +36,15 @@ module Test
|
|
36
36
|
# STDOUT.
|
37
37
|
def initialize(suite, options={})
|
38
38
|
super
|
39
|
-
@output_level = @options[:output_level] ||
|
39
|
+
@output_level = @options[:output_level] || guess_output_level
|
40
40
|
@output = @options[:output] || STDOUT
|
41
41
|
@use_color = @options[:use_color]
|
42
42
|
@use_color = guess_color_availability if @use_color.nil?
|
43
43
|
@color_scheme = @options[:color_scheme] || ColorScheme.default
|
44
44
|
@reset_color = Color.new("reset")
|
45
|
+
@progress_style = @options[:progress_style] || guess_progress_style
|
46
|
+
@progress_marks = ["|", "/", "-", "\\", "|", "/", "-", "\\"]
|
47
|
+
@progress_mark_index = 0
|
45
48
|
@progress_row = 0
|
46
49
|
@progress_row_max = @options[:progress_row_max]
|
47
50
|
@progress_row_max ||= guess_progress_row_max
|
@@ -110,12 +113,17 @@ module Test
|
|
110
113
|
end
|
111
114
|
|
112
115
|
def finished(elapsed_time)
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
116
|
+
unless @show_detail_immediately
|
117
|
+
nl if output?(NORMAL) and !output?(VERBOSE)
|
118
|
+
output_faults
|
119
|
+
end
|
120
|
+
case @progress_style
|
121
|
+
when :inplace
|
122
|
+
output_single("\r", nil, PROGRESS_ONLY)
|
123
|
+
when :mark
|
124
|
+
nl(PROGRESS_ONLY)
|
118
125
|
end
|
126
|
+
output_statistics(elapsed_time)
|
119
127
|
end
|
120
128
|
|
121
129
|
def output_faults
|
@@ -178,21 +186,16 @@ module Test
|
|
178
186
|
|
179
187
|
def output_fault_in_detail(fault)
|
180
188
|
if fault.is_a?(Failure) and
|
181
|
-
fault.inspected_expected and
|
189
|
+
fault.inspected_expected and
|
190
|
+
fault.inspected_actual
|
182
191
|
output_single("#{fault.label}: ")
|
183
192
|
output(fault.test_name, fault_color(fault))
|
184
193
|
output_fault_backtrace(fault)
|
185
194
|
output_failure_message(fault)
|
186
195
|
else
|
187
|
-
|
188
|
-
|
189
|
-
|
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
|
196
|
+
output_single("#{fault.label}: ")
|
197
|
+
output_single(fault.test_name, fault_color(fault))
|
198
|
+
output_fault_message(fault)
|
196
199
|
output_fault_backtrace(fault)
|
197
200
|
end
|
198
201
|
end
|
@@ -212,26 +215,38 @@ module Test
|
|
212
215
|
end
|
213
216
|
|
214
217
|
def output_fault_backtrace(fault)
|
215
|
-
snippet_is_shown = false
|
216
218
|
detector = FaultLocationDetector.new(fault, @code_snippet_fetcher)
|
217
219
|
backtrace = fault.location
|
218
220
|
# workaround for test-spec. :<
|
219
221
|
# see also GitHub:#22
|
220
222
|
backtrace ||= []
|
223
|
+
|
224
|
+
code_snippet_backtrace_index = nil
|
225
|
+
code_snippet_lines = nil
|
221
226
|
backtrace.each_with_index do |entry, i|
|
222
|
-
output(entry)
|
223
|
-
next if snippet_is_shown
|
224
227
|
next unless detector.target?(entry)
|
225
228
|
file, line_number, = detector.split_backtrace_entry(entry)
|
226
|
-
|
227
|
-
|
229
|
+
lines = fetch_code_snippet(file, line_number)
|
230
|
+
unless lines.empty?
|
231
|
+
code_snippet_backtrace_index = i
|
232
|
+
code_snippet_lines = lines
|
233
|
+
break
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
backtrace.each_with_index do |entry, i|
|
238
|
+
output(entry)
|
239
|
+
if i == code_snippet_backtrace_index
|
240
|
+
output_code_snippet(code_snippet_lines, fault_color(fault))
|
241
|
+
end
|
228
242
|
end
|
229
243
|
end
|
230
244
|
|
231
|
-
def
|
232
|
-
|
233
|
-
|
245
|
+
def fetch_code_snippet(file, line_number)
|
246
|
+
@code_snippet_fetcher.fetch(file, line_number)
|
247
|
+
end
|
234
248
|
|
249
|
+
def output_code_snippet(lines, target_line_color=nil)
|
235
250
|
max_n = lines.collect {|n, line, attributes| n}.max
|
236
251
|
digits = (Math.log10(max_n) + 1).truncate
|
237
252
|
lines.each do |n, line, attributes|
|
@@ -245,7 +260,6 @@ module Test
|
|
245
260
|
output(" %2s %*d: %s" % [current_line_mark, digits, n, line],
|
246
261
|
line_color)
|
247
262
|
end
|
248
|
-
true
|
249
263
|
end
|
250
264
|
|
251
265
|
def output_failure_message(failure)
|
@@ -303,6 +317,7 @@ module Test
|
|
303
317
|
end
|
304
318
|
|
305
319
|
def output_fault_in_short(fault)
|
320
|
+
output_single("#{fault.label}: ")
|
306
321
|
output_single(fault.message, fault_color(fault))
|
307
322
|
output(" [#{fault.test_name}]")
|
308
323
|
output(fault.location.first)
|
@@ -313,9 +328,13 @@ module Test
|
|
313
328
|
end
|
314
329
|
|
315
330
|
def output_statistics(elapsed_time)
|
316
|
-
|
331
|
+
change_output_level(IMPORTANT_FAULTS_ONLY) do
|
332
|
+
output("Finished in #{elapsed_time} seconds.")
|
333
|
+
end
|
317
334
|
output_summary_marker
|
318
|
-
|
335
|
+
change_output_level(IMPORTANT_FAULTS_ONLY) do
|
336
|
+
output(@result)
|
337
|
+
end
|
319
338
|
output("%g%% passed" % @result.pass_percentage)
|
320
339
|
unless elapsed_time.zero?
|
321
340
|
output_summary_marker
|
@@ -330,30 +349,45 @@ module Test
|
|
330
349
|
end
|
331
350
|
|
332
351
|
def output_summary_marker
|
333
|
-
|
334
|
-
|
335
|
-
marker_width = 6
|
336
|
-
else
|
337
|
-
marker_width = term_width
|
338
|
-
end
|
339
|
-
output("-" * marker_width, summary_marker_color)
|
352
|
+
return if @progress_row_max <= 0
|
353
|
+
output("-" * @progress_row_max, summary_marker_color)
|
340
354
|
end
|
341
355
|
|
342
356
|
def test_started(test)
|
343
357
|
return unless output?(VERBOSE)
|
344
358
|
|
345
|
-
|
346
|
-
|
359
|
+
tab_width = 8
|
360
|
+
name = test.local_name
|
361
|
+
separator = ":"
|
362
|
+
left_used = indent.size + name.size + separator.size
|
363
|
+
right_space = tab_width * 2
|
347
364
|
left_space = @progress_row_max - right_space
|
348
|
-
|
349
|
-
|
350
|
-
|
365
|
+
if (left_used % tab_width).zero?
|
366
|
+
left_space -= left_used
|
367
|
+
n_tabs = 0
|
368
|
+
else
|
369
|
+
left_space -= ((left_used / tab_width) + 1) * tab_width
|
370
|
+
n_tabs = 1
|
371
|
+
end
|
372
|
+
n_tabs += [left_space, 0].max / tab_width
|
373
|
+
tab_stop = "\t" * n_tabs
|
374
|
+
output_single("#{indent}#{name}#{separator}#{tab_stop}",
|
375
|
+
nil,
|
376
|
+
VERBOSE)
|
351
377
|
@test_start = Time.now
|
352
378
|
end
|
353
379
|
|
354
380
|
def test_finished(test)
|
355
381
|
unless @already_outputted
|
356
|
-
|
382
|
+
case @progress_style
|
383
|
+
when :inplace
|
384
|
+
mark = @progress_marks[@progress_mark_index]
|
385
|
+
@progress_mark_index =
|
386
|
+
(@progress_mark_index + 1) % @progress_marks.size
|
387
|
+
output_progress(mark, color("pass-marker"))
|
388
|
+
when :mark
|
389
|
+
output_progress(".", color("pass-marker"))
|
390
|
+
end
|
357
391
|
end
|
358
392
|
@already_outputted = false
|
359
393
|
|
@@ -416,18 +450,24 @@ module Test
|
|
416
450
|
|
417
451
|
def output_single(something, color=nil, level=nil)
|
418
452
|
return false unless output?(level)
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
453
|
+
something.to_s.each_line do |line|
|
454
|
+
if @use_color and color
|
455
|
+
line = "%s%s%s" % [color.escape_sequence,
|
456
|
+
line,
|
457
|
+
@reset_color.escape_sequence]
|
458
|
+
end
|
459
|
+
@output.write(line)
|
423
460
|
end
|
424
|
-
@output.write(something)
|
425
461
|
@output.flush
|
426
462
|
true
|
427
463
|
end
|
428
464
|
|
429
465
|
def output_progress(mark, color=nil)
|
430
|
-
if
|
466
|
+
if @progress_style == :inplace
|
467
|
+
output_single("\r#{mark}", color, PROGRESS_ONLY)
|
468
|
+
else
|
469
|
+
return unless output?(PROGRESS_ONLY)
|
470
|
+
output_single(mark, color)
|
431
471
|
return unless @progress_row_max > 0
|
432
472
|
@progress_row += mark.size
|
433
473
|
if @progress_row >= @progress_row_max
|
@@ -438,24 +478,29 @@ module Test
|
|
438
478
|
end
|
439
479
|
|
440
480
|
def output_progress_in_detail_marker(fault)
|
441
|
-
if @progress_row_max
|
442
|
-
|
443
|
-
else
|
444
|
-
nl
|
445
|
-
end
|
481
|
+
return if @progress_row_max <= 0
|
482
|
+
output("=" * @progress_row_max)
|
446
483
|
end
|
447
484
|
|
448
485
|
def output_progress_in_detail(fault)
|
449
486
|
return if @output_level == SILENT
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
output_fault_in_detail(fault)
|
487
|
+
need_detail_faults = (categorize_fault(fault) == :need_detail_faults)
|
488
|
+
if need_detail_faults
|
489
|
+
log_level = IMPORTANT_FAULTS_ONLY
|
454
490
|
else
|
455
|
-
|
491
|
+
log_level = @current_output_level
|
492
|
+
end
|
493
|
+
change_output_level(log_level) do
|
494
|
+
nl(NORMAL)
|
495
|
+
output_progress_in_detail_marker(fault)
|
496
|
+
if need_detail_faults
|
497
|
+
output_fault_in_detail(fault)
|
498
|
+
else
|
499
|
+
output_fault_in_short(fault)
|
500
|
+
end
|
501
|
+
output_progress_in_detail_marker(fault)
|
502
|
+
@progress_row = 0
|
456
503
|
end
|
457
|
-
output_progress_in_detail_marker(fault)
|
458
|
-
@progress_row = 0
|
459
504
|
end
|
460
505
|
|
461
506
|
def output?(level)
|
@@ -473,8 +518,12 @@ module Test
|
|
473
518
|
fault_class.name.split(/::/).last.downcase
|
474
519
|
end
|
475
520
|
|
521
|
+
def fault_class_color(fault_class)
|
522
|
+
color(fault_class_color_name(fault_class))
|
523
|
+
end
|
524
|
+
|
476
525
|
def fault_color(fault)
|
477
|
-
|
526
|
+
fault_class_color(fault.class)
|
478
527
|
end
|
479
528
|
|
480
529
|
def fault_marker_color(fault)
|
@@ -485,18 +534,54 @@ module Test
|
|
485
534
|
color("#{@result.status}-marker")
|
486
535
|
end
|
487
536
|
|
537
|
+
def guess_output_level
|
538
|
+
if ENV["GITHUB_ACTIONS"] == "true"
|
539
|
+
IMPORTANT_FAULTS_ONLY
|
540
|
+
else
|
541
|
+
NORMAL
|
542
|
+
end
|
543
|
+
end
|
544
|
+
|
545
|
+
TERM_COLOR_SUPPORT = /
|
546
|
+
color| # explicitly claims color support in the name
|
547
|
+
direct| # explicitly claims "direct color" (24 bit) support
|
548
|
+
#{ColorScheme::TERM_256}|
|
549
|
+
\Acygwin|
|
550
|
+
\Alinux|
|
551
|
+
\Ansterm-bce|
|
552
|
+
\Ansterm-c-|
|
553
|
+
\Aputty|
|
554
|
+
\Arxvt|
|
555
|
+
\Ascreen|
|
556
|
+
\Atmux|
|
557
|
+
\Axterm
|
558
|
+
/x
|
559
|
+
|
488
560
|
def guess_color_availability
|
561
|
+
return true if ENV["GITHUB_ACTIONS"] == "true"
|
489
562
|
return false unless @output.tty?
|
490
563
|
return true if windows? and ruby_2_0_or_later?
|
491
564
|
case ENV["TERM"]
|
492
565
|
when /(?:term|screen)(?:-(?:256)?color)?\z/
|
493
566
|
true
|
567
|
+
when TERM_COLOR_SUPPORT
|
568
|
+
true
|
494
569
|
else
|
495
570
|
return true if ENV["EMACS"] == "t"
|
496
571
|
false
|
497
572
|
end
|
498
573
|
end
|
499
574
|
|
575
|
+
def guess_progress_style
|
576
|
+
if @output_level >= VERBOSE
|
577
|
+
:mark
|
578
|
+
else
|
579
|
+
return :fault_only if ENV["GITHUB_ACTIONS"] == "true"
|
580
|
+
return :fault_only unless @output.tty?
|
581
|
+
:inplace
|
582
|
+
end
|
583
|
+
end
|
584
|
+
|
500
585
|
def windows?
|
501
586
|
/mswin|mingw/ === RUBY_PLATFORM
|
502
587
|
end
|
@@ -620,6 +705,7 @@ module Test
|
|
620
705
|
|
621
706
|
def diff_line(from_line, to_line)
|
622
707
|
to_operations = []
|
708
|
+
mark_operations = []
|
623
709
|
from_line, to_line, _operations = line_operations(from_line, to_line)
|
624
710
|
|
625
711
|
no_replace = true
|
@@ -649,11 +735,22 @@ module Test
|
|
649
735
|
output_single(" " * (from_width - to_width))
|
650
736
|
end
|
651
737
|
end
|
738
|
+
mark_operations << Proc.new do
|
739
|
+
output_single("?" * from_width,
|
740
|
+
color("diff-difference-tag"))
|
741
|
+
if (to_width < from_width)
|
742
|
+
output_single(" " * (from_width - to_width))
|
743
|
+
end
|
744
|
+
end
|
652
745
|
when :delete
|
653
746
|
output_single(from_line[from_start...from_end],
|
654
747
|
color("diff-deleted"))
|
655
748
|
unless no_replace
|
656
749
|
to_operations << Proc.new {output_single(" " * from_width)}
|
750
|
+
mark_operations << Proc.new do
|
751
|
+
output_single("-" * from_width,
|
752
|
+
color("diff-deleted"))
|
753
|
+
end
|
657
754
|
end
|
658
755
|
when :insert
|
659
756
|
if no_replace
|
@@ -665,11 +762,16 @@ module Test
|
|
665
762
|
output_single(to_line[to_start...to_end],
|
666
763
|
color("diff-inserted"))
|
667
764
|
end
|
765
|
+
mark_operations << Proc.new do
|
766
|
+
output_single("+" * to_width,
|
767
|
+
color("diff-inserted"))
|
768
|
+
end
|
668
769
|
end
|
669
770
|
when :equal
|
670
771
|
output_single(from_line[from_start...from_end])
|
671
772
|
unless no_replace
|
672
773
|
to_operations << Proc.new {output_single(" " * to_width)}
|
774
|
+
mark_operations << Proc.new {output_single(" " * to_width)}
|
673
775
|
end
|
674
776
|
else
|
675
777
|
raise "unknown tag: #{tag}"
|
@@ -685,6 +787,15 @@ module Test
|
|
685
787
|
end
|
686
788
|
output("")
|
687
789
|
end
|
790
|
+
|
791
|
+
unless mark_operations.empty?
|
792
|
+
output_single("?", color("diff-difference-tag"))
|
793
|
+
output_single(" ")
|
794
|
+
mark_operations.each do |operation|
|
795
|
+
operation.call
|
796
|
+
end
|
797
|
+
output("")
|
798
|
+
end
|
688
799
|
end
|
689
800
|
end
|
690
801
|
end
|
@@ -30,16 +30,16 @@ module Test
|
|
30
30
|
location_display = "\n" + failure.location.join("\n")
|
31
31
|
end
|
32
32
|
result = "#{failure.label}:\n"
|
33
|
-
result
|
34
|
-
result
|
33
|
+
result += "#{failure.test_name}#{location_display}:\n"
|
34
|
+
result += failure.message
|
35
35
|
result
|
36
36
|
end
|
37
37
|
|
38
38
|
def format_fault_error(error)
|
39
39
|
result = "#{error.label}:\n"
|
40
|
-
result
|
41
|
-
result
|
42
|
-
result
|
40
|
+
result += "#{error.test_name}:\n"
|
41
|
+
result += "#{error.message}\n"
|
42
|
+
result += error.backtrace.join("\n")
|
43
43
|
result
|
44
44
|
end
|
45
45
|
end
|
@@ -4,7 +4,6 @@
|
|
4
4
|
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
5
5
|
# License:: Ruby license.
|
6
6
|
|
7
|
-
require 'test/unit'
|
8
7
|
require 'test/unit/util/observable'
|
9
8
|
require 'test/unit/testresult'
|
10
9
|
|
@@ -18,9 +17,9 @@ module Test
|
|
18
17
|
RESET = name + "::RESET"
|
19
18
|
STARTED = name + "::STARTED"
|
20
19
|
FINISHED = name + "::FINISHED"
|
21
|
-
|
20
|
+
|
22
21
|
include Util::Observable
|
23
|
-
|
22
|
+
|
24
23
|
# Creates a new TestRunnerMediator initialized to run
|
25
24
|
# the passed suite.
|
26
25
|
def initialize(suite)
|
@@ -37,11 +36,14 @@ module Test
|
|
37
36
|
Test::Unit.run_at_start_hooks
|
38
37
|
start_time = Time.now
|
39
38
|
begin
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
catch do |stop_tag|
|
40
|
+
result.stop_tag = stop_tag
|
41
|
+
with_listener(result) do
|
42
|
+
notify_listeners(RESET, @suite.size)
|
43
|
+
notify_listeners(STARTED, result)
|
43
44
|
|
44
|
-
|
45
|
+
run_suite(result)
|
46
|
+
end
|
45
47
|
end
|
46
48
|
ensure
|
47
49
|
elapsed_time = Time.now - start_time
|
@@ -1,3 +1,8 @@
|
|
1
|
+
begin
|
2
|
+
require 'power_assert'
|
3
|
+
rescue LoadError, SyntaxError
|
4
|
+
end
|
5
|
+
|
1
6
|
module Test
|
2
7
|
module Unit
|
3
8
|
module Util
|
@@ -6,21 +11,28 @@ module Test
|
|
6
11
|
TESTUNIT_PREFIX = __FILE__.split(TESTUNIT_FILE_SEPARATORS)[0..-3]
|
7
12
|
TESTUNIT_RB_FILE = /\.rb\Z/
|
8
13
|
|
14
|
+
POWERASSERT_PREFIX =
|
15
|
+
defined?(::PowerAssert) ?
|
16
|
+
::PowerAssert.method(:start).source_location[0].split(TESTUNIT_FILE_SEPARATORS)[0..-2] :
|
17
|
+
nil
|
18
|
+
|
9
19
|
module_function
|
10
20
|
def filter_backtrace(backtrace, prefix=nil)
|
11
21
|
return ["No backtrace"] unless backtrace
|
12
22
|
return backtrace if ENV["TEST_UNIT_ALL_BACKTRACE"]
|
13
23
|
|
14
24
|
if prefix
|
15
|
-
|
25
|
+
split_prefixes = [prefix.split(TESTUNIT_FILE_SEPARATORS)]
|
16
26
|
else
|
17
|
-
|
27
|
+
split_prefixes = [TESTUNIT_PREFIX, POWERASSERT_PREFIX].compact
|
18
28
|
end
|
19
29
|
test_unit_internal_p = lambda do |entry|
|
20
30
|
components = entry.split(TESTUNIT_FILE_SEPARATORS)
|
21
|
-
|
22
|
-
|
23
|
-
|
31
|
+
split_prefixes.any? do |split_prefix|
|
32
|
+
split_entry = components[0, split_prefix.size]
|
33
|
+
next false unless split_entry[0..-2] == split_prefix[0..-2]
|
34
|
+
split_entry[-1].sub(TESTUNIT_RB_FILE, '') == split_prefix[-1]
|
35
|
+
end
|
24
36
|
end
|
25
37
|
|
26
38
|
in_user_code = false
|
@@ -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
|
-
#
|
30
|
-
#
|
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
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
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
|
|
data/lib/test/unit/version.rb
CHANGED