[cairo-commit] rcairo/test-unit/lib/test/unit/ui testrunner.rb, NONE, 1.1 testrunnermediator.rb, NONE, 1.1 testrunnerutilities.rb, NONE, 1.1
Kouhei Sutou
commit at pdx.freedesktop.org
Wed Aug 13 01:20:58 PDT 2008
Committed by: kou
Update of /cvs/cairo/rcairo/test-unit/lib/test/unit/ui
In directory kemper:/tmp/cvs-serv10309/test-unit/lib/test/unit/ui
Added Files:
testrunner.rb testrunnermediator.rb testrunnerutilities.rb
Log Message:
* test-unit: imported Test::Unit 2.x.
--- NEW FILE: testrunner.rb ---
require 'test/unit/ui/testrunnerutilities'
module Test
module Unit
module UI
class TestRunner
extend TestRunnerUtilities
def initialize(suite, options={})
if suite.respond_to?(:suite)
@suite = suite.suite
else
@suite = suite
end
@options = options
end
end
end
end
end
--- NEW FILE: testrunnermediator.rb ---
#--
#
# Author:: Nathaniel Talbott.
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
# License:: Ruby license.
require 'test/unit'
require 'test/unit/util/observable'
require 'test/unit/testresult'
module Test
module Unit
module UI
# Provides an interface to write any given UI against,
# hopefully making it easy to write new UIs.
class TestRunnerMediator
RESET = name + "::RESET"
STARTED = name + "::STARTED"
FINISHED = name + "::FINISHED"
include Util::Observable
# Creates a new TestRunnerMediator initialized to run
# the passed suite.
def initialize(suite)
@suite = suite
end
# Runs the suite the TestRunnerMediator was created
# with.
def run_suite
Unit.run = true
result = create_result
result_listener = result.add_listener(TestResult::CHANGED) do |*args|
notify_listeners(TestResult::CHANGED, *args)
end
fault_listener = result.add_listener(TestResult::FAULT) do |*args|
notify_listeners(TestResult::FAULT, *args)
end
start_time = Time.now
begin
notify_listeners(RESET, @suite.size)
notify_listeners(STARTED, result)
@suite.run(result) do |channel, value|
notify_listeners(channel, value)
end
ensure
elapsed_time = Time.now - start_time
result.remove_listener(TestResult::FAULT, fault_listener)
result.remove_listener(TestResult::CHANGED, result_listener)
notify_listeners(FINISHED, elapsed_time)
end
result
end
private
# A factory method to create the result the mediator
# should run with. Can be overridden by subclasses if
# one wants to use a different result.
def create_result
TestResult.new
end
def measure_time
begin_time = Time.now
yield
Time.now - begin_time
end
end
end
end
end
--- NEW FILE: testrunnerutilities.rb ---
#--
#
# Author:: Nathaniel Talbott.
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
# License:: Ruby license.
module Test
module Unit
module UI
# Provides some utilities common to most, if not all,
# TestRunners.
#
#--
#
# Perhaps there ought to be a TestRunner superclass? There
# seems to be a decent amount of shared code between test
# runners.
module TestRunnerUtilities
# Creates a new TestRunner and runs the suite.
def run(suite, options={})
return new(suite, options).start
end
# Takes care of the ARGV parsing and suite
# determination necessary for running one of the
# TestRunners from the command line.
def start_command_line_test
if ARGV.empty?
puts "You should supply the name of a test suite file to the runner"
exit
end
require ARGV[0].gsub(/.+::/, '')
new(eval(ARGV[0])).start
end
end
end
end
end
More information about the cairo-commit
mailing list