rroonga 0.9.3-x86-mingw32 → 0.9.4-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.ja.rdoc +13 -0
- data/NEWS.rdoc +13 -0
- data/Rakefile +1 -1
- data/ext/groonga/extconf.rb +4 -3
- data/ext/groonga/rb-grn.h +698 -0
- data/html/developer.html +10 -7
- data/html/index.html +1 -1
- data/lib/1.8/groonga.so +0 -0
- data/lib/1.9/groonga.so +0 -0
- data/pkg-config.rb +1 -1
- data/test/run-test.rb +9 -3
- data/vendor/local/bin/libgroonga-0.dll +0 -0
- data/vendor/local/include/groonga.h +2285 -0
- data/vendor/local/lib/libgroonga.la +41 -0
- metadata +37 -85
- data/ext/groonga/mkmf.log +0 -99
- data/test-unit/Rakefile +0 -40
- data/test-unit/TODO +0 -5
- data/test-unit/bin/testrb +0 -5
- data/test-unit/html/classic.html +0 -15
- data/test-unit/html/index.html +0 -25
- data/test-unit/html/index.html.ja +0 -27
- data/test-unit/lib/test/unit/assertionfailederror.rb +0 -25
- data/test-unit/lib/test/unit/assertions.rb +0 -1230
- data/test-unit/lib/test/unit/attribute.rb +0 -125
- data/test-unit/lib/test/unit/autorunner.rb +0 -360
- data/test-unit/lib/test/unit/collector/descendant.rb +0 -23
- data/test-unit/lib/test/unit/collector/dir.rb +0 -108
- data/test-unit/lib/test/unit/collector/load.rb +0 -144
- data/test-unit/lib/test/unit/collector/objectspace.rb +0 -34
- data/test-unit/lib/test/unit/collector.rb +0 -36
- data/test-unit/lib/test/unit/color-scheme.rb +0 -102
- data/test-unit/lib/test/unit/color.rb +0 -96
- data/test-unit/lib/test/unit/diff.rb +0 -724
- data/test-unit/lib/test/unit/error.rb +0 -130
- data/test-unit/lib/test/unit/exceptionhandler.rb +0 -39
- data/test-unit/lib/test/unit/failure.rb +0 -136
- data/test-unit/lib/test/unit/fixture.rb +0 -176
- data/test-unit/lib/test/unit/notification.rb +0 -129
- data/test-unit/lib/test/unit/omission.rb +0 -191
- data/test-unit/lib/test/unit/pending.rb +0 -150
- data/test-unit/lib/test/unit/priority.rb +0 -180
- data/test-unit/lib/test/unit/runner/console.rb +0 -52
- data/test-unit/lib/test/unit/runner/emacs.rb +0 -8
- data/test-unit/lib/test/unit/runner/tap.rb +0 -8
- data/test-unit/lib/test/unit/testcase.rb +0 -476
- data/test-unit/lib/test/unit/testresult.rb +0 -89
- data/test-unit/lib/test/unit/testsuite.rb +0 -110
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +0 -14
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +0 -466
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +0 -63
- data/test-unit/lib/test/unit/ui/tap/testrunner.rb +0 -92
- data/test-unit/lib/test/unit/ui/testrunner.rb +0 -28
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +0 -77
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +0 -41
- data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -41
- data/test-unit/lib/test/unit/util/method-owner-finder.rb +0 -28
- data/test-unit/lib/test/unit/util/observable.rb +0 -90
- data/test-unit/lib/test/unit/util/procwrapper.rb +0 -48
- data/test-unit/lib/test/unit/version.rb +0 -7
- data/test-unit/lib/test/unit.rb +0 -323
- data/test-unit/sample/adder.rb +0 -13
- data/test-unit/sample/subtracter.rb +0 -12
- data/test-unit/sample/test_adder.rb +0 -20
- data/test-unit/sample/test_subtracter.rb +0 -20
- data/test-unit/sample/test_user.rb +0 -23
- data/test-unit/test/collector/test-descendant.rb +0 -133
- data/test-unit/test/collector/test-load.rb +0 -442
- data/test-unit/test/collector/test_dir.rb +0 -406
- data/test-unit/test/collector/test_objectspace.rb +0 -100
- data/test-unit/test/run-test.rb +0 -15
- data/test-unit/test/test-attribute.rb +0 -86
- data/test-unit/test/test-color-scheme.rb +0 -67
- data/test-unit/test/test-color.rb +0 -47
- data/test-unit/test/test-diff.rb +0 -518
- data/test-unit/test/test-emacs-runner.rb +0 -60
- data/test-unit/test/test-fixture.rb +0 -287
- data/test-unit/test/test-notification.rb +0 -33
- data/test-unit/test/test-omission.rb +0 -81
- data/test-unit/test/test-pending.rb +0 -70
- data/test-unit/test/test-priority.rb +0 -119
- data/test-unit/test/test-testcase.rb +0 -544
- data/test-unit/test/test_assertions.rb +0 -1151
- data/test-unit/test/test_error.rb +0 -26
- data/test-unit/test/test_failure.rb +0 -33
- data/test-unit/test/test_testresult.rb +0 -113
- data/test-unit/test/test_testsuite.rb +0 -129
- data/test-unit/test/testunit-test-util.rb +0 -14
- data/test-unit/test/ui/test_testrunmediator.rb +0 -20
- data/test-unit/test/util/test-method-owner-finder.rb +0 -38
- data/test-unit/test/util/test_backtracefilter.rb +0 -41
- data/test-unit/test/util/test_observable.rb +0 -102
- data/test-unit/test/util/test_procwrapper.rb +0 -36
@@ -1,77 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
#
|
3
|
-
# Author:: Nathaniel Talbott.
|
4
|
-
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
5
|
-
# License:: Ruby license.
|
6
|
-
|
7
|
-
require 'test/unit'
|
8
|
-
require 'test/unit/util/observable'
|
9
|
-
require 'test/unit/testresult'
|
10
|
-
|
11
|
-
module Test
|
12
|
-
module Unit
|
13
|
-
module UI
|
14
|
-
|
15
|
-
# Provides an interface to write any given UI against,
|
16
|
-
# hopefully making it easy to write new UIs.
|
17
|
-
class TestRunnerMediator
|
18
|
-
RESET = name + "::RESET"
|
19
|
-
STARTED = name + "::STARTED"
|
20
|
-
FINISHED = name + "::FINISHED"
|
21
|
-
|
22
|
-
include Util::Observable
|
23
|
-
|
24
|
-
# Creates a new TestRunnerMediator initialized to run
|
25
|
-
# the passed suite.
|
26
|
-
def initialize(suite)
|
27
|
-
@suite = suite
|
28
|
-
end
|
29
|
-
|
30
|
-
# Runs the suite the TestRunnerMediator was created
|
31
|
-
# with.
|
32
|
-
def run_suite
|
33
|
-
Unit.run = true
|
34
|
-
|
35
|
-
result = create_result
|
36
|
-
result_listener = result.add_listener(TestResult::CHANGED) do |*args|
|
37
|
-
notify_listeners(TestResult::CHANGED, *args)
|
38
|
-
end
|
39
|
-
fault_listener = result.add_listener(TestResult::FAULT) do |*args|
|
40
|
-
notify_listeners(TestResult::FAULT, *args)
|
41
|
-
end
|
42
|
-
|
43
|
-
start_time = Time.now
|
44
|
-
begin
|
45
|
-
notify_listeners(RESET, @suite.size)
|
46
|
-
notify_listeners(STARTED, result)
|
47
|
-
|
48
|
-
@suite.run(result) do |channel, value|
|
49
|
-
notify_listeners(channel, value)
|
50
|
-
end
|
51
|
-
ensure
|
52
|
-
elapsed_time = Time.now - start_time
|
53
|
-
result.remove_listener(TestResult::FAULT, fault_listener)
|
54
|
-
result.remove_listener(TestResult::CHANGED, result_listener)
|
55
|
-
notify_listeners(FINISHED, elapsed_time)
|
56
|
-
end
|
57
|
-
|
58
|
-
result
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
# A factory method to create the result the mediator
|
63
|
-
# should run with. Can be overridden by subclasses if
|
64
|
-
# one wants to use a different result.
|
65
|
-
def create_result
|
66
|
-
TestResult.new
|
67
|
-
end
|
68
|
-
|
69
|
-
def measure_time
|
70
|
-
begin_time = Time.now
|
71
|
-
yield
|
72
|
-
Time.now - begin_time
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
#
|
3
|
-
# Author:: Nathaniel Talbott.
|
4
|
-
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
5
|
-
# License:: Ruby license.
|
6
|
-
|
7
|
-
module Test
|
8
|
-
module Unit
|
9
|
-
module UI
|
10
|
-
|
11
|
-
# Provides some utilities common to most, if not all,
|
12
|
-
# TestRunners.
|
13
|
-
#
|
14
|
-
#--
|
15
|
-
#
|
16
|
-
# Perhaps there ought to be a TestRunner superclass? There
|
17
|
-
# seems to be a decent amount of shared code between test
|
18
|
-
# runners.
|
19
|
-
|
20
|
-
module TestRunnerUtilities
|
21
|
-
|
22
|
-
# Creates a new TestRunner and runs the suite.
|
23
|
-
def run(suite, options={})
|
24
|
-
return new(suite, options).start
|
25
|
-
end
|
26
|
-
|
27
|
-
# Takes care of the ARGV parsing and suite
|
28
|
-
# determination necessary for running one of the
|
29
|
-
# TestRunners from the command line.
|
30
|
-
def start_command_line_test
|
31
|
-
if ARGV.empty?
|
32
|
-
puts "You should supply the name of a test suite file to the runner"
|
33
|
-
exit
|
34
|
-
end
|
35
|
-
require ARGV[0].gsub(/.+::/, '')
|
36
|
-
new(eval(ARGV[0])).start
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Test
|
2
|
-
module Unit
|
3
|
-
module Util
|
4
|
-
module BacktraceFilter
|
5
|
-
TESTUNIT_FILE_SEPARATORS = %r{[\\/:]}
|
6
|
-
TESTUNIT_PREFIX = __FILE__.split(TESTUNIT_FILE_SEPARATORS)[0..-3]
|
7
|
-
TESTUNIT_RB_FILE = /\.rb\Z/
|
8
|
-
|
9
|
-
module_function
|
10
|
-
def filter_backtrace(backtrace, prefix=nil)
|
11
|
-
return ["No backtrace"] unless(backtrace)
|
12
|
-
split_p = if(prefix)
|
13
|
-
prefix.split(TESTUNIT_FILE_SEPARATORS)
|
14
|
-
else
|
15
|
-
TESTUNIT_PREFIX
|
16
|
-
end
|
17
|
-
match = proc do |e|
|
18
|
-
split_e = e.split(TESTUNIT_FILE_SEPARATORS)[0, split_p.size]
|
19
|
-
next false unless(split_e[0..-2] == split_p[0..-2])
|
20
|
-
split_e[-1].sub(TESTUNIT_RB_FILE, '') == split_p[-1]
|
21
|
-
end
|
22
|
-
return backtrace unless(backtrace.detect(&match))
|
23
|
-
found_prefix = false
|
24
|
-
new_backtrace = backtrace.reverse.reject do |e|
|
25
|
-
if(match[e])
|
26
|
-
found_prefix = true
|
27
|
-
true
|
28
|
-
elsif(found_prefix)
|
29
|
-
false
|
30
|
-
else
|
31
|
-
true
|
32
|
-
end
|
33
|
-
end.reverse
|
34
|
-
new_backtrace = (new_backtrace.empty? ? backtrace : new_backtrace)
|
35
|
-
new_backtrace = new_backtrace.reject(&match)
|
36
|
-
new_backtrace.empty? ? backtrace : new_backtrace
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Test
|
2
|
-
module Unit
|
3
|
-
module Util
|
4
|
-
module MethodOwnerFinder
|
5
|
-
module_function
|
6
|
-
def find(object, method_name)
|
7
|
-
method = object.method(method_name)
|
8
|
-
return method.owner if method.respond_to?(:owner)
|
9
|
-
|
10
|
-
if /\((.+?)\)\#/ =~ method.to_s
|
11
|
-
owner_name = $1
|
12
|
-
if /\A#</ =~ owner_name
|
13
|
-
ObjectSpace.each_object(Module) do |mod|
|
14
|
-
return mod if mod.to_s == owner_name
|
15
|
-
end
|
16
|
-
else
|
17
|
-
owner_name.split(/::/).inject(Object) do |parent, name|
|
18
|
-
parent.const_get(name)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
else
|
22
|
-
object.class
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
#
|
3
|
-
# Author:: Nathaniel Talbott.
|
4
|
-
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
5
|
-
# License:: Ruby license.
|
6
|
-
|
7
|
-
require 'test/unit/util/procwrapper'
|
8
|
-
|
9
|
-
module Test
|
10
|
-
module Unit
|
11
|
-
module Util
|
12
|
-
|
13
|
-
# This is a utility class that allows anything mixing
|
14
|
-
# it in to notify a set of listeners about interesting
|
15
|
-
# events.
|
16
|
-
module Observable
|
17
|
-
# We use this for defaults since nil might mean something
|
18
|
-
NOTHING = "NOTHING/#{__id__}"
|
19
|
-
|
20
|
-
# Adds the passed proc as a listener on the
|
21
|
-
# channel indicated by channel_name. listener_key
|
22
|
-
# is used to remove the listener later; if none is
|
23
|
-
# specified, the proc itself is used.
|
24
|
-
#
|
25
|
-
# Whatever is used as the listener_key is
|
26
|
-
# returned, making it very easy to use the proc
|
27
|
-
# itself as the listener_key:
|
28
|
-
#
|
29
|
-
# listener = add_listener("Channel") { ... }
|
30
|
-
# remove_listener("Channel", listener)
|
31
|
-
def add_listener(channel_name, listener_key=NOTHING, &listener) # :yields: value
|
32
|
-
unless(block_given?)
|
33
|
-
raise ArgumentError.new("No callback was passed as a listener")
|
34
|
-
end
|
35
|
-
|
36
|
-
key = listener_key
|
37
|
-
if (listener_key == NOTHING)
|
38
|
-
listener_key = listener
|
39
|
-
key = ProcWrapper.new(listener)
|
40
|
-
end
|
41
|
-
|
42
|
-
channels[channel_name] ||= {}
|
43
|
-
channels[channel_name][key] = listener
|
44
|
-
return listener_key
|
45
|
-
end
|
46
|
-
|
47
|
-
# Removes the listener indicated by listener_key
|
48
|
-
# from the channel indicated by
|
49
|
-
# channel_name. Returns the registered proc, or
|
50
|
-
# nil if none was found.
|
51
|
-
def remove_listener(channel_name, listener_key)
|
52
|
-
channel = channels[channel_name]
|
53
|
-
return nil unless (channel)
|
54
|
-
key = listener_key
|
55
|
-
if (listener_key.instance_of?(Proc))
|
56
|
-
key = ProcWrapper.new(listener_key)
|
57
|
-
end
|
58
|
-
if (channel.has_key?(key))
|
59
|
-
return channel.delete(key)
|
60
|
-
end
|
61
|
-
return nil
|
62
|
-
end
|
63
|
-
|
64
|
-
# Calls all the procs registered on the channel
|
65
|
-
# indicated by channel_name. If value is
|
66
|
-
# specified, it is passed in to the procs,
|
67
|
-
# otherwise they are called with no arguments.
|
68
|
-
#
|
69
|
-
#--
|
70
|
-
#
|
71
|
-
# Perhaps this should be private? Would it ever
|
72
|
-
# make sense for an external class to call this
|
73
|
-
# method directly?
|
74
|
-
def notify_listeners(channel_name, *arguments)
|
75
|
-
channel = channels[channel_name]
|
76
|
-
return 0 unless (channel)
|
77
|
-
listeners = channel.values
|
78
|
-
listeners.each { |listener| listener.call(*arguments) }
|
79
|
-
return listeners.size
|
80
|
-
end
|
81
|
-
|
82
|
-
private
|
83
|
-
def channels
|
84
|
-
@channels ||= {}
|
85
|
-
return @channels
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
#
|
3
|
-
# Author:: Nathaniel Talbott.
|
4
|
-
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
5
|
-
# License:: Ruby license.
|
6
|
-
|
7
|
-
module Test
|
8
|
-
module Unit
|
9
|
-
module Util
|
10
|
-
|
11
|
-
# Allows the storage of a Proc passed through '&' in a
|
12
|
-
# hash.
|
13
|
-
#
|
14
|
-
# Note: this may be inefficient, since the hash being
|
15
|
-
# used is not necessarily very good. In Observable,
|
16
|
-
# efficiency is not too important, since the hash is
|
17
|
-
# only accessed when adding and removing listeners,
|
18
|
-
# not when notifying.
|
19
|
-
|
20
|
-
class ProcWrapper
|
21
|
-
|
22
|
-
# Creates a new wrapper for a_proc.
|
23
|
-
def initialize(a_proc)
|
24
|
-
@a_proc = a_proc
|
25
|
-
@hash = a_proc.inspect.sub(/^(#<#{a_proc.class}:)/){''}.sub(/(>)$/){''}.hex
|
26
|
-
end
|
27
|
-
|
28
|
-
def hash
|
29
|
-
return @hash
|
30
|
-
end
|
31
|
-
|
32
|
-
def ==(other)
|
33
|
-
case(other)
|
34
|
-
when ProcWrapper
|
35
|
-
return @a_proc == other.to_proc
|
36
|
-
else
|
37
|
-
return super
|
38
|
-
end
|
39
|
-
end
|
40
|
-
alias :eql? :==
|
41
|
-
|
42
|
-
def to_proc
|
43
|
-
return @a_proc
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/test-unit/lib/test/unit.rb
DELETED
@@ -1,323 +0,0 @@
|
|
1
|
-
require 'test/unit/testcase'
|
2
|
-
require 'test/unit/autorunner'
|
3
|
-
|
4
|
-
module Test # :nodoc:
|
5
|
-
#
|
6
|
-
# = Test::Unit - Ruby Unit Testing Framework
|
7
|
-
#
|
8
|
-
# == Introduction
|
9
|
-
#
|
10
|
-
# Unit testing is making waves all over the place, largely due to the
|
11
|
-
# fact that it is a core practice of XP. While XP is great, unit testing
|
12
|
-
# has been around for a long time and has always been a good idea. One
|
13
|
-
# of the keys to good unit testing, though, is not just writing tests,
|
14
|
-
# but having tests. What's the difference? Well, if you just _write_ a
|
15
|
-
# test and throw it away, you have no guarantee that something won't
|
16
|
-
# change later which breaks your code. If, on the other hand, you _have_
|
17
|
-
# tests (obviously you have to write them first), and run them as often
|
18
|
-
# as possible, you slowly build up a wall of things that cannot break
|
19
|
-
# without you immediately knowing about it. This is when unit testing
|
20
|
-
# hits its peak usefulness.
|
21
|
-
#
|
22
|
-
# Enter Test::Unit, a framework for unit testing in Ruby, helping you to
|
23
|
-
# design, debug and evaluate your code by making it easy to write and
|
24
|
-
# have tests for it.
|
25
|
-
#
|
26
|
-
#
|
27
|
-
# == Notes
|
28
|
-
#
|
29
|
-
# Test::Unit has grown out of and superceded Lapidary.
|
30
|
-
#
|
31
|
-
#
|
32
|
-
# == Feedback
|
33
|
-
#
|
34
|
-
# I like (and do my best to practice) XP, so I value early releases,
|
35
|
-
# user feedback, and clean, simple, expressive code. There is always
|
36
|
-
# room for improvement in everything I do, and Test::Unit is no
|
37
|
-
# exception. Please, let me know what you think of Test::Unit as it
|
38
|
-
# stands, and what you'd like to see expanded/changed/improved/etc. If
|
39
|
-
# you find a bug, let me know ASAP; one good way to let me know what the
|
40
|
-
# bug is is to submit a new test that catches it :-) Also, I'd love to
|
41
|
-
# hear about any successes you have with Test::Unit, and any
|
42
|
-
# documentation you might add will be greatly appreciated. My contact
|
43
|
-
# info is below.
|
44
|
-
#
|
45
|
-
#
|
46
|
-
# == Contact Information
|
47
|
-
#
|
48
|
-
# A lot of discussion happens about Ruby in general on the ruby-talk
|
49
|
-
# mailing list (http://www.ruby-lang.org/en/ml.html), and you can ask
|
50
|
-
# any questions you might have there. I monitor the list, as do many
|
51
|
-
# other helpful Rubyists, and you're sure to get a quick answer. Of
|
52
|
-
# course, you're also welcome to email me (Nathaniel Talbott) directly
|
53
|
-
# at mailto:testunit@talbott.ws, and I'll do my best to help you out.
|
54
|
-
#
|
55
|
-
#
|
56
|
-
# == Credits
|
57
|
-
#
|
58
|
-
# I'd like to thank...
|
59
|
-
#
|
60
|
-
# Matz, for a great language!
|
61
|
-
#
|
62
|
-
# Masaki Suketa, for his work on RubyUnit, which filled a vital need in
|
63
|
-
# the Ruby world for a very long time. I'm also grateful for his help in
|
64
|
-
# polishing Test::Unit and getting the RubyUnit compatibility layer
|
65
|
-
# right. His graciousness in allowing Test::Unit to supercede RubyUnit
|
66
|
-
# continues to be a challenge to me to be more willing to defer my own
|
67
|
-
# rights.
|
68
|
-
#
|
69
|
-
# Ken McKinlay, for his interest and work on unit testing, and for his
|
70
|
-
# willingness to dialog about it. He was also a great help in pointing
|
71
|
-
# out some of the holes in the RubyUnit compatibility layer.
|
72
|
-
#
|
73
|
-
# Dave Thomas, for the original idea that led to the extremely simple
|
74
|
-
# "require 'test/unit'", plus his code to improve it even more by
|
75
|
-
# allowing the selection of tests from the command-line. Also, without
|
76
|
-
# RDoc, the documentation for Test::Unit would stink a lot more than it
|
77
|
-
# does now.
|
78
|
-
#
|
79
|
-
# Everyone who's helped out with bug reports, feature ideas,
|
80
|
-
# encouragement to continue, etc. It's a real privilege to be a part of
|
81
|
-
# the Ruby community.
|
82
|
-
#
|
83
|
-
# The guys at RoleModel Software, for putting up with me repeating, "But
|
84
|
-
# this would be so much easier in Ruby!" whenever we're coding in Java.
|
85
|
-
#
|
86
|
-
# My Creator, for giving me life, and giving it more abundantly.
|
87
|
-
#
|
88
|
-
#
|
89
|
-
# == License
|
90
|
-
#
|
91
|
-
# Test::Unit is copyright (c) 2000-2003 Nathaniel Talbott. It is free
|
92
|
-
# software, and is distributed under the Ruby license. See the COPYING
|
93
|
-
# file in the standard Ruby distribution for details.
|
94
|
-
#
|
95
|
-
#
|
96
|
-
# == Warranty
|
97
|
-
#
|
98
|
-
# This software is provided "as is" and without any express or
|
99
|
-
# implied warranties, including, without limitation, the implied
|
100
|
-
# warranties of merchantibility and fitness for a particular
|
101
|
-
# purpose.
|
102
|
-
#
|
103
|
-
#
|
104
|
-
# == Author
|
105
|
-
#
|
106
|
-
# Nathaniel Talbott.
|
107
|
-
# Copyright (c) 2000-2003, Nathaniel Talbott
|
108
|
-
#
|
109
|
-
# ----
|
110
|
-
#
|
111
|
-
# = Usage
|
112
|
-
#
|
113
|
-
# The general idea behind unit testing is that you write a _test_
|
114
|
-
# _method_ that makes certain _assertions_ about your code, working
|
115
|
-
# against a _test_ _fixture_. A bunch of these _test_ _methods_ are
|
116
|
-
# bundled up into a _test_ _suite_ and can be run any time the
|
117
|
-
# developer wants. The results of a run are gathered in a _test_
|
118
|
-
# _result_ and displayed to the user through some UI. So, lets break
|
119
|
-
# this down and see how Test::Unit provides each of these necessary
|
120
|
-
# pieces.
|
121
|
-
#
|
122
|
-
#
|
123
|
-
# == Assertions
|
124
|
-
#
|
125
|
-
# These are the heart of the framework. Think of an assertion as a
|
126
|
-
# statement of expected outcome, i.e. "I assert that x should be equal
|
127
|
-
# to y". If, when the assertion is executed, it turns out to be
|
128
|
-
# correct, nothing happens, and life is good. If, on the other hand,
|
129
|
-
# your assertion turns out to be false, an error is propagated with
|
130
|
-
# pertinent information so that you can go back and make your
|
131
|
-
# assertion succeed, and, once again, life is good. For an explanation
|
132
|
-
# of the current assertions, see Test::Unit::Assertions.
|
133
|
-
#
|
134
|
-
#
|
135
|
-
# == Test Method & Test Fixture
|
136
|
-
#
|
137
|
-
# Obviously, these assertions have to be called within a context that
|
138
|
-
# knows about them and can do something meaningful with their
|
139
|
-
# pass/fail value. Also, it's handy to collect a bunch of related
|
140
|
-
# tests, each test represented by a method, into a common test class
|
141
|
-
# that knows how to run them. The tests will be in a separate class
|
142
|
-
# from the code they're testing for a couple of reasons. First of all,
|
143
|
-
# it allows your code to stay uncluttered with test code, making it
|
144
|
-
# easier to maintain. Second, it allows the tests to be stripped out
|
145
|
-
# for deployment, since they're really there for you, the developer,
|
146
|
-
# and your users don't need them. Third, and most importantly, it
|
147
|
-
# allows you to set up a common test fixture for your tests to run
|
148
|
-
# against.
|
149
|
-
#
|
150
|
-
# What's a test fixture? Well, tests do not live in a vacuum; rather,
|
151
|
-
# they're run against the code they are testing. Often, a collection
|
152
|
-
# of tests will run against a common set of data, also called a
|
153
|
-
# fixture. If they're all bundled into the same test class, they can
|
154
|
-
# all share the setting up and tearing down of that data, eliminating
|
155
|
-
# unnecessary duplication and making it much easier to add related
|
156
|
-
# tests.
|
157
|
-
#
|
158
|
-
# Test::Unit::TestCase wraps up a collection of test methods together
|
159
|
-
# and allows you to easily set up and tear down the same test fixture
|
160
|
-
# for each test. This is done by overriding #setup and/or #teardown,
|
161
|
-
# which will be called before and after each test method that is
|
162
|
-
# run. The TestCase also knows how to collect the results of your
|
163
|
-
# assertions into a Test::Unit::TestResult, which can then be reported
|
164
|
-
# back to you... but I'm getting ahead of myself. To write a test,
|
165
|
-
# follow these steps:
|
166
|
-
#
|
167
|
-
# * Make sure Test::Unit is in your library path.
|
168
|
-
# * require 'test/unit' in your test script.
|
169
|
-
# * Create a class that subclasses Test::Unit::TestCase.
|
170
|
-
# * Add a method that begins with "test" to your class.
|
171
|
-
# * Make assertions in your test method.
|
172
|
-
# * Optionally define #setup and/or #teardown to set up and/or tear
|
173
|
-
# down your common test fixture.
|
174
|
-
# * You can now run your test as you would any other Ruby
|
175
|
-
# script... try it and see!
|
176
|
-
#
|
177
|
-
# A really simple test might look like this (#setup and #teardown are
|
178
|
-
# commented out to indicate that they are completely optional):
|
179
|
-
#
|
180
|
-
# require 'test/unit'
|
181
|
-
#
|
182
|
-
# class MyTest < Test::Unit::TestCase
|
183
|
-
# # def setup
|
184
|
-
# # end
|
185
|
-
#
|
186
|
-
# # def teardown
|
187
|
-
# # end
|
188
|
-
#
|
189
|
-
# def test_fail
|
190
|
-
# assert(false, 'Assertion was false.')
|
191
|
-
# end
|
192
|
-
# end
|
193
|
-
#
|
194
|
-
#
|
195
|
-
# == Test Runners
|
196
|
-
#
|
197
|
-
# So, now you have this great test class, but you still
|
198
|
-
# need a way to run it and view any failures that occur
|
199
|
-
# during the run. There are some test runner; console test
|
200
|
-
# runner, GTK+ test runner and so on. The console test
|
201
|
-
# runner is automatically invoked for you if you require
|
202
|
-
# 'test/unit' and simply run the file. To use another
|
203
|
-
# runner simply set default test runner ID to
|
204
|
-
# Test::Unit::AutoRunner:
|
205
|
-
#
|
206
|
-
# require 'test/unit'
|
207
|
-
# Test::Unit::AutoRunner.default_runner = "gtk2"
|
208
|
-
#
|
209
|
-
# == Test Suite
|
210
|
-
#
|
211
|
-
# As more and more unit tests accumulate for a given project, it
|
212
|
-
# becomes a real drag running them one at a time, and it also
|
213
|
-
# introduces the potential to overlook a failing test because you
|
214
|
-
# forget to run it. Suddenly it becomes very handy that the
|
215
|
-
# TestRunners can take any object that returns a Test::Unit::TestSuite
|
216
|
-
# in response to a suite method. The TestSuite can, in turn, contain
|
217
|
-
# other TestSuites or individual tests (typically created by a
|
218
|
-
# TestCase). In other words, you can easily wrap up a group of
|
219
|
-
# TestCases and TestSuites.
|
220
|
-
#
|
221
|
-
# Test::Unit does a little bit more for you, by wrapping
|
222
|
-
# these up automatically when you require
|
223
|
-
# 'test/unit'. What does this mean? It means you could
|
224
|
-
# write the above test case like this instead:
|
225
|
-
#
|
226
|
-
# require 'test/unit'
|
227
|
-
# require 'test_myfirsttests'
|
228
|
-
# require 'test_moretestsbyme'
|
229
|
-
# require 'test_anothersetoftests'
|
230
|
-
#
|
231
|
-
# Test::Unit is smart enough to find all the test cases existing in
|
232
|
-
# the ObjectSpace and wrap them up into a suite for you. It then runs
|
233
|
-
# the dynamic suite using the console TestRunner.
|
234
|
-
#
|
235
|
-
#
|
236
|
-
# == Configuration file
|
237
|
-
#
|
238
|
-
# Test::Unit reads 'test-unit.yml' in the current working
|
239
|
-
# directory as Test::Unit's configuration file. It can
|
240
|
-
# contain the following configurations:
|
241
|
-
#
|
242
|
-
# * color scheme definitions
|
243
|
-
# * test runner to be used
|
244
|
-
# * test runner options
|
245
|
-
# * test collector to be used
|
246
|
-
#
|
247
|
-
# Except color scheme definitions, all of them are
|
248
|
-
# specified by command line option.
|
249
|
-
#
|
250
|
-
# Here are sample color scheme definitions:
|
251
|
-
#
|
252
|
-
# color_schemes:
|
253
|
-
# inverted:
|
254
|
-
# success:
|
255
|
-
# name: red
|
256
|
-
# bold: true
|
257
|
-
# failure:
|
258
|
-
# name: green
|
259
|
-
# bold: true
|
260
|
-
# other_scheme:
|
261
|
-
# ...
|
262
|
-
#
|
263
|
-
# Here are the syntax of color scheme definitions:
|
264
|
-
#
|
265
|
-
# color_schemes:
|
266
|
-
# SCHEME_NAME:
|
267
|
-
# EVENT_NAME:
|
268
|
-
# name: COLOR_NAME
|
269
|
-
# intensity: BOOLEAN
|
270
|
-
# bold: BOOLEAN
|
271
|
-
# italic: BOOLEAN
|
272
|
-
# underline: BOOLEAN
|
273
|
-
# ...
|
274
|
-
# ...
|
275
|
-
#
|
276
|
-
# SCHEME_NAME:: the name of the color scheme
|
277
|
-
# EVENT_NAME:: one of [success, failure, pending,
|
278
|
-
# omission, notification, error]
|
279
|
-
# COLOR_NAME:: one of [black, red, green, yellow, blue,
|
280
|
-
# magenta, cyan, white]
|
281
|
-
# BOOLEAN:: true or false
|
282
|
-
#
|
283
|
-
# You can use the above 'inverted' color scheme with the
|
284
|
-
# following configuration:
|
285
|
-
#
|
286
|
-
# runner: console
|
287
|
-
# console_options:
|
288
|
-
# color_scheme: inverted
|
289
|
-
# color_schemes:
|
290
|
-
# inverted:
|
291
|
-
# success:
|
292
|
-
# name: red
|
293
|
-
# bold: true
|
294
|
-
# failure:
|
295
|
-
# name: green
|
296
|
-
# bold: true
|
297
|
-
#
|
298
|
-
# == Questions?
|
299
|
-
#
|
300
|
-
# I'd really like to get feedback from all levels of Ruby
|
301
|
-
# practitioners about typos, grammatical errors, unclear statements,
|
302
|
-
# missing points, etc., in this document (or any other).
|
303
|
-
#
|
304
|
-
|
305
|
-
module Unit
|
306
|
-
# Set true when Test::Unit has run. If set to true Test::Unit
|
307
|
-
# will not automatically run at exit.
|
308
|
-
def self.run=(flag)
|
309
|
-
@run = flag
|
310
|
-
end
|
311
|
-
|
312
|
-
# Already tests have run?
|
313
|
-
def self.run?
|
314
|
-
@run ||= false
|
315
|
-
end
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
at_exit do
|
320
|
-
unless $! || Test::Unit.run?
|
321
|
-
exit Test::Unit::AutoRunner.run
|
322
|
-
end
|
323
|
-
end
|
data/test-unit/sample/adder.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# Author:: Nathaniel Talbott.
|
2
|
-
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
3
|
-
# License:: Ruby license.
|
4
|
-
|
5
|
-
class Adder
|
6
|
-
def initialize(number)
|
7
|
-
@number = number
|
8
|
-
end
|
9
|
-
def add(number)
|
10
|
-
return @number + number
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# Author:: Nathaniel Talbott.
|
2
|
-
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
3
|
-
# License:: Ruby license.
|
4
|
-
|
5
|
-
class Subtracter
|
6
|
-
def initialize(number)
|
7
|
-
@number = number
|
8
|
-
end
|
9
|
-
def subtract(number)
|
10
|
-
return @number - number
|
11
|
-
end
|
12
|
-
end
|