test-unit 2.4.5 → 2.4.6
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.
- data/README.textile +4 -0
- data/lib/test-unit.rb +1 -0
- data/lib/test/unit/autorunner.rb +1 -1
- data/lib/test/unit/code-snippet-fetcher.rb +32 -0
- data/lib/test/unit/ui/console/testrunner.rb +26 -18
- data/lib/test/unit/ui/emacs/testrunner.rb +0 -14
- data/lib/test/unit/version.rb +1 -1
- metadata +80 -59
- data/bin/testrb +0 -5
- data/lib/test/unit/runner/tap.rb +0 -8
- data/lib/test/unit/ui/tap/testrunner.rb +0 -82
- data/test/ui/test_tap.rb +0 -33
data/README.textile
CHANGED
data/lib/test-unit.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "test/unit"
|
data/lib/test/unit/autorunner.rb
CHANGED
@@ -359,6 +359,7 @@ module Test
|
|
359
359
|
def run
|
360
360
|
suite = @collector[self]
|
361
361
|
return false if suite.nil?
|
362
|
+
return true if suite.empty?
|
362
363
|
runner = @runner[self]
|
363
364
|
return false if runner.nil?
|
364
365
|
@runner_options[:color_scheme] ||= @color_scheme
|
@@ -421,5 +422,4 @@ end
|
|
421
422
|
|
422
423
|
require 'test/unit/runner/console'
|
423
424
|
require 'test/unit/runner/emacs'
|
424
|
-
require 'test/unit/runner/tap'
|
425
425
|
require 'test/unit/runner/xml'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Test
|
2
|
+
module Unit
|
3
|
+
class CodeSnippetFetcher
|
4
|
+
def initialize
|
5
|
+
@sources = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def fetch(file, line, options={})
|
9
|
+
n_context_line = options[:n_context_line] || 3
|
10
|
+
lines = source(file)
|
11
|
+
return [] if lines.nil?
|
12
|
+
min_line = [line - n_context_line, 1].max
|
13
|
+
max_line = [line + n_context_line, lines.length].min
|
14
|
+
window = min_line..max_line
|
15
|
+
window.collect do |n|
|
16
|
+
attributes = {:target_line? => (n == line)}
|
17
|
+
[n, lines[n - 1].chomp, attributes]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def source(file)
|
22
|
+
@sources[file] ||= read_source(file)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def read_source(file)
|
27
|
+
return nil unless File.exist?(file)
|
28
|
+
File.readlines(file)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -7,6 +7,7 @@
|
|
7
7
|
# License:: Ruby license.
|
8
8
|
|
9
9
|
require 'test/unit/color-scheme'
|
10
|
+
require 'test/unit/code-snippet-fetcher'
|
10
11
|
require 'test/unit/ui/testrunner'
|
11
12
|
require 'test/unit/ui/testrunnermediator'
|
12
13
|
require 'test/unit/ui/console/outputlevel'
|
@@ -44,6 +45,7 @@ module Test
|
|
44
45
|
@top_level = true
|
45
46
|
@current_output_level = NORMAL
|
46
47
|
@faults = []
|
48
|
+
@code_snippet_fetcher = CodeSnippetFetcher.new
|
47
49
|
end
|
48
50
|
|
49
51
|
private
|
@@ -181,26 +183,32 @@ module Test
|
|
181
183
|
|
182
184
|
def output_fault_backtrace(fault)
|
183
185
|
backtrace = fault.location
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
186
|
+
output(fault.test_name)
|
187
|
+
backtrace.each_with_index do |entry, i|
|
188
|
+
output(entry)
|
189
|
+
output_code_snippet(entry, fault_color(fault)) if i.zero?
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def output_code_snippet(entry, target_line_color=nil)
|
194
|
+
return unless /\A(.*):(\d+)/ =~ entry
|
195
|
+
file = $1
|
196
|
+
line = $2.to_i
|
197
|
+
lines = @code_snippet_fetcher.fetch(file, line)
|
198
|
+
max_n = lines.collect {|n, line, attributes| n}.max
|
199
|
+
digits = (Math.log10(max_n) + 1).truncate
|
200
|
+
lines.each do |n, line, attributes|
|
201
|
+
if attributes[:target_line?]
|
202
|
+
line_color = target_line_color
|
203
|
+
current_line_mark = "=>"
|
204
|
+
else
|
205
|
+
line_color = nil
|
206
|
+
current_line_mark = ""
|
202
207
|
end
|
208
|
+
output(" %2s %*d: %s" % [current_line_mark, digits, n, line],
|
209
|
+
line_color)
|
203
210
|
end
|
211
|
+
nl
|
204
212
|
end
|
205
213
|
|
206
214
|
def output_fault_message(fault)
|
@@ -22,20 +22,6 @@ module Test
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def output_fault_backtrace(fault)
|
26
|
-
backtrace = fault.location
|
27
|
-
if backtrace.size == 1
|
28
|
-
output(fault.test_name +
|
29
|
-
backtrace[0].sub(/\A(.+:\d+).*/, ' [\\1]') +
|
30
|
-
":")
|
31
|
-
else
|
32
|
-
output(fault.test_name)
|
33
|
-
backtrace.each do |entry|
|
34
|
-
output(entry)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
25
|
def format_fault_failure(failure)
|
40
26
|
if failure.location.size == 1
|
41
27
|
location = failure.location[0]
|
data/lib/test/unit/version.rb
CHANGED
metadata
CHANGED
@@ -1,79 +1,94 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-unit
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 4
|
9
|
+
- 6
|
10
|
+
version: 2.4.6
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Kouhei Sutou
|
9
14
|
- Haruka Yoshihara
|
10
15
|
autorequire:
|
11
16
|
bindir: bin
|
12
17
|
cert_chain: []
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
|
19
|
+
date: 2012-02-09 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
18
23
|
none: false
|
19
|
-
requirements:
|
20
|
-
- -
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
|
23
|
-
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
name: rake
|
24
32
|
prerelease: false
|
25
|
-
version_requirements: *7305640
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: yard
|
28
|
-
requirement: &7318880 !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
30
|
-
requirements:
|
31
|
-
- - ! '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
33
|
type: :development
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
name: jeweler
|
39
|
-
requirement: &7317320 !ruby/object:Gem::Requirement
|
34
|
+
requirement: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
37
|
none: false
|
41
|
-
requirements:
|
42
|
-
- -
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
name: yard
|
46
|
+
prerelease: false
|
45
47
|
type: :development
|
48
|
+
requirement: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
name: jeweler
|
46
60
|
prerelease: false
|
47
|
-
|
48
|
-
|
49
|
-
|
61
|
+
type: :development
|
62
|
+
requirement: *id003
|
63
|
+
description: |
|
64
|
+
Ruby 1.9.x bundles minitest not Test::Unit. Test::Unit
|
50
65
|
bundled in Ruby 1.8.x had not been improved but unbundled
|
51
|
-
|
52
66
|
Test::Unit (test-unit 2) will be improved actively.
|
53
67
|
|
54
|
-
|
55
|
-
email:
|
68
|
+
email:
|
56
69
|
- kou@cozmixng.org
|
57
70
|
- yoshihara@clear-code.com
|
58
|
-
executables:
|
59
|
-
|
71
|
+
executables: []
|
72
|
+
|
60
73
|
extensions: []
|
61
|
-
|
74
|
+
|
75
|
+
extra_rdoc_files:
|
62
76
|
- README.textile
|
63
77
|
- TODO
|
64
|
-
files:
|
78
|
+
files:
|
65
79
|
- COPYING
|
66
80
|
- GPL
|
67
81
|
- PSFL
|
68
82
|
- README.textile
|
69
83
|
- Rakefile
|
70
84
|
- TODO
|
71
|
-
-
|
85
|
+
- lib/test-unit.rb
|
72
86
|
- lib/test/unit.rb
|
73
87
|
- lib/test/unit/assertionfailederror.rb
|
74
88
|
- lib/test/unit/assertions.rb
|
75
89
|
- lib/test/unit/attribute.rb
|
76
90
|
- lib/test/unit/autorunner.rb
|
91
|
+
- lib/test/unit/code-snippet-fetcher.rb
|
77
92
|
- lib/test/unit/collector.rb
|
78
93
|
- lib/test/unit/collector/descendant.rb
|
79
94
|
- lib/test/unit/collector/dir.rb
|
@@ -94,7 +109,6 @@ files:
|
|
94
109
|
- lib/test/unit/priority.rb
|
95
110
|
- lib/test/unit/runner/console.rb
|
96
111
|
- lib/test/unit/runner/emacs.rb
|
97
|
-
- lib/test/unit/runner/tap.rb
|
98
112
|
- lib/test/unit/runner/xml.rb
|
99
113
|
- lib/test/unit/testcase.rb
|
100
114
|
- lib/test/unit/testresult.rb
|
@@ -103,7 +117,6 @@ files:
|
|
103
117
|
- lib/test/unit/ui/console/outputlevel.rb
|
104
118
|
- lib/test/unit/ui/console/testrunner.rb
|
105
119
|
- lib/test/unit/ui/emacs/testrunner.rb
|
106
|
-
- lib/test/unit/ui/tap/testrunner.rb
|
107
120
|
- lib/test/unit/ui/testrunner.rb
|
108
121
|
- lib/test/unit/ui/testrunnermediator.rb
|
109
122
|
- lib/test/unit/ui/testrunnerutilities.rb
|
@@ -143,7 +156,6 @@ files:
|
|
143
156
|
- test/test_testresult.rb
|
144
157
|
- test/test_testsuite.rb
|
145
158
|
- test/testunit-test-util.rb
|
146
|
-
- test/ui/test_tap.rb
|
147
159
|
- test/ui/test_testrunmediator.rb
|
148
160
|
- test/util/test-method-owner-finder.rb
|
149
161
|
- test/util/test-output.rb
|
@@ -151,28 +163,37 @@ files:
|
|
151
163
|
- test/util/test_observable.rb
|
152
164
|
- test/util/test_procwrapper.rb
|
153
165
|
homepage: http://test-unit.rubyforge.org/
|
154
|
-
licenses:
|
166
|
+
licenses:
|
155
167
|
- Ruby's and PSFL (lib/test/unit/diff.rb)
|
156
168
|
post_install_message:
|
157
169
|
rdoc_options: []
|
158
|
-
|
170
|
+
|
171
|
+
require_paths:
|
159
172
|
- lib
|
160
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
174
|
none: false
|
162
|
-
requirements:
|
163
|
-
- -
|
164
|
-
- !ruby/object:Gem::Version
|
165
|
-
|
166
|
-
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
hash: 3
|
179
|
+
segments:
|
180
|
+
- 0
|
181
|
+
version: "0"
|
182
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
183
|
none: false
|
168
|
-
requirements:
|
169
|
-
- -
|
170
|
-
- !ruby/object:Gem::Version
|
171
|
-
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
hash: 3
|
188
|
+
segments:
|
189
|
+
- 0
|
190
|
+
version: "0"
|
172
191
|
requirements: []
|
192
|
+
|
173
193
|
rubyforge_project: test-unit
|
174
|
-
rubygems_version: 1.8.
|
194
|
+
rubygems_version: 1.8.15
|
175
195
|
signing_key:
|
176
196
|
specification_version: 3
|
177
197
|
summary: test-unit 2 - Improved version of Test::Unit bundled in Ruby 1.8.x.
|
178
198
|
test_files: []
|
199
|
+
|
data/bin/testrb
DELETED
data/lib/test/unit/runner/tap.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
#
|
3
|
-
# Author:: Kouhei Sutou.
|
4
|
-
# Copyright:: Copyright (c) 2009-2010 Kouhei Sutou <kou@clear-code.com>.
|
5
|
-
# License:: Ruby license.
|
6
|
-
|
7
|
-
require 'test/unit/ui/testrunner'
|
8
|
-
require 'test/unit/ui/testrunnermediator'
|
9
|
-
|
10
|
-
module Test
|
11
|
-
module Unit
|
12
|
-
module UI
|
13
|
-
module Tap
|
14
|
-
|
15
|
-
# Runs a Test::Unit::TestSuite and outputs result
|
16
|
-
# as TAP format.
|
17
|
-
class TestRunner < UI::TestRunner
|
18
|
-
def initialize(suite, options={})
|
19
|
-
super
|
20
|
-
@output = @options[:output] || STDOUT
|
21
|
-
@n_tests = 0
|
22
|
-
@already_outputted = false
|
23
|
-
end
|
24
|
-
|
25
|
-
# Begins the test run.
|
26
|
-
def start
|
27
|
-
result = super
|
28
|
-
def result.passed?
|
29
|
-
true # for prove commend :<
|
30
|
-
end
|
31
|
-
result
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
def attach_to_mediator
|
36
|
-
@mediator.add_listener(TestResult::FAULT, &method(:add_fault))
|
37
|
-
@mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
|
38
|
-
@mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
|
39
|
-
@mediator.add_listener(TestCase::STARTED, &method(:test_started))
|
40
|
-
@mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
|
41
|
-
end
|
42
|
-
|
43
|
-
def add_fault(fault)
|
44
|
-
puts("not ok #{@n_tests} - #{fault.short_display}")
|
45
|
-
fault.long_display.each_line do |line|
|
46
|
-
puts("# #{line}")
|
47
|
-
end
|
48
|
-
@already_outputted = true
|
49
|
-
end
|
50
|
-
|
51
|
-
def started(result)
|
52
|
-
@result = result
|
53
|
-
puts("1..#{@suite.size}")
|
54
|
-
end
|
55
|
-
|
56
|
-
def finished(elapsed_time)
|
57
|
-
puts("# Finished in #{elapsed_time} seconds.")
|
58
|
-
@result.to_s.each_line do |line|
|
59
|
-
puts("# #{line}")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_started(name)
|
64
|
-
@n_tests += 1
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_finished(name)
|
68
|
-
unless @already_outputted
|
69
|
-
puts("ok #{@n_tests} - #{name}")
|
70
|
-
end
|
71
|
-
@already_outputted = false
|
72
|
-
end
|
73
|
-
|
74
|
-
def puts(*args)
|
75
|
-
@output.puts(*args)
|
76
|
-
@output.flush
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
data/test/ui/test_tap.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'stringio'
|
2
|
-
require 'test/unit/ui/tap/testrunner'
|
3
|
-
|
4
|
-
class TestTap < Test::Unit::TestCase
|
5
|
-
def test_run
|
6
|
-
fail_line = nil
|
7
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
8
|
-
def test_success
|
9
|
-
assert_equal(3, 1 + 2)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_fail; assert_equal(3, 1 - 2); end; fail_line = __LINE__
|
13
|
-
end
|
14
|
-
output = StringIO.new
|
15
|
-
runner = Test::Unit::UI::Tap::TestRunner.new(test_case.suite,
|
16
|
-
:output => output)
|
17
|
-
result = runner.start; start_line = __LINE__
|
18
|
-
assert_equal(<<-EOR, output.string.gsub(/[\d\.]+ seconds/, "0.001 seconds"))
|
19
|
-
1..2
|
20
|
-
not ok 1 - test_fail(): <3> expected but was
|
21
|
-
# Failure:
|
22
|
-
# test_fail()
|
23
|
-
# [#{__FILE__}:#{fail_line}:in `test_fail'
|
24
|
-
# #{__FILE__}:#{start_line}:in `test_run']:
|
25
|
-
# <3> expected but was
|
26
|
-
# <-1>.
|
27
|
-
ok 2 - test_success()
|
28
|
-
# Finished in 0.001 seconds.
|
29
|
-
# 2 tests, 2 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
|
30
|
-
EOR
|
31
|
-
assert_true(result.passed?)
|
32
|
-
end
|
33
|
-
end
|