miniunit 1.0.0 → 1.1.0
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/.autotest +5 -0
- data/History.txt +11 -0
- data/Manifest.txt +3 -0
- data/README.txt +7 -5
- data/Rakefile +20 -0
- data/lib/test/unit.rb +245 -43
- data/lib/test/unit/testcase.rb +5 -0
- data/test/test_test_case.rb +321 -0
- data/test/test_test_unit.rb +75 -0
- metadata +18 -11
data/.autotest
ADDED
data/History.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== 1.1.0 / 2007-11-08
|
2
|
+
|
3
|
+
* 4 major enhancements:
|
4
|
+
* Finished writing all missing assertions.
|
5
|
+
* Output matches original test/unit.
|
6
|
+
* Documented every method needed by language implementor.
|
7
|
+
* Fully switched over to self-testing setup.
|
8
|
+
* 2 minor enhancements:
|
9
|
+
* Added deny (assert ! test), our favorite extension to test/unit.
|
10
|
+
* Added .autotest and fairly complete unit tests. (thanks Chad for help here)
|
11
|
+
|
1
12
|
== 1.0.0 / 2006-10-30
|
2
13
|
|
3
14
|
* 1 major enhancement
|
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
@@ -4,13 +4,15 @@ miniunit by Ryan Davis
|
|
4
4
|
== DESCRIPTION:
|
5
5
|
|
6
6
|
miniunit is a completely minimial drop-in replacement for ruby's
|
7
|
-
test/unit. This is meant
|
8
|
-
|
7
|
+
test/unit. This is meant to be clean and easy to use both as a regular
|
8
|
+
test writer and for language implementors that need a minimal set of
|
9
|
+
methods to bootstrap a working unit test suite.
|
9
10
|
|
10
11
|
== FEATURES/PROBLEMS:
|
11
12
|
|
12
|
-
*
|
13
|
-
|
13
|
+
* Fully test/unit compatible assertions.
|
14
|
+
* Incredibly small and fast runner, but no bells and whistles.
|
15
|
+
* Incompatible at the runner level.
|
14
16
|
|
15
17
|
== REQUIREMENTS:
|
16
18
|
|
@@ -24,7 +26,7 @@ set of methods to bootstrap a working unit test suite.
|
|
24
26
|
|
25
27
|
(The MIT License)
|
26
28
|
|
27
|
-
Copyright (c) 2006 Ryan Davis, Seattle.rb
|
29
|
+
Copyright (c) 2006-2007 Ryan Davis, Seattle.rb
|
28
30
|
|
29
31
|
Permission is hereby granted, free of charge, to any person obtaining
|
30
32
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
|
3
|
+
$TESTING_MINIUNIT = true
|
4
|
+
|
3
5
|
require 'rubygems'
|
4
6
|
require 'hoe'
|
5
7
|
require './lib/test/unit.rb'
|
@@ -12,4 +14,22 @@ Hoe.new('miniunit', Test::Unit::VERSION) do |p|
|
|
12
14
|
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
13
15
|
end
|
14
16
|
|
17
|
+
task :sort do
|
18
|
+
begin
|
19
|
+
sh 'for f in lib/**/*.rb; do echo $f; grep "^ *def " $f | grep -v sort=skip > x; sort x > y; echo $f; echo; diff x y; done'
|
20
|
+
sh 'for f in test/test_*.rb; do echo $f; grep "^ *def.test_" $f > x; sort x > y; echo $f; echo; diff x y; done'
|
21
|
+
ensure
|
22
|
+
sh 'rm x y'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
task :woot do
|
27
|
+
begin
|
28
|
+
system "ruby blah.rb > x; ruby -Ilib blah.rb > y"
|
29
|
+
system "diff -u x y > z"
|
30
|
+
# ensure
|
31
|
+
# rm_f "x", "y", "z"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
15
35
|
# vim: syntax=Ruby
|
data/lib/test/unit.rb
CHANGED
@@ -2,101 +2,303 @@
|
|
2
2
|
# Totally minimal (hopefully) drop-in replacement for test/unit
|
3
3
|
#
|
4
4
|
|
5
|
-
#
|
5
|
+
# Minimal methods needed to run full miniunit + assert:
|
6
|
+
#
|
7
|
+
# Array: each, grep, join, size
|
8
|
+
# Class: new, inherited
|
9
|
+
# Enumerable: find
|
10
|
+
# Exception: backtrace, message
|
11
|
+
# Fixnum: +
|
12
|
+
# Hash: keys
|
13
|
+
# Kernel: at_exit
|
14
|
+
# Module: ===, public_instance_methods
|
15
|
+
# Object: __send__, class, inspect
|
16
|
+
# String: sub, %
|
17
|
+
# Regexp: =~
|
18
|
+
|
19
|
+
# Only needed for specific assertions:
|
20
|
+
#
|
21
|
+
# Array.last
|
22
|
+
# Enumerable.include?
|
23
|
+
# Float: abs
|
24
|
+
# Object: ==, inspect, equal?, kind_of?, nil?, respond_to?
|
25
|
+
# Numeric: to_f, <, -
|
26
|
+
|
27
|
+
$TESTING_MINIUNIT ||= false
|
6
28
|
|
7
|
-
at_exit {
|
29
|
+
at_exit { exit MiniTest::Unit.autotest } unless $TESTING_MINIUNIT
|
8
30
|
|
9
|
-
|
31
|
+
MINIUNIT_FILE_SEPARATORS = %r{[\\/:]}
|
32
|
+
MINIUNIT_PREFIX = __FILE__.split(MINIUNIT_FILE_SEPARATORS)[0..-3]
|
33
|
+
MINIUNIT_RB_FILE = /\.rb\Z/
|
34
|
+
|
35
|
+
def filter_backtrace(backtrace, prefix=nil)
|
36
|
+
return ["No backtrace"] unless(backtrace)
|
37
|
+
return backtrace if $TESTING_MINIUNIT
|
38
|
+
split_p = if(prefix)
|
39
|
+
prefix.split(MINIUNIT_FILE_SEPARATORS)
|
40
|
+
else
|
41
|
+
MINIUNIT_PREFIX
|
42
|
+
end
|
43
|
+
match = proc do |e|
|
44
|
+
split_e = e.split(MINIUNIT_FILE_SEPARATORS)[0, split_p.size]
|
45
|
+
next false unless(split_e[0..-2] == split_p[0..-2])
|
46
|
+
split_e[-1].sub(MINIUNIT_RB_FILE, '') == split_p[-1]
|
47
|
+
end
|
48
|
+
return backtrace unless(backtrace.detect(&match))
|
49
|
+
found_prefix = false
|
50
|
+
new_backtrace = backtrace.reverse.reject do |e|
|
51
|
+
if(match[e])
|
52
|
+
found_prefix = true
|
53
|
+
true
|
54
|
+
elsif(found_prefix)
|
55
|
+
false
|
56
|
+
else
|
57
|
+
true
|
58
|
+
end
|
59
|
+
end.reverse
|
60
|
+
new_backtrace = (new_backtrace.empty? ? backtrace : new_backtrace)
|
61
|
+
new_backtrace = new_backtrace.reject(&match)
|
62
|
+
new_backtrace.empty? ? backtrace : new_backtrace
|
63
|
+
end
|
64
|
+
|
65
|
+
module MiniTest
|
10
66
|
class Assertion < Exception; end
|
11
67
|
|
12
68
|
class Unit
|
13
|
-
VERSION = "1.
|
69
|
+
VERSION = "1.1.0"
|
70
|
+
|
71
|
+
attr_reader :report
|
72
|
+
|
73
|
+
@@out = $stdout
|
74
|
+
|
75
|
+
def self.output= stream
|
76
|
+
@@out = stream
|
77
|
+
end
|
14
78
|
|
15
79
|
def self.autotest
|
16
|
-
|
17
|
-
|
80
|
+
self.new.autotest
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.tests_from(klass)
|
84
|
+
klass.public_instance_methods(true).grep(/^test/).sort
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.location_of_failure(e)
|
88
|
+
e.backtrace.find { |s|
|
89
|
+
s !~ /in .(assert|flunk)/
|
90
|
+
}.sub(/:in .*$/, '')
|
91
|
+
end
|
92
|
+
|
93
|
+
def puke(klass, meth, e)
|
94
|
+
if MiniTest::Assertion === e then
|
95
|
+
@results[:failures] += 1
|
96
|
+
loc = self.class.location_of_failure(e)
|
97
|
+
@report << "Failure:\n#{meth}(#{klass}) [#{loc}]:\n#{e.message}\n"
|
98
|
+
'F'
|
99
|
+
else
|
100
|
+
@results[:errors] += 1
|
101
|
+
bt = filter_backtrace(e.backtrace).join("\n ")
|
102
|
+
@report << "Error:\n#{meth}(#{klass}):\n#{e.class}: #{e.message}\n #{bt}\n"
|
103
|
+
'E'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def initialize
|
108
|
+
@report = []
|
109
|
+
@results = {:errors => 0, :failures => 0}
|
110
|
+
end
|
111
|
+
|
112
|
+
def autotest
|
113
|
+
@@out.puts "Loaded suite #{$0.sub(/\.rb$/, '')}\nStarted"
|
114
|
+
|
115
|
+
timestamp_before_test_run = Time.now
|
116
|
+
test_count, assertion_count = run_test_suites
|
117
|
+
|
118
|
+
@@out.puts
|
119
|
+
@@out.puts "Finished in #{'%.6f' % (Time.now - timestamp_before_test_run)} seconds."
|
120
|
+
|
121
|
+
@report.each_with_index do |msg, i|
|
122
|
+
@@out.puts "\n%3d) %s" % [i + 1, msg]
|
123
|
+
end
|
124
|
+
|
125
|
+
@@out.puts
|
126
|
+
@@out.puts "%d tests, %d assertions, %d failures, %d errors" % [test_count, assertion_count, failures, errors]
|
127
|
+
|
128
|
+
return failures + errors
|
129
|
+
end
|
130
|
+
|
131
|
+
def run_test_suites
|
132
|
+
test_count, assertion_count = 0, 0
|
133
|
+
TestCase.test_suites.each do |klass|
|
18
134
|
inst = klass.new
|
19
|
-
|
20
|
-
|
135
|
+
inst._assertions = 0
|
136
|
+
tests = self.class.tests_from(klass)
|
137
|
+
tests.each do |meth|
|
138
|
+
result = '.'
|
21
139
|
begin
|
22
140
|
inst.setup
|
23
|
-
inst.
|
24
|
-
inst.teardown
|
141
|
+
inst.__send__ meth
|
25
142
|
rescue Exception => e
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
143
|
+
result = puke(klass, meth, e)
|
144
|
+
ensure
|
145
|
+
begin
|
146
|
+
inst.teardown
|
147
|
+
rescue Exception => e
|
148
|
+
result = puke(klass, meth, e)
|
149
|
+
end
|
30
150
|
end
|
151
|
+
@@out.print result
|
31
152
|
end
|
153
|
+
test_count += tests.size
|
154
|
+
assertion_count += inst._assertions
|
32
155
|
end
|
156
|
+
[test_count, assertion_count]
|
157
|
+
end
|
158
|
+
|
159
|
+
def failures
|
160
|
+
@results[:failures]
|
161
|
+
end
|
162
|
+
|
163
|
+
def errors
|
164
|
+
@results[:errors]
|
33
165
|
end
|
34
166
|
|
35
167
|
class TestCase
|
168
|
+
def self.reset
|
169
|
+
@@test_suites = {}
|
170
|
+
end
|
171
|
+
|
172
|
+
reset
|
173
|
+
|
174
|
+
def self.inherited klass
|
175
|
+
@@test_suites[klass] = true
|
176
|
+
end
|
177
|
+
|
178
|
+
def self.test_suites
|
179
|
+
@@test_suites.keys.sort_by { |ts| ts.name }
|
180
|
+
end
|
181
|
+
|
182
|
+
attr_accessor :_assertions
|
36
183
|
def setup; end
|
37
184
|
def teardown; end
|
38
185
|
|
39
|
-
def
|
40
|
-
|
186
|
+
def _increment_assertions
|
187
|
+
@_assertions ||= 0
|
188
|
+
@_assertions += 1
|
189
|
+
end
|
190
|
+
|
191
|
+
def assert test, msg = "failed assertion (no message given)"
|
192
|
+
_increment_assertions
|
193
|
+
raise MiniTest::Assertion, msg unless test
|
194
|
+
end
|
195
|
+
|
196
|
+
def assert_block msg = "assert_block failed."
|
197
|
+
assert yield, msg
|
198
|
+
end
|
199
|
+
|
200
|
+
def assert_equal exp, act, msg = ""
|
201
|
+
msg += '.' unless msg.empty?
|
202
|
+
assert exp == act, "#{msg}\n<#{exp.inspect}> expected but was\n<#{act.inspect}>.".strip
|
41
203
|
end
|
42
204
|
|
43
|
-
def
|
44
|
-
assert exp
|
205
|
+
def assert_in_delta exp, act, delta, msg = "Expected #{exp} to be within #{delta} of #{act}"
|
206
|
+
assert delta.to_f > (exp.to_f - act.to_f).abs, msg
|
45
207
|
end
|
46
208
|
|
47
|
-
def
|
48
|
-
assert
|
209
|
+
def assert_instance_of cls, obj, msg = "Expected #{obj.inspect} to be an instance of #{cls}"
|
210
|
+
assert cls === obj, msg
|
49
211
|
end
|
50
212
|
|
51
|
-
def
|
52
|
-
assert cls
|
213
|
+
def assert_kind_of cls, obj, msg = "Expected #{obj.inspect} to be a kind of #{cls}"
|
214
|
+
assert obj.kind_of?(cls), msg
|
53
215
|
end
|
54
216
|
|
55
|
-
def
|
56
|
-
assert
|
217
|
+
def assert_match exp, act, msg = "Expected #{act.inspect} to match #{exp.inspect}"
|
218
|
+
assert act =~ exp, msg
|
57
219
|
end
|
58
220
|
|
59
|
-
def
|
60
|
-
assert
|
221
|
+
def assert_nil obj, msg = "Expected #{obj.inspect} to be nil"
|
222
|
+
assert obj.nil?, msg
|
61
223
|
end
|
62
224
|
|
63
|
-
def
|
64
|
-
assert
|
225
|
+
def assert_no_match exp, act, msg = "Expected #{act.inspect} to not match #{exp.inspect}"
|
226
|
+
assert act !~ exp, msg
|
65
227
|
end
|
66
228
|
|
67
|
-
def assert_not_equal
|
68
|
-
assert exp != act, msg
|
229
|
+
def assert_not_equal exp, act, msg = "Expected #{act.inspect} to not be equal to #{exp.inspect}"
|
230
|
+
assert exp != act, msg
|
69
231
|
end
|
70
232
|
|
71
|
-
def assert_not_nil
|
72
|
-
assert ! obj.nil?, msg
|
233
|
+
def assert_not_nil obj, msg = "Expected #{obj.inspect} to not be nil"
|
234
|
+
assert ! obj.nil?, msg
|
235
|
+
end
|
236
|
+
|
237
|
+
def assert_not_same exp, act, msg = "Expected #{act.inspect} to not be the same as #{exp.inspect}"
|
238
|
+
assert ! exp.equal?(act), msg
|
239
|
+
end
|
240
|
+
|
241
|
+
def assert_nothing_raised
|
242
|
+
_increment_assertions
|
243
|
+
yield
|
244
|
+
rescue => e
|
245
|
+
raise MiniTest::Assertion, exception_details(e, "Exception raised:")
|
246
|
+
end
|
247
|
+
|
248
|
+
alias :assert_nothing_thrown :assert_nothing_raised
|
249
|
+
|
250
|
+
def assert_operator o1, op, o2, msg = "<#{o1.inspect}> expected to be\n#{op.inspect}\n<#{o2.inspect}>."
|
251
|
+
assert o1.__send__(op, o2), msg
|
73
252
|
end
|
74
253
|
|
75
|
-
def
|
76
|
-
|
254
|
+
def exception_details e, msg
|
255
|
+
"#{msg}\nClass: <#{e.class}>\nMessage: <#{e.message.inspect}>\n---Backtrace---\n#{filter_backtrace(e.backtrace).join("\n")}\n---------------"
|
77
256
|
end
|
78
257
|
|
79
|
-
def assert_raises
|
258
|
+
def assert_raises *exp
|
259
|
+
msg = String === exp.last ? exp.pop : nil
|
260
|
+
exp = exp.first if exp.size == 1
|
80
261
|
begin
|
81
262
|
yield
|
82
|
-
|
263
|
+
raise MiniTest::Assertion, "<#{exp.inspect}> exception expected but none was thrown."
|
83
264
|
rescue Exception => e
|
84
|
-
assert exp
|
265
|
+
assert((Array === exp ? exp.include?(e) : exp === e),
|
266
|
+
exception_details(e,
|
267
|
+
"<#{exp.inspect}> exception expected but was"))
|
268
|
+
|
85
269
|
return e
|
86
270
|
end
|
87
271
|
end
|
88
272
|
alias :assert_raise :assert_raises
|
89
273
|
|
90
|
-
def
|
91
|
-
assert
|
274
|
+
def assert_respond_to obj, meth, msg = "Expected #{obj.inspect} of type #{obj.class} to respond_to? #{meth.inspect}"
|
275
|
+
assert obj.respond_to?(meth), msg
|
92
276
|
end
|
93
277
|
|
94
|
-
def
|
95
|
-
assert
|
278
|
+
def assert_same exp, act, msg = "Expected #{act.inspect} to be the same as #{exp.inspect}."
|
279
|
+
assert exp.equal?(act), msg
|
96
280
|
end
|
97
281
|
|
98
|
-
def
|
282
|
+
def assert_send send, msg = nil
|
283
|
+
recv, meth, *args = send
|
284
|
+
assert(recv.__send__(meth, *args),
|
285
|
+
msg || "<#{recv.inspect}> expected to respond to\n<#{meth.inspect}> with a true value.")
|
286
|
+
end
|
99
287
|
|
288
|
+
def assert_throws sym, msg = "<#{sym.inspect}> should have been thrown."
|
289
|
+
caught = true
|
290
|
+
catch(sym) do
|
291
|
+
yield rescue nil
|
292
|
+
caught = false
|
293
|
+
end
|
294
|
+
assert caught, msg
|
295
|
+
end
|
296
|
+
|
297
|
+
def flunk msg = "Flunked"
|
298
|
+
assert false, msg
|
299
|
+
end
|
100
300
|
end # class TestCase
|
101
301
|
end # class Unit
|
102
|
-
end # module
|
302
|
+
end # module MiniTest
|
303
|
+
|
304
|
+
Test = MiniTest unless defined? Test
|
data/lib/test/unit/testcase.rb
CHANGED
@@ -0,0 +1,321 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
$TESTING_TEST_UNIT = true
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
# TODO: add message versions
|
8
|
+
class TestTestCase < MiniTest::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
util_test_suites.clear
|
11
|
+
@tc = MiniTest::Unit::TestCase.new
|
12
|
+
@zomg = "zomg ponies!"
|
13
|
+
@assertion_count = 1
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
assert_equal @assertion_count, @tc._assertions if @tc._assertions
|
18
|
+
Object.send :remove_const, :ATestCase if defined? ATestCase
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_class_inherited
|
22
|
+
util_test_case
|
23
|
+
assert util_test_suites[ATestCase]
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_class_test_suites
|
27
|
+
util_test_case
|
28
|
+
assert_equal 1, MiniTest::Unit::TestCase.test_suites.size
|
29
|
+
assert_equal [ATestCase], MiniTest::Unit::TestCase.test_suites
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_assert
|
33
|
+
@tc.assert true
|
34
|
+
@tc.assert true, "message"
|
35
|
+
@assertion_count = 2
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_assert_triggered
|
39
|
+
util_assert_triggered "failed assertion (no message given)" do
|
40
|
+
@tc.assert false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_assert_triggered_message
|
45
|
+
util_assert_triggered @zomg do
|
46
|
+
@tc.assert false, @zomg
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_assert_block
|
51
|
+
@tc.assert_block do
|
52
|
+
true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_assert_block_triggered
|
57
|
+
util_assert_triggered 'assert_block failed.' do
|
58
|
+
@tc.assert_block do
|
59
|
+
false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_assert_equal
|
65
|
+
@tc.assert_equal 1, 1
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_assert_equal_triggered
|
69
|
+
util_assert_triggered "<1> expected but was\n<2>." do
|
70
|
+
@tc.assert_equal 1, 2
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_assert_in_delta
|
75
|
+
@tc.assert_in_delta 0.0, 1.0 / 1000, 0.1
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_assert_in_delta_triggered
|
79
|
+
util_assert_triggered 'Expected 0.0 to be within 1.0e-06 of 0.001' do
|
80
|
+
@tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_assert_instance_of
|
85
|
+
@tc.assert_instance_of String, "blah"
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_assert_instance_of_triggered
|
89
|
+
util_assert_triggered 'Expected "blah" to be an instance of Array' do
|
90
|
+
@tc.assert_instance_of Array, "blah"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_assert_kind_of
|
95
|
+
@tc.assert_kind_of String, "blah"
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_assert_kind_of_triggered
|
99
|
+
util_assert_triggered 'Expected "blah" to be a kind of Array' do
|
100
|
+
@tc.assert_kind_of Array, "blah"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_assert_match
|
105
|
+
@tc.assert_match "blah blah blah", /\w+/
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_assert_match_triggered
|
109
|
+
util_assert_triggered 'Expected /\d+/ to match "blah blah blah"' do
|
110
|
+
@tc.assert_match "blah blah blah", /\d+/
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_assert_nil
|
115
|
+
@tc.assert_nil nil
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_assert_nil_triggered
|
119
|
+
util_assert_triggered 'Expected 42 to be nil' do
|
120
|
+
@tc.assert_nil 42
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_assert_no_match
|
125
|
+
@tc.assert_no_match "blah blah blah", /\d+/
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_assert_no_match_triggered
|
129
|
+
util_assert_triggered 'Expected /\w+/ to not match "blah blah blah"' do
|
130
|
+
@tc.assert_no_match "blah blah blah", /\w+/
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_assert_not_equal
|
135
|
+
@tc.assert_not_equal "blah", "yay"
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_assert_not_equal_triggered
|
139
|
+
util_assert_triggered 'Expected "blah" to not be equal to "blah"' do
|
140
|
+
@tc.assert_not_equal "blah", "blah"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_assert_not_nil
|
145
|
+
@tc.assert_not_nil 42
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_assert_not_nil_triggered
|
149
|
+
util_assert_triggered 'Expected nil to not be nil' do
|
150
|
+
@tc.assert_not_nil nil
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_assert_not_same
|
155
|
+
@tc.assert_not_same 1, 2
|
156
|
+
end
|
157
|
+
|
158
|
+
# TODO: "with id <id>" crap from assertions.rb
|
159
|
+
def test_assert_not_same_triggered
|
160
|
+
util_assert_triggered 'Expected 1 to not be the same as 1' do
|
161
|
+
@tc.assert_not_same 1, 1
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_assert_nothing_raised
|
166
|
+
@tc.assert_nothing_raised do
|
167
|
+
# do nothing
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_assert_nothing_raised_triggered
|
172
|
+
expected = 'Exception raised:
|
173
|
+
Class: <RuntimeError>
|
174
|
+
Message: <"oops!">
|
175
|
+
---Backtrace---'
|
176
|
+
|
177
|
+
util_assert_triggered expected do
|
178
|
+
@tc.assert_nothing_raised do
|
179
|
+
raise "oops!"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_assert_operator
|
185
|
+
@tc.assert_operator 2, :>, 1
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_assert_operator_triggered
|
189
|
+
util_assert_triggered "<2> expected to be\n:<\n<1>." do
|
190
|
+
@tc.assert_operator 2, :<, 1
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_assert_raises
|
195
|
+
@tc.assert_raises RuntimeError do
|
196
|
+
raise "blah"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_assert_raises_triggered_none
|
201
|
+
e = @tc.assert_raises MiniTest::Assertion do
|
202
|
+
# do nothing
|
203
|
+
end
|
204
|
+
|
205
|
+
expected = "<MiniTest::Assertion> exception expected but none was thrown."
|
206
|
+
|
207
|
+
assert_equal expected, e.message
|
208
|
+
# @assertion_count = 2
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_assert_raises_triggered_wrong
|
212
|
+
e = assert_raises(MiniTest::Assertion) do
|
213
|
+
@tc.assert_raises RuntimeError do
|
214
|
+
raise SyntaxError, "icky"
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
expected = "<RuntimeError> exception expected but was
|
219
|
+
Class: <SyntaxError>
|
220
|
+
Message: <\"icky\">
|
221
|
+
---Backtrace---"
|
222
|
+
|
223
|
+
assert_equal expected, e.message.sub(/(---Backtrace---).*/m, '\1')
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_assert_respond_to
|
227
|
+
@tc.assert_respond_to "blah", :empty?
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_assert_respond_to_triggered
|
231
|
+
util_assert_triggered 'Expected "blah" of type String to respond_to? :rawr!' do
|
232
|
+
@tc.assert_respond_to "blah", :rawr!
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_assert_same
|
237
|
+
o = "blah"
|
238
|
+
@tc.assert_same 1, 1
|
239
|
+
@tc.assert_same :blah, :blah
|
240
|
+
@tc.assert_same o, o
|
241
|
+
@assertion_count = 3
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_assert_same_triggered
|
245
|
+
util_assert_triggered 'Expected 2 to be the same as 1.' do
|
246
|
+
@tc.assert_same 1, 2
|
247
|
+
end
|
248
|
+
|
249
|
+
util_assert_triggered 'Expected "blah" to be the same as "blah".' do
|
250
|
+
s1 = "blah"
|
251
|
+
s2 = "blah"
|
252
|
+
@tc.assert_same s1, s2
|
253
|
+
end
|
254
|
+
|
255
|
+
@assertion_count = 2
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_assert_send
|
259
|
+
o = [ 42 ]
|
260
|
+
@tc.assert_send([o, :clear])
|
261
|
+
assert_equal [], o
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_assert_send_triggered
|
265
|
+
util_assert_triggered '<"blah"> expected to respond to
|
266
|
+
<:empty?> with a true value.' do
|
267
|
+
o = "blah"
|
268
|
+
@tc.assert_send([o, :empty?])
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_assert_throws
|
273
|
+
@tc.assert_throws(:blah) do
|
274
|
+
throw :blah
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_assert_throws_triggered
|
279
|
+
util_assert_triggered '<:blah> should have been thrown.' do
|
280
|
+
@tc.assert_throws(:blah) do
|
281
|
+
# do nothing
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
def test_assert_throws_triggered_different
|
287
|
+
util_assert_triggered '<:blah> should have been thrown.' do
|
288
|
+
@tc.assert_throws(:blah) do
|
289
|
+
throw :not_blah
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_flunk
|
295
|
+
util_assert_triggered 'Flunked' do
|
296
|
+
@tc.flunk
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_flunk_message
|
301
|
+
util_assert_triggered @zomg do
|
302
|
+
@tc.flunk @zomg
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
def util_assert_triggered expected
|
307
|
+
e = assert_raises(MiniTest::Assertion) do
|
308
|
+
yield
|
309
|
+
end
|
310
|
+
|
311
|
+
assert_equal expected, e.message.sub(/(---Backtrace---).*/m, '\1')
|
312
|
+
end
|
313
|
+
|
314
|
+
def util_test_suites
|
315
|
+
MiniTest::Unit::TestCase.__send__(:class_variable_get, :@@test_suites)
|
316
|
+
end
|
317
|
+
|
318
|
+
def util_test_case
|
319
|
+
Object.const_set(:ATestCase, Class.new(MiniTest::Unit::TestCase))
|
320
|
+
end
|
321
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
$TESTING_MINIUNIT = true
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class TestTestUnit < MiniTest::Unit::TestCase
|
10
|
+
|
11
|
+
def setup
|
12
|
+
MiniTest::Unit::TestCase.reset
|
13
|
+
@tu = MiniTest::Unit.new
|
14
|
+
MiniTest::Unit.output = StringIO.new("")
|
15
|
+
assert_equal [0, 0], @tu.run_test_suites
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
MiniTest::Unit.output = $stdout
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_class_puke_with_assertion_failed
|
23
|
+
exception = MiniTest::Assertion.new "Oh no!"
|
24
|
+
exception.set_backtrace ["unhappy"]
|
25
|
+
assert_equal 'F', @tu.puke('SomeClass', 'method_name', exception)
|
26
|
+
assert_equal 1, @tu.failures
|
27
|
+
assert_match(/^Failure.*Oh no!/m, @tu.report.first)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_class_puke_with_failure_and_flunk_in_backtrace
|
31
|
+
exception = begin
|
32
|
+
MiniTest::Unit::TestCase.new.flunk
|
33
|
+
rescue MiniTest::Assertion => failure
|
34
|
+
failure
|
35
|
+
end
|
36
|
+
assert_equal 'F', @tu.puke('SomeClass', 'method_name', exception)
|
37
|
+
assert !@tu.report.any?{|line| line =~ /in .flunk/}
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_class_puke_with_non_failure_exception
|
41
|
+
exception = Exception.new("Oh no again!")
|
42
|
+
assert_equal 'E', @tu.puke('SomeClass', 'method_name', exception)
|
43
|
+
assert_equal 1, @tu.errors
|
44
|
+
assert_match(/^Exception.*Oh no again!/m, @tu.report.first)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_class_run_test_suites
|
48
|
+
create_a_test_case_named("ATestCase")
|
49
|
+
assert_equal [1, 1], @tu.run_test_suites
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_class_autotest_failing
|
53
|
+
create_a_test_case_named("FailingTest", :failing => true)
|
54
|
+
@tu.autotest
|
55
|
+
assert_equal(1, @tu.report.size)
|
56
|
+
assert_match(/test_failure/, @tu.report.first)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_class_autotest_passing
|
60
|
+
create_a_test_case_named("PassingTest")
|
61
|
+
@tu.autotest
|
62
|
+
assert_equal([], @tu.report)
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_a_test_case_named(name, options = {})
|
66
|
+
eval <<-CODE
|
67
|
+
class #{name} < MiniTest::Unit::TestCase
|
68
|
+
def test_something
|
69
|
+
assert true
|
70
|
+
end
|
71
|
+
#{if options[:failing]; "def test_failure; assert false; end"; end}
|
72
|
+
end
|
73
|
+
CODE
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: miniunit
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date:
|
6
|
+
version: 1.1.0
|
7
|
+
date: 2007-11-08 00:00:00 -08:00
|
8
8
|
summary: miniunit is a completely minimial drop-in replacement for ruby's test/unit.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: ryand-ruby@zenspider.com
|
12
12
|
homepage: " http://rubyforge.org/projects/bfts"
|
13
13
|
rubyforge_project: bfts
|
14
|
-
description: miniunit is a completely minimial drop-in replacement for ruby's test/unit. This is meant for language implementors
|
14
|
+
description: miniunit is a completely minimial drop-in replacement for ruby's test/unit. This is meant to be clean and easy to use both as a regular test writer and for language implementors that need a minimal set of methods to bootstrap a working unit test suite.
|
15
15
|
autorequire:
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
@@ -29,18 +29,25 @@ post_install_message:
|
|
29
29
|
authors:
|
30
30
|
- Ryan Davis
|
31
31
|
files:
|
32
|
+
- .autotest
|
32
33
|
- History.txt
|
33
34
|
- Manifest.txt
|
34
35
|
- README.txt
|
35
36
|
- Rakefile
|
36
37
|
- lib/test/unit.rb
|
37
38
|
- lib/test/unit/testcase.rb
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
- test/test_test_case.rb
|
40
|
+
- test/test_test_unit.rb
|
41
|
+
test_files:
|
42
|
+
- test/test_test_case.rb
|
43
|
+
- test/test_test_unit.rb
|
44
|
+
rdoc_options:
|
45
|
+
- --main
|
46
|
+
- README.txt
|
47
|
+
extra_rdoc_files:
|
48
|
+
- History.txt
|
49
|
+
- Manifest.txt
|
50
|
+
- README.txt
|
44
51
|
executables: []
|
45
52
|
|
46
53
|
extensions: []
|
@@ -55,5 +62,5 @@ dependencies:
|
|
55
62
|
requirements:
|
56
63
|
- - ">="
|
57
64
|
- !ruby/object:Gem::Version
|
58
|
-
version: 1.
|
65
|
+
version: 1.3.0
|
59
66
|
version:
|