mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/runit, lib/rubyunit.rb, test/testunit/runit: removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bda85cb021
commit
923d3ea159
13 changed files with 4 additions and 951 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Fri Dec 21 12:55:39 2007 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* lib/runit, lib/rubyunit.rb, test/testunit/runit: removed.
|
||||||
|
|
||||||
Fri Dec 21 12:32:08 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Fri Dec 21 12:32:08 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* file.c (Init_File): File.exists? revived.
|
* file.c (Init_File): File.exists? revived.
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
# Author:: Nathaniel Talbott.
|
|
||||||
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
|
||||||
# License:: Ruby license.
|
|
||||||
|
|
||||||
require 'runit/testcase'
|
|
||||||
require 'test/unit'
|
|
|
@ -1,76 +0,0 @@
|
||||||
# Author:: Nathaniel Talbott.
|
|
||||||
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
|
||||||
# License:: Ruby license.
|
|
||||||
|
|
||||||
require 'test/unit/assertions'
|
|
||||||
require 'runit/error'
|
|
||||||
|
|
||||||
module RUNIT
|
|
||||||
module AssertMixin
|
|
||||||
|
|
||||||
def setup_assert
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_no_exception(*args, &block)
|
|
||||||
assert_nothing_raised(*args, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
# To deal with the fact that RubyUnit does not check that the
|
|
||||||
# regular expression is, indeed, a regular expression, if it is
|
|
||||||
# not, we do our own assertion using the same semantics as
|
|
||||||
# RubyUnit
|
|
||||||
def assert_match(actual_string, expected_re, message="")
|
|
||||||
_wrap_assertion {
|
|
||||||
full_message = build_message(message, "Expected <?> to match <?>", actual_string, expected_re)
|
|
||||||
assert_block(full_message) {
|
|
||||||
expected_re =~ actual_string
|
|
||||||
}
|
|
||||||
Regexp.last_match
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_not_nil(actual, message="")
|
|
||||||
assert(!actual.nil?, message)
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_not_match(actual_string, expected_re, message="")
|
|
||||||
assert_no_match(expected_re, actual_string, message)
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_matches(*args)
|
|
||||||
assert_match(*args)
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_fail(message="")
|
|
||||||
flunk(message)
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_equal_float(expected, actual, delta, message="")
|
|
||||||
assert_in_delta(expected, actual, delta, message)
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_send(object, method, *args)
|
|
||||||
super([object, method, *args])
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_exception(exception, message="", &block)
|
|
||||||
assert_raises(exception, message, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_respond_to(method, object, message="")
|
|
||||||
if (called_internally?)
|
|
||||||
super
|
|
||||||
else
|
|
||||||
super(object, method, message)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def called_internally?
|
|
||||||
/assertions\.rb/.match(caller[1])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
module Assert
|
|
||||||
include Test::Unit::Assertions
|
|
||||||
include AssertMixin
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,51 +0,0 @@
|
||||||
# Author:: Nathaniel Talbott.
|
|
||||||
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
|
||||||
# License:: Ruby license.
|
|
||||||
|
|
||||||
require 'test/unit/ui/console/testrunner'
|
|
||||||
require 'runit/testresult'
|
|
||||||
|
|
||||||
module RUNIT
|
|
||||||
module CUI
|
|
||||||
class TestRunner < Test::Unit::UI::Console::TestRunner
|
|
||||||
@@quiet_mode = false
|
|
||||||
|
|
||||||
def self.run(suite)
|
|
||||||
self.new().run(suite)
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize
|
|
||||||
super nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def run(suite, quiet_mode=@@quiet_mode)
|
|
||||||
@suite = suite
|
|
||||||
def @suite.suite
|
|
||||||
self
|
|
||||||
end
|
|
||||||
@output_level = (quiet_mode ? Test::Unit::UI::PROGRESS_ONLY : Test::Unit::UI::VERBOSE)
|
|
||||||
start
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_mediator(suite)
|
|
||||||
mediator = Test::Unit::UI::TestRunnerMediator.new(suite)
|
|
||||||
class << mediator
|
|
||||||
attr_writer :result_delegate
|
|
||||||
def create_result
|
|
||||||
return @result_delegate.create_result
|
|
||||||
end
|
|
||||||
end
|
|
||||||
mediator.result_delegate = self
|
|
||||||
return mediator
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_result
|
|
||||||
return RUNIT::TestResult.new
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.quiet_mode=(boolean)
|
|
||||||
@@quiet_mode = boolean
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,9 +0,0 @@
|
||||||
# Author:: Nathaniel Talbott.
|
|
||||||
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
|
||||||
# License:: Ruby license.
|
|
||||||
|
|
||||||
require 'test/unit/assertionfailederror.rb'
|
|
||||||
|
|
||||||
module RUNIT
|
|
||||||
AssertionFailedError = Test::Unit::AssertionFailedError
|
|
||||||
end
|
|
|
@ -1,45 +0,0 @@
|
||||||
# Author:: Nathaniel Talbott.
|
|
||||||
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
|
||||||
# License:: Ruby license.
|
|
||||||
|
|
||||||
require 'runit/testresult'
|
|
||||||
require 'runit/testsuite'
|
|
||||||
require 'runit/assert'
|
|
||||||
require 'runit/error'
|
|
||||||
require 'test/unit/testcase'
|
|
||||||
|
|
||||||
module RUNIT
|
|
||||||
class TestCase < Test::Unit::TestCase
|
|
||||||
include RUNIT::AssertMixin
|
|
||||||
|
|
||||||
def self.suite
|
|
||||||
method_names = instance_methods(true)
|
|
||||||
tests = method_names.delete_if { |method_name| method_name !~ /^test/ }
|
|
||||||
suite = TestSuite.new(name)
|
|
||||||
tests.each {
|
|
||||||
|test|
|
|
||||||
catch(:invalid_test) {
|
|
||||||
suite << new(test, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return suite
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize(test_name, suite_name=self.class.name)
|
|
||||||
super(test_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_equals(*args)
|
|
||||||
assert_equal(*args)
|
|
||||||
end
|
|
||||||
|
|
||||||
def name
|
|
||||||
super.sub(/^(.*?)\((.*)\)$/, '\2#\1')
|
|
||||||
end
|
|
||||||
|
|
||||||
def run(result, &progress_block)
|
|
||||||
progress_block = proc {} unless (block_given?)
|
|
||||||
super(result, &progress_block)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,44 +0,0 @@
|
||||||
# Author:: Nathaniel Talbott.
|
|
||||||
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
|
||||||
# License:: Ruby license.
|
|
||||||
|
|
||||||
require 'test/unit/testresult'
|
|
||||||
|
|
||||||
module RUNIT
|
|
||||||
class TestResult < Test::Unit::TestResult
|
|
||||||
attr_reader(:errors, :failures)
|
|
||||||
def succeed?
|
|
||||||
return passed?
|
|
||||||
end
|
|
||||||
def failure_size
|
|
||||||
return failure_count
|
|
||||||
end
|
|
||||||
def run_asserts
|
|
||||||
return assertion_count
|
|
||||||
end
|
|
||||||
def error_size
|
|
||||||
return error_count
|
|
||||||
end
|
|
||||||
def run_tests
|
|
||||||
return run_count
|
|
||||||
end
|
|
||||||
def add_failure(failure)
|
|
||||||
def failure.at
|
|
||||||
return location
|
|
||||||
end
|
|
||||||
def failure.err
|
|
||||||
return message
|
|
||||||
end
|
|
||||||
super(failure)
|
|
||||||
end
|
|
||||||
def add_error(error)
|
|
||||||
def error.at
|
|
||||||
return location
|
|
||||||
end
|
|
||||||
def error.err
|
|
||||||
return exception
|
|
||||||
end
|
|
||||||
super(error)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,26 +0,0 @@
|
||||||
# Author:: Nathaniel Talbott.
|
|
||||||
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
|
||||||
# License:: Ruby license.
|
|
||||||
|
|
||||||
require 'test/unit/testsuite'
|
|
||||||
|
|
||||||
module RUNIT
|
|
||||||
class TestSuite < Test::Unit::TestSuite
|
|
||||||
def add_test(*args)
|
|
||||||
add(*args)
|
|
||||||
end
|
|
||||||
|
|
||||||
def add(*args)
|
|
||||||
self.<<(*args)
|
|
||||||
end
|
|
||||||
|
|
||||||
def count_test_cases
|
|
||||||
return size
|
|
||||||
end
|
|
||||||
|
|
||||||
def run(result, &progress_block)
|
|
||||||
progress_block = proc {} unless (block_given?)
|
|
||||||
super(result, &progress_block)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,8 +0,0 @@
|
||||||
# Author:: Nathaniel Talbott.
|
|
||||||
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
|
||||||
# License:: Ruby license.
|
|
||||||
|
|
||||||
module RUNIT
|
|
||||||
module ToPublic
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,402 +0,0 @@
|
||||||
# Author:: Masaki Suketa.
|
|
||||||
# Adapted by:: Nathaniel Talbott.
|
|
||||||
# Copyright:: Copyright (c) Masaki Suketa. All rights reserved.
|
|
||||||
# Copyright:: Copyright (c) 2002 Nathaniel Talbott. All rights reserved.
|
|
||||||
# License:: Ruby license.
|
|
||||||
|
|
||||||
require 'rubyunit'
|
|
||||||
|
|
||||||
module RUNIT
|
|
||||||
class TargetAssert
|
|
||||||
include RUNIT::Assert
|
|
||||||
end
|
|
||||||
|
|
||||||
class TestAssert < RUNIT::TestCase
|
|
||||||
def setup
|
|
||||||
@assert = TargetAssert.new
|
|
||||||
@e = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert
|
|
||||||
sub_test_assert_pass(true)
|
|
||||||
sub_test_assert_pass(TRUE)
|
|
||||||
sub_test_assert_failure(false)
|
|
||||||
sub_test_assert_failure(FALSE)
|
|
||||||
sub_test_assert_failure(nil)
|
|
||||||
sub_test_assert_pass("")
|
|
||||||
sub_test_assert_pass("ok")
|
|
||||||
sub_test_assert_pass(0)
|
|
||||||
sub_test_assert_pass(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_with_2_argument
|
|
||||||
assert_no_exception {
|
|
||||||
assert(true, "3")
|
|
||||||
}
|
|
||||||
assert_no_exception {
|
|
||||||
assert(true)
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_equal_float_0_1
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_equal_float(1.4, 1.35, 0.1)
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_equal_float_0_5
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_equal_float(1.4, 1.34, 0.5)
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_equal_float_0
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_equal_float(1.4, 1.4, 0)
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_equal_float_0_raise
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_equal_float(1.4, 1.34, 0)
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_equal_float_0_01
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_equal_float(1.4, 1.35, 0.01)
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_equal_float_0_001
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_equal_float(Math.sqrt(2), 1.414, 0.001)
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_equal_float_minus_1_0
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_equal_float(1.4, 1.35, -1.0)
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_fail
|
|
||||||
except = nil
|
|
||||||
begin
|
|
||||||
@assert.assert_fail("failure")
|
|
||||||
rescue Exception
|
|
||||||
except = $!
|
|
||||||
end
|
|
||||||
assert_not_nil(except)
|
|
||||||
end
|
|
||||||
|
|
||||||
def sub_test_assert_pass(obj)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert(obj)
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def sub_test_assert_failure(obj)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert(obj)
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_equal
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_equal(2, 2)
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_equal(2, 3)
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_nil
|
|
||||||
obj = nil
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_nil(obj)
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
obj = 'string'
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_not_nil
|
|
||||||
obj = 'string'
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_not_nil(obj)
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
|
|
||||||
obj = nil
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_operator
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_operator(2, :<, 3)
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_operator(2, :>, 3)
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_respond_to
|
|
||||||
sub_test_assert_respond_to('string', 'sub', 'foo')
|
|
||||||
sub_test_assert_respond_to('string', :sub, :foo)
|
|
||||||
end
|
|
||||||
|
|
||||||
def sub_test_assert_respond_to(obj, msg, dummy_msg)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_respond_to(msg, obj)
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_respond_to(dummy_msg, obj)
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_send
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
ary = []
|
|
||||||
@assert.assert_send ary, :empty?
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
ary = [2,3]
|
|
||||||
@assert.assert_send ary, :empty?
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
str = "abc"
|
|
||||||
@assert.assert_send str, :sub!, "z", "y"
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_kind_of
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_kind_of(String, "string")
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_kind_of(Regexp, "string")
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_instance_of
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_instance_of(String, "string")
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_instance_of(Object, "string")
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_match
|
|
||||||
assert_proc = Proc.new{
|
|
||||||
@assert.assert_match('foostring', /foo/)
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_match('barstring', /foo/)
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
match = @assert.assert_match('foostring', /foo/)
|
|
||||||
assert_instance_of(MatchData, match)
|
|
||||||
assert_equal('foo', match[0])
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_matches
|
|
||||||
assert_proc = Proc.new{
|
|
||||||
@assert.assert_matches('foostring', /foo/)
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_matches('barstring', /foo/)
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_not_match
|
|
||||||
assert_proc = Proc.new{
|
|
||||||
@assert.assert_not_match('barstring', /foo/)
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_not_match('foostring', /foo/)
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_not_match('foobarbaz', /ba.+/)
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_same
|
|
||||||
flag = false
|
|
||||||
e = "foo"
|
|
||||||
a = e
|
|
||||||
assert_proc = Proc.new {@assert.assert_same(e, a)}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
|
|
||||||
a = "foo"
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_exception
|
|
||||||
assert_proc = Proc.new{
|
|
||||||
@assert.assert_exception(IOError) {
|
|
||||||
raise IOError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
|
|
||||||
assert_proc = Proc.new{
|
|
||||||
@assert.assert_exception(StandardError) {
|
|
||||||
raise IOError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
|
|
||||||
assert_proc = Proc.new{
|
|
||||||
@assert.assert_exception(IOError, "Exception") {
|
|
||||||
raise StandardError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_exception(StandardError) {
|
|
||||||
"No Exception raised in this block"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_exception(StandardError) {
|
|
||||||
exit(33)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
|
|
||||||
t = @assert.assert_exception(IOError) {
|
|
||||||
raise IOError
|
|
||||||
}
|
|
||||||
assert_instance_of(IOError, t)
|
|
||||||
t = @assert.assert_exception(NameError) {
|
|
||||||
non_existent_method
|
|
||||||
}
|
|
||||||
assert_instance_of(NameError, t)
|
|
||||||
t = @assert.assert_exception(SystemExit) {
|
|
||||||
exit(33)
|
|
||||||
}
|
|
||||||
assert_instance_of(SystemExit, t)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_assert_no_exception
|
|
||||||
assert_proc = Proc.new{
|
|
||||||
@assert.assert_no_exception(IOError, ArgumentError) {
|
|
||||||
"No Exception raised in this block"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub_assert_pass(assert_proc)
|
|
||||||
|
|
||||||
assert_proc = Proc.new{
|
|
||||||
@assert.assert_no_exception(IOError, ArgumentError) {
|
|
||||||
raise StandardError, "Standard Error raised"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub_assert_raise_error(assert_proc)
|
|
||||||
|
|
||||||
assert_proc = Proc.new{
|
|
||||||
@assert.assert_no_exception(IOError, ArgumentError) {
|
|
||||||
raise ArgumentError, "Bad Argument"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
|
|
||||||
assert_proc = Proc.new{
|
|
||||||
@assert.assert_no_exception {
|
|
||||||
raise ArgumentError, "Bad Argument"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
|
|
||||||
assert_proc = Proc.new{
|
|
||||||
@assert.assert_no_exception {
|
|
||||||
raise NameError, "Bad Name"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
assert_proc = Proc.new {
|
|
||||||
@assert.assert_no_exception {
|
|
||||||
raise NoMemoryError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub_assert_raise_fail(assert_proc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def sub_assert_pass(p)
|
|
||||||
flag = false
|
|
||||||
err = nil
|
|
||||||
begin
|
|
||||||
p.call
|
|
||||||
flag = true
|
|
||||||
rescue
|
|
||||||
err = $!
|
|
||||||
flag = false
|
|
||||||
end
|
|
||||||
assert(flag, err.to_s)
|
|
||||||
end
|
|
||||||
|
|
||||||
def sub_assert_raise_fail(p)
|
|
||||||
flag = false
|
|
||||||
err = nil
|
|
||||||
begin
|
|
||||||
p.call
|
|
||||||
flag = false
|
|
||||||
rescue RUNIT::AssertionFailedError
|
|
||||||
flag = true
|
|
||||||
err = $!
|
|
||||||
rescue Exception
|
|
||||||
flag = false
|
|
||||||
err = $!
|
|
||||||
end
|
|
||||||
assert(flag, err.to_s)
|
|
||||||
end
|
|
||||||
|
|
||||||
def sub_assert_raise_error(p)
|
|
||||||
flag = false
|
|
||||||
err = nil
|
|
||||||
begin
|
|
||||||
p.call
|
|
||||||
flag = false
|
|
||||||
rescue RUNIT::AssertionFailedError
|
|
||||||
flag = false
|
|
||||||
err = $!
|
|
||||||
rescue Exception
|
|
||||||
flag = true
|
|
||||||
err = $!
|
|
||||||
end
|
|
||||||
assert(flag, err.to_s)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,91 +0,0 @@
|
||||||
# Author:: Masaki Suketa.
|
|
||||||
# Adapted by:: Nathaniel Talbott.
|
|
||||||
# Copyright:: Copyright (c) Masaki Suketa. All rights reserved.
|
|
||||||
# Copyright:: Copyright (c) 2002 Nathaniel Talbott. All rights reserved.
|
|
||||||
# License:: Ruby license.
|
|
||||||
|
|
||||||
require 'rubyunit'
|
|
||||||
|
|
||||||
module RUNIT
|
|
||||||
class DummyError < StandardError
|
|
||||||
end
|
|
||||||
|
|
||||||
class TestTestCase < RUNIT::TestCase
|
|
||||||
def setup
|
|
||||||
@dummy_testcase = Class.new(RUNIT::TestCase) do
|
|
||||||
def self.name
|
|
||||||
"DummyTestCase"
|
|
||||||
end
|
|
||||||
|
|
||||||
attr_reader :status, :dummy_called, :dummy2_called
|
|
||||||
|
|
||||||
def initialize(*arg)
|
|
||||||
super(*arg)
|
|
||||||
@status = 0
|
|
||||||
@dummy_called = false
|
|
||||||
@dummy2_called = false
|
|
||||||
end
|
|
||||||
|
|
||||||
def setup
|
|
||||||
@status = 1 if @status == 0
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_dummy
|
|
||||||
@status = 2 if @status == 1
|
|
||||||
@dummy_called = true
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_dummy2
|
|
||||||
@status = 2 if @status == 1
|
|
||||||
@dummy2_called = true
|
|
||||||
raise DummyError
|
|
||||||
end
|
|
||||||
|
|
||||||
def teardown
|
|
||||||
@status = 3 if @status == 2
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@test1 = @dummy_testcase.new('test_dummy')
|
|
||||||
@test2 = @dummy_testcase.new('test_dummy2', 'TestCase')
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_name
|
|
||||||
assert_equal('DummyTestCase#test_dummy', @test1.name) # The second parameter to #initialize is ignored in emulation
|
|
||||||
assert_equal('DummyTestCase#test_dummy2', @test2.name)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_run
|
|
||||||
result = RUNIT::TestResult.new
|
|
||||||
@test1.run(result)
|
|
||||||
assert_equal(1, result.run_count)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_s_suite
|
|
||||||
suite = @dummy_testcase.suite
|
|
||||||
assert_instance_of(RUNIT::TestSuite, suite)
|
|
||||||
assert_equal(2, suite.count_test_cases)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_teardown_err
|
|
||||||
suite = Class.new(RUNIT::TestCase) do
|
|
||||||
def test_foo
|
|
||||||
assert(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_bar
|
|
||||||
assert(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
def teardown
|
|
||||||
raise StandardError
|
|
||||||
end
|
|
||||||
end.suite
|
|
||||||
|
|
||||||
result = RUNIT::TestResult.new
|
|
||||||
suite.run(result)
|
|
||||||
assert_equal(2, result.error_size)
|
|
||||||
assert_equal(1, result.failure_size)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,144 +0,0 @@
|
||||||
# Author:: Masaki Suketa.
|
|
||||||
# Adapted by:: Nathaniel Talbott.
|
|
||||||
# Copyright:: Copyright (c) Masaki Suketa. All rights reserved.
|
|
||||||
# Copyright:: Copyright (c) 2002 Nathaniel Talbott. All rights reserved.
|
|
||||||
# License:: Ruby license.
|
|
||||||
|
|
||||||
require 'rubyunit'
|
|
||||||
|
|
||||||
module RUNIT
|
|
||||||
class TestTestResult < RUNIT::TestCase
|
|
||||||
def setup
|
|
||||||
@result = RUNIT::TestResult.new
|
|
||||||
|
|
||||||
@normal_suite = Class::new(RUNIT::TestCase) do
|
|
||||||
def test_1
|
|
||||||
assert(true)
|
|
||||||
assert(true)
|
|
||||||
end
|
|
||||||
end.suite
|
|
||||||
|
|
||||||
@failure_suite = Class::new(RUNIT::TestCase) do
|
|
||||||
def test_1
|
|
||||||
assert(true)
|
|
||||||
assert(false)
|
|
||||||
end
|
|
||||||
end.suite
|
|
||||||
|
|
||||||
@error_suite = Class::new(RUNIT::TestCase) do
|
|
||||||
def setup
|
|
||||||
raise ScriptError
|
|
||||||
end
|
|
||||||
def test_1
|
|
||||||
assert(true)
|
|
||||||
end
|
|
||||||
end.suite
|
|
||||||
|
|
||||||
@multi_failure_suite = Class::new(RUNIT::TestCase) do
|
|
||||||
def test1
|
|
||||||
assert(false)
|
|
||||||
end
|
|
||||||
def test2
|
|
||||||
assert(false)
|
|
||||||
end
|
|
||||||
def test3
|
|
||||||
assert(false)
|
|
||||||
end
|
|
||||||
end.suite
|
|
||||||
|
|
||||||
@with_error_suite = Class::new(RUNIT::TestCase) do
|
|
||||||
def test1
|
|
||||||
raise StandardError
|
|
||||||
end
|
|
||||||
end.suite
|
|
||||||
|
|
||||||
@multi_error_suite = Class::new(RUNIT::TestCase) do
|
|
||||||
def test1
|
|
||||||
raise StandardError
|
|
||||||
end
|
|
||||||
def test2
|
|
||||||
raise StandardError
|
|
||||||
end
|
|
||||||
def test3
|
|
||||||
raise StandardError
|
|
||||||
end
|
|
||||||
end.suite
|
|
||||||
|
|
||||||
@multi_suite = Class::new(RUNIT::TestCase) do
|
|
||||||
def test_1
|
|
||||||
assert(true)
|
|
||||||
assert(true)
|
|
||||||
end
|
|
||||||
def test_2
|
|
||||||
assert(true)
|
|
||||||
end
|
|
||||||
def test_3
|
|
||||||
assert(true)
|
|
||||||
assert(false)
|
|
||||||
assert(true)
|
|
||||||
end
|
|
||||||
end.suite
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_error_size
|
|
||||||
@normal_suite.run(@result)
|
|
||||||
assert_equal(0, @result.error_size)
|
|
||||||
@with_error_suite.run(@result)
|
|
||||||
assert_equal(1, @result.error_size)
|
|
||||||
@multi_error_suite.run(@result)
|
|
||||||
assert_equal(4, @result.error_size)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_errors
|
|
||||||
@normal_suite.run(@result)
|
|
||||||
assert_equal(0, @result.errors.size)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_failure_size
|
|
||||||
@normal_suite.run(@result)
|
|
||||||
assert_equal(0, @result.failure_size)
|
|
||||||
@failure_suite.run(@result)
|
|
||||||
assert_equal(1, @result.failure_size)
|
|
||||||
@multi_failure_suite.run(@result)
|
|
||||||
assert_equal(4, @result.failure_size)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_failures
|
|
||||||
@normal_suite.run(@result)
|
|
||||||
assert_equal(0, @result.failures.size)
|
|
||||||
@failure_suite.run(@result)
|
|
||||||
assert_equal(1, @result.failures.size)
|
|
||||||
@multi_failure_suite.run(@result)
|
|
||||||
assert_equal(4, @result.failures.size)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_run_no_exception
|
|
||||||
assert_no_exception {
|
|
||||||
@error_suite.run(@result)
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_run_asserts
|
|
||||||
@normal_suite.run(@result)
|
|
||||||
assert_equal(2, @result.run_asserts)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_run_asserts2
|
|
||||||
@failure_suite.run(@result)
|
|
||||||
assert_equal(2, @result.run_asserts)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_run_tests
|
|
||||||
assert_equal(0, @result.run_tests)
|
|
||||||
@normal_suite.run(@result)
|
|
||||||
assert_equal(1, @result.run_tests)
|
|
||||||
@multi_suite.run(@result)
|
|
||||||
assert_equal(4, @result.run_tests)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_succeed?
|
|
||||||
@normal_suite.run(@result)
|
|
||||||
assert(@result.succeed?)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,49 +0,0 @@
|
||||||
# Author:: Masaki Suketa.
|
|
||||||
# Adapted by:: Nathaniel Talbott.
|
|
||||||
# Copyright:: Copyright (c) Masaki Suketa. All rights reserved.
|
|
||||||
# Copyright:: Copyright (c) 2002 Nathaniel Talbott. All rights reserved.
|
|
||||||
# License:: Ruby license.
|
|
||||||
|
|
||||||
require 'rubyunit'
|
|
||||||
|
|
||||||
module RUNIT
|
|
||||||
class TestTestSuite < RUNIT::TestCase
|
|
||||||
def setup
|
|
||||||
@testsuite = RUNIT::TestSuite.new
|
|
||||||
@dummy_test = Class.new(RUNIT::TestCase) do
|
|
||||||
def test_foo
|
|
||||||
end
|
|
||||||
def test_bar
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@dummy_empty_test = Class.new(RUNIT::TestCase){}
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_count_test_cases
|
|
||||||
assert_equal(0, @testsuite.count_test_cases)
|
|
||||||
|
|
||||||
@testsuite.add(@dummy_empty_test.suite)
|
|
||||||
assert_equal(0, @testsuite.count_test_cases)
|
|
||||||
|
|
||||||
@testsuite.add(@dummy_test.suite)
|
|
||||||
assert_equal(2, @testsuite.count_test_cases)
|
|
||||||
|
|
||||||
@testsuite.add(@dummy_test.suite)
|
|
||||||
assert_equal(4, @testsuite.count_test_cases)
|
|
||||||
|
|
||||||
dummytest_foo = @dummy_test.new('test_foo')
|
|
||||||
@testsuite.add(dummytest_foo)
|
|
||||||
assert_equal(5, @testsuite.count_test_cases)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_add
|
|
||||||
@testsuite.add(@dummy_empty_test.suite)
|
|
||||||
assert_equal(0, @testsuite.size)
|
|
||||||
assert_equal(0, @testsuite.count_test_cases)
|
|
||||||
|
|
||||||
@testsuite.add(@dummy_test.suite)
|
|
||||||
assert_equal(2, @testsuite.size)
|
|
||||||
assert_equal(2, @testsuite.count_test_cases)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Add table
Reference in a new issue