test 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- metadata +36 -112
- data/.gemspec +0 -152
- data/.gitignore +0 -7
- data/.ruby +0 -46
- data/.test +0 -11
- data/.yardopts +0 -7
- data/Assembly +0 -46
- data/COPYING.rdoc +0 -31
- data/HISTORY.md +0 -29
- data/LICENSE.txt +0 -25
- data/MANIFEST +0 -37
- data/PROFILE +0 -31
- data/README.md +0 -110
- data/VERSION +0 -1
- data/bin/ruby-test +0 -4
- data/lib/test.rb +0 -3
- data/lib/test/autorun.rb +0 -18
- data/lib/test/cli.rb +0 -110
- data/lib/test/code_snippet.rb +0 -93
- data/lib/test/config.rb +0 -72
- data/lib/test/core_ext.rb +0 -9
- data/lib/test/core_ext/assertion.rb +0 -30
- data/lib/test/core_ext/exception.rb +0 -8
- data/lib/test/core_ext/string.rb +0 -30
- data/lib/test/rake.rb +0 -124
- data/lib/test/recorder.rb +0 -53
- data/lib/test/reporters/abstract.rb +0 -268
- data/lib/test/reporters/abstract_hash.rb +0 -224
- data/lib/test/reporters/dotprogress.rb +0 -89
- data/lib/test/reporters/html.rb +0 -155
- data/lib/test/reporters/outline.rb +0 -211
- data/lib/test/reporters/progress.rb +0 -197
- data/lib/test/reporters/summary.rb +0 -145
- data/lib/test/reporters/tap.rb +0 -61
- data/lib/test/reporters/tapj.rb +0 -53
- data/lib/test/reporters/tapy.rb +0 -53
- data/lib/test/reporters/test.rb +0 -51
- data/lib/test/runner.rb +0 -342
- data/site/assets/images/test_pattern.jpg +0 -0
- data/site/index.html +0 -77
- data/spec/01_test.md +0 -29
- data/spec/02_case.md +0 -34
- data/spec/applique/ruby-test.rb +0 -2
- data/test/basic_case.rb +0 -11
- data/try/raw_example.rb +0 -41
- data/work/NOTES.md +0 -17
data/lib/test/config.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
module Test
|
2
|
-
|
3
|
-
#
|
4
|
-
def self.run(name=:default, &block)
|
5
|
-
@config ||= {}
|
6
|
-
@config[name.to_s] = block
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.config
|
10
|
-
@config ||= {}
|
11
|
-
end
|
12
|
-
|
13
|
-
#
|
14
|
-
class Config
|
15
|
-
|
16
|
-
# Test configuration file.
|
17
|
-
#
|
18
|
-
# The name of the file is an ode to the original Ruby cli test tool.
|
19
|
-
#
|
20
|
-
# @example
|
21
|
-
# .test
|
22
|
-
# .testrb
|
23
|
-
# .test.rb
|
24
|
-
# .config/test.rb
|
25
|
-
#
|
26
|
-
GLOB_RC = '{.testrb,.test.rb,.test,.config/test.rb,config/test.rb}'
|
27
|
-
|
28
|
-
#
|
29
|
-
GLOB_ROOT = '{.ruby,.git,.hg}'
|
30
|
-
|
31
|
-
#
|
32
|
-
def self.load
|
33
|
-
super(rc_file) if rc_file
|
34
|
-
end
|
35
|
-
|
36
|
-
# Find rc file.
|
37
|
-
def self.rc_file
|
38
|
-
@rc_file ||= (
|
39
|
-
glob = GLOB_RC
|
40
|
-
stop = root
|
41
|
-
default = nil
|
42
|
-
dir = Dir.pwd
|
43
|
-
file = nil
|
44
|
-
loop do
|
45
|
-
file = Dir[File.join(dir, glob)].first
|
46
|
-
break file if file
|
47
|
-
break if dir == stop
|
48
|
-
dir = File.dirname(dir)
|
49
|
-
break if dir == '/'
|
50
|
-
end
|
51
|
-
file ? file : default
|
52
|
-
)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Find project root.
|
56
|
-
def self.root
|
57
|
-
@root ||= (
|
58
|
-
glob = GLOB_ROOT
|
59
|
-
stop = '/'
|
60
|
-
default = Dir.pwd
|
61
|
-
dir = Dir.pwd
|
62
|
-
until dir == stop
|
63
|
-
break dir if Dir[File.join(dir, glob)].first
|
64
|
-
dir = File.dirname(dir)
|
65
|
-
end
|
66
|
-
dir == stop ? default : dir
|
67
|
-
)
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
data/lib/test/core_ext.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
class Assertion < Exception
|
2
|
-
|
3
|
-
# New assertion (failure).
|
4
|
-
#
|
5
|
-
# @param message [String] the failure message
|
6
|
-
# @param options [Hash] options such as :backtrace
|
7
|
-
#
|
8
|
-
def initialize(message=nil, options={})
|
9
|
-
super(message)
|
10
|
-
backtrace = options[:backtrace]
|
11
|
-
set_backtrace(backtrace) if backtrace
|
12
|
-
@assertion = true
|
13
|
-
end
|
14
|
-
|
15
|
-
# Technically any object that affirmatively responds to #assertion?
|
16
|
-
# can be taken to be an Assertion. This makes it easier for various
|
17
|
-
# libraries to work together without having to depend upon a common
|
18
|
-
# Assertion base class.
|
19
|
-
def assertion?
|
20
|
-
true # @assertion
|
21
|
-
end
|
22
|
-
|
23
|
-
# Parents error message prefixed with "(assertion)".
|
24
|
-
#
|
25
|
-
# @return [String] error message
|
26
|
-
def to_s
|
27
|
-
'(assertion) ' + super
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
data/lib/test/core_ext/string.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
# Preserves relative tabbing.
|
4
|
-
# The first non-empty line ends up with n spaces before nonspace.
|
5
|
-
#
|
6
|
-
# This is a Ruby Facet (http://rubyworks.github.com/facets).
|
7
|
-
|
8
|
-
def tabto(n)
|
9
|
-
if self =~ /^( *)\S/
|
10
|
-
indent(n - $1.length)
|
11
|
-
else
|
12
|
-
self
|
13
|
-
end
|
14
|
-
end unless method_defined?(:tabto)
|
15
|
-
|
16
|
-
# Indent left or right by n spaces.
|
17
|
-
# (This used to be called #tab and aliased as #indent.)
|
18
|
-
#
|
19
|
-
# This is a Ruby Facet (http://rubyworks.github.com/facets).
|
20
|
-
|
21
|
-
def indent(n, c=' ')
|
22
|
-
if n >= 0
|
23
|
-
gsub(/^/, c * n)
|
24
|
-
else
|
25
|
-
gsub(/^#{Regexp.escape(c)}{0,#{-n}}/, "")
|
26
|
-
end
|
27
|
-
end unless method_defined?(:indent)
|
28
|
-
|
29
|
-
end
|
30
|
-
|
data/lib/test/rake.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
require 'rake/tasklib'
|
2
|
-
|
3
|
-
module Test
|
4
|
-
|
5
|
-
module Rake
|
6
|
-
|
7
|
-
# Define a test rake task.
|
8
|
-
#
|
9
|
-
# The `TEST` environment variable can be used to select tests
|
10
|
-
# when using the task.
|
11
|
-
#
|
12
|
-
#--
|
13
|
-
# TODO: The test task uses #fork. Maybe it should shell out instead?
|
14
|
-
# Or provide the option for either?
|
15
|
-
#++
|
16
|
-
class TestTask < ::Rake::TaskLib
|
17
|
-
|
18
|
-
# Glob patterns are used by default to select test scripts.
|
19
|
-
DEFAULT_TESTS = [
|
20
|
-
'test/**/case_*.rb',
|
21
|
-
'test/**/*_case.rb',
|
22
|
-
'test/**/test_*.rb',
|
23
|
-
'test/**/*_test.rb'
|
24
|
-
]
|
25
|
-
|
26
|
-
# Test scripts to load. Can be a file glob.
|
27
|
-
attr_accessor :tests
|
28
|
-
|
29
|
-
# Paths to add to $LOAD_PATH.
|
30
|
-
attr_accessor :loadpath
|
31
|
-
|
32
|
-
# Scripts to load prior to loading tests.
|
33
|
-
attr_accessor :requires
|
34
|
-
|
35
|
-
# Report format to use.
|
36
|
-
attr_accessor :format
|
37
|
-
|
38
|
-
# Filter tests based by tags.
|
39
|
-
attr_accessor :tags
|
40
|
-
|
41
|
-
# Filter tests by matching description.
|
42
|
-
attr_accessor :match
|
43
|
-
|
44
|
-
# From Rake's own TestTask.
|
45
|
-
alias_method :libs, :loadpath
|
46
|
-
alias_method :test_files, :tests
|
47
|
-
|
48
|
-
#
|
49
|
-
def initialize(name='test', desc="run tests", &block)
|
50
|
-
@name = name
|
51
|
-
@desc = desc
|
52
|
-
|
53
|
-
@loadpath = ['lib']
|
54
|
-
@requires = []
|
55
|
-
@tests = [ENV['TEST'] || DEFAULT_TESTS].flatten
|
56
|
-
@format = nil
|
57
|
-
@match = nil
|
58
|
-
@tags = []
|
59
|
-
|
60
|
-
block.call(self)
|
61
|
-
|
62
|
-
define_task
|
63
|
-
end
|
64
|
-
|
65
|
-
#
|
66
|
-
def define_task
|
67
|
-
desc @desc
|
68
|
-
task @name do
|
69
|
-
@tests ||= default_tests
|
70
|
-
run
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
#
|
75
|
-
def run
|
76
|
-
fork {
|
77
|
-
#require 'test'
|
78
|
-
require 'test/runner'
|
79
|
-
|
80
|
-
loadpath.each { |d| $LOAD_PATH.unshift(d) }
|
81
|
-
requires.each { |f| require f }
|
82
|
-
test_files.each { |f| require f }
|
83
|
-
|
84
|
-
suite = $TEST_SUITE || []
|
85
|
-
runner = new(suite, :format=>format, :tags=>tags, :match=>match)
|
86
|
-
success = runner.run
|
87
|
-
|
88
|
-
exit -1 unless success
|
89
|
-
}
|
90
|
-
Process.wait
|
91
|
-
end
|
92
|
-
|
93
|
-
# Resolve test globs.
|
94
|
-
#--
|
95
|
-
# TODO: simplify?
|
96
|
-
#++
|
97
|
-
def test_files
|
98
|
-
files = tests
|
99
|
-
files = files.map{ |f| Dir[f] }.flatten
|
100
|
-
files = files.map{ |f| File.directory?(f) ? Dir[File.join(f, '**/*.rb')] : f }
|
101
|
-
files = files.flatten.uniq
|
102
|
-
files = files.map{ |f| File.expand_path(f) }
|
103
|
-
files
|
104
|
-
end
|
105
|
-
|
106
|
-
#
|
107
|
-
def default_tests
|
108
|
-
if ENV['tests']
|
109
|
-
ENV['tests'].split(/[:;]/)
|
110
|
-
else
|
111
|
-
DEFAULT_TESTS
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
#
|
116
|
-
#def ruby_command
|
117
|
-
# File.join(RbConfig::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
|
118
|
-
#end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
data/lib/test/recorder.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Test
|
2
|
-
|
3
|
-
# Recorder class is an observer that tracks all tests
|
4
|
-
# that are run and categorizes them according to their
|
5
|
-
# test status.
|
6
|
-
class Recorder
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@table = Hash.new{ |h,k| h[k] = [] }
|
10
|
-
end
|
11
|
-
|
12
|
-
def [](key)
|
13
|
-
@table[key.to_sym]
|
14
|
-
end
|
15
|
-
|
16
|
-
#
|
17
|
-
def skip(test)
|
18
|
-
self[:skip] << test
|
19
|
-
end
|
20
|
-
|
21
|
-
# Add `test` to pass set.
|
22
|
-
def pass(test)
|
23
|
-
self[:pass] << test
|
24
|
-
end
|
25
|
-
|
26
|
-
def fail(test, exception)
|
27
|
-
self[:fail] << [test, exception]
|
28
|
-
end
|
29
|
-
|
30
|
-
def error(test, exception)
|
31
|
-
self[:error] << [test, exception]
|
32
|
-
end
|
33
|
-
|
34
|
-
def todo(test, exception)
|
35
|
-
self[:todo] << [test, exception]
|
36
|
-
end
|
37
|
-
|
38
|
-
def omit(test, exception)
|
39
|
-
self[:omit] << [test, exception]
|
40
|
-
end
|
41
|
-
|
42
|
-
# Returns true if their are no test errors or failures.
|
43
|
-
def success?
|
44
|
-
self[:error].size + self[:fail].size > 0 ? false : true
|
45
|
-
end
|
46
|
-
|
47
|
-
# Ignore any other signals.
|
48
|
-
def method_missing(*a)
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
@@ -1,268 +0,0 @@
|
|
1
|
-
require 'ansi/core'
|
2
|
-
require 'test/core_ext'
|
3
|
-
require 'test/code_snippet'
|
4
|
-
|
5
|
-
ignore_path = File.expand_path(File.join(__FILE__, '../../..'))
|
6
|
-
ignore_regexp = Regexp.new(Regexp.escape(ignore_path))
|
7
|
-
|
8
|
-
RUBY_IGNORE_CALLERS = [] unless defined? RUBY_IGNORE_CALLERS
|
9
|
-
RUBY_IGNORE_CALLERS << ignore_regexp
|
10
|
-
RUBY_IGNORE_CALLERS << /bin\/ruby-test/
|
11
|
-
|
12
|
-
module Test
|
13
|
-
|
14
|
-
#
|
15
|
-
module Reporters
|
16
|
-
|
17
|
-
# Test Reporter Base Class
|
18
|
-
class Abstract
|
19
|
-
|
20
|
-
#
|
21
|
-
def self.inherited(base)
|
22
|
-
registry << base
|
23
|
-
end
|
24
|
-
|
25
|
-
#
|
26
|
-
def self.registry
|
27
|
-
@registry ||= []
|
28
|
-
end
|
29
|
-
|
30
|
-
#
|
31
|
-
def initialize(runner)
|
32
|
-
@runner = runner
|
33
|
-
#@source = {}
|
34
|
-
|
35
|
-
# in case start_suite is overridden
|
36
|
-
@start_time = Time.now
|
37
|
-
end
|
38
|
-
|
39
|
-
#
|
40
|
-
attr :runner
|
41
|
-
|
42
|
-
#
|
43
|
-
def begin_suite(test_suite)
|
44
|
-
@start_time = Time.now
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
def begin_case(test_case)
|
49
|
-
end
|
50
|
-
|
51
|
-
#
|
52
|
-
def begin_test(test)
|
53
|
-
end
|
54
|
-
|
55
|
-
#
|
56
|
-
def skip_case(test_case)
|
57
|
-
end
|
58
|
-
|
59
|
-
#
|
60
|
-
def skip_test(test)
|
61
|
-
end
|
62
|
-
|
63
|
-
#
|
64
|
-
#def test(test)
|
65
|
-
#end
|
66
|
-
|
67
|
-
#
|
68
|
-
def pass(test)
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
def fail(test, exception)
|
73
|
-
end
|
74
|
-
|
75
|
-
#
|
76
|
-
def error(test, exception)
|
77
|
-
end
|
78
|
-
|
79
|
-
# Report a pending test.
|
80
|
-
def todo(test, exception)
|
81
|
-
end
|
82
|
-
|
83
|
-
# Report an omitted test.
|
84
|
-
def omit(test, exception)
|
85
|
-
end
|
86
|
-
|
87
|
-
#
|
88
|
-
def end_test(test)
|
89
|
-
end
|
90
|
-
|
91
|
-
#
|
92
|
-
def end_case(test_case)
|
93
|
-
end
|
94
|
-
|
95
|
-
#
|
96
|
-
def end_suite(test_suite)
|
97
|
-
end
|
98
|
-
|
99
|
-
protected
|
100
|
-
|
101
|
-
def record
|
102
|
-
runner.recorder
|
103
|
-
end
|
104
|
-
|
105
|
-
# Is coverage information requested?
|
106
|
-
#def cover?
|
107
|
-
# runner.cover?
|
108
|
-
#end
|
109
|
-
|
110
|
-
# Count up the total number of tests.
|
111
|
-
def total_count(suite)
|
112
|
-
c = 0
|
113
|
-
suite.each do |tc|
|
114
|
-
if tc.respond_to?(:each)
|
115
|
-
c += total_count(tc)
|
116
|
-
else
|
117
|
-
c += 1
|
118
|
-
end
|
119
|
-
end
|
120
|
-
return c
|
121
|
-
end
|
122
|
-
|
123
|
-
# Common timestamp any reporter can use.
|
124
|
-
def timestamp
|
125
|
-
seconds = Time.now - @start_time
|
126
|
-
|
127
|
-
"Finished in %.5fs, %.2f tests/s." % [seconds, total/seconds]
|
128
|
-
end
|
129
|
-
|
130
|
-
#
|
131
|
-
def total
|
132
|
-
@total ||= subtotal
|
133
|
-
end
|
134
|
-
|
135
|
-
#
|
136
|
-
def subtotal
|
137
|
-
[:todo, :pass, :fail, :error, :omit, :skip].inject(0) do |s,r|
|
138
|
-
s += record[r.to_sym].size; s
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
# TODO: lump skipped and omitted into one group ?
|
143
|
-
|
144
|
-
TITLES = {
|
145
|
-
:pass => 'passing',
|
146
|
-
:fail => 'failures',
|
147
|
-
:error => 'errors',
|
148
|
-
:todo => 'pending',
|
149
|
-
:omit => 'omissions',
|
150
|
-
:skip => 'skipped'
|
151
|
-
}
|
152
|
-
|
153
|
-
# TODO: Add assertion counts (if reasonably possible).
|
154
|
-
|
155
|
-
# Common tally stamp any reporter can use.
|
156
|
-
#
|
157
|
-
# @return [String] tally stamp
|
158
|
-
def tally
|
159
|
-
sizes = {}
|
160
|
-
names = %w{error fail todo omit skip}.map{ |n| n.to_sym }
|
161
|
-
names.each do |r|
|
162
|
-
sizes[r] = record[r].size
|
163
|
-
end
|
164
|
-
|
165
|
-
#names.unshift(:tests)
|
166
|
-
#sizes[:tests] = total
|
167
|
-
|
168
|
-
s = []
|
169
|
-
names.each do |n|
|
170
|
-
next unless sizes[n] > 0
|
171
|
-
s << tally_item(n, sizes)
|
172
|
-
end
|
173
|
-
|
174
|
-
'Executed ' + "#{total}".ansi(:bold) + ' tests with ' + s.join(', ')
|
175
|
-
end
|
176
|
-
|
177
|
-
#
|
178
|
-
def tally_item(name, sizes)
|
179
|
-
x = []
|
180
|
-
x << "%s" % sizes[name].to_s.ansi(:bold)
|
181
|
-
x << " %s" % TITLES[name].downcase
|
182
|
-
x << " (%.1f%%)" % ((sizes[name].to_f/total*100)) if runner.verbose?
|
183
|
-
x.join('')
|
184
|
-
end
|
185
|
-
|
186
|
-
#--
|
187
|
-
# TODO: Matching `bin/ruby-test` is not robust.
|
188
|
-
#++
|
189
|
-
|
190
|
-
# Remove reference to lemon library from backtrace.
|
191
|
-
#
|
192
|
-
# @param [Exception] exception
|
193
|
-
# The error that was rasied.
|
194
|
-
#
|
195
|
-
# @return [Array] filtered backtrace
|
196
|
-
def clean_backtrace(exception)
|
197
|
-
trace = (Exception === exception ? exception.backtrace : exception)
|
198
|
-
return trace if $DEBUG
|
199
|
-
trace = trace.reject{ |t| RUBY_IGNORE_CALLERS.any?{ |r| r =~ t }}
|
200
|
-
trace = trace.map do |t|
|
201
|
-
i = t.index(':in')
|
202
|
-
i ? t[0...i] : t
|
203
|
-
end
|
204
|
-
#if trace.empty?
|
205
|
-
# exception
|
206
|
-
#else
|
207
|
-
# exception.set_backtrace(trace) if Exception === exception
|
208
|
-
# exception
|
209
|
-
#end
|
210
|
-
trace.uniq
|
211
|
-
end
|
212
|
-
|
213
|
-
# That an exception, backtrace or source code text and line
|
214
|
-
# number and return a CodeSnippet object.
|
215
|
-
#
|
216
|
-
# @return [CodeSnippet] code snippet
|
217
|
-
def code(source, line=nil)
|
218
|
-
case source
|
219
|
-
when Exception, Array
|
220
|
-
CodeSnippet.from_backtrace(clean_backtrace(source))
|
221
|
-
else
|
222
|
-
CodeSnippet.new(source, line)
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
#--
|
227
|
-
# TODO: Show more of the file name than just the basename.
|
228
|
-
#++
|
229
|
-
|
230
|
-
#
|
231
|
-
def file_and_line(exception)
|
232
|
-
line = clean_backtrace(exception)[0]
|
233
|
-
return "" unless line
|
234
|
-
i = line.rindex(':in')
|
235
|
-
line = i ? line[0...i] : line
|
236
|
-
File.basename(line)
|
237
|
-
end
|
238
|
-
|
239
|
-
#
|
240
|
-
def file_and_line_array(exception)
|
241
|
-
case exception
|
242
|
-
when Exception
|
243
|
-
line = exception.backtrace[0]
|
244
|
-
else
|
245
|
-
line = exception[0] # backtrace
|
246
|
-
end
|
247
|
-
return ["", 0] unless line
|
248
|
-
i = line.rindex(':in')
|
249
|
-
line = i ? line[0...i] : line
|
250
|
-
f, l = File.basename(line).split(':')
|
251
|
-
return [f, l.to_i]
|
252
|
-
end
|
253
|
-
|
254
|
-
#
|
255
|
-
def file(exception)
|
256
|
-
file_and_line_array(exception).first
|
257
|
-
end
|
258
|
-
|
259
|
-
#
|
260
|
-
def line(exception)
|
261
|
-
file_and_line_array(exception).last
|
262
|
-
end
|
263
|
-
|
264
|
-
end
|
265
|
-
|
266
|
-
end
|
267
|
-
|
268
|
-
end
|