module Roby::Test::Self

This module is extending Test to be able to run tests using the normal testrb command. It is meant to be used to test libraries (e.g. Roby itself) as, in complex Roby applications, the setup and teardown steps would be very expensive.

@see Test

Public Instance Methods

enable_event_reporting(*filters) click to toggle source
# File lib/roby/test/self.rb, line 66
def enable_event_reporting(*filters)
    plan.event_logger.enabled = true
    filters.each { |f| plan.event_logger.filter(f) }
end
make_tmpdir() click to toggle source
# File lib/roby/test/self.rb, line 94
def make_tmpdir
    @temp_dirs << (dir = Dir.mktmpdir)
    dir
end
setup() click to toggle source
Calls superclass method Roby::Test::Assertions#setup
# File lib/roby/test/self.rb, line 40
def setup
    @temp_dirs = Array.new

    Roby.app.log['server'] = false
    Roby.app.auto_load_models = false
    Roby.app.plugins_enabled = false
    Roby.app.testing = true
    Roby.app.public_logs = false
    Roby.app.log_base_dir = make_tmpdir
    Roby.app.reset_log_dir
    Roby.app.setup
    Roby.app.prepare

    @plan    = ExecutablePlan.new(event_logger: EventReporter.new(STDOUT))
    @control = DecisionControl.new

    super

    # Save and restore some arrays
    save_collection Roby::ExecutionEngine.propagation_handlers
    save_collection Roby::ExecutionEngine.external_events_handlers
    save_collection Roby::Plan.structure_checks
    Roby.app.abort_on_exception = false
    Roby.app.abort_on_application_exception = true
end
teardown() click to toggle source
Calls superclass method Roby::Test::Assertions#teardown
# File lib/roby/test/self.rb, line 71
def teardown
    @temp_dirs.each { |p| FileUtils.rm_rf(p) }
    begin
        super
    rescue Exception => e
        teardown_failure = e
    end
    if execution_engine
        execution_engine.shutdown
    end
    Roby.app.shutdown
    Roby.app.cleanup
    State.clear
    State.clear_model
    Conf.clear
    Conf.clear_model

ensure
    if teardown_failure
        raise teardown_failure
    end
end