Class: Roby::App::Rake::RobotTestTask

Inherits:
BaseTestTask show all
Defined in:
lib/roby/app/rake.rb

Overview

Rake task to run the Roby tests

To use, add the following to your Rakefile:

require 'roby/app/rake'
Roby::App::Rake::TestTask.new

It create a test task per robot configuration, named “test:$#robot_name”. It also creates a test:all-robots task that runs each robot’s configuration in sequence. You can inspect these tasks with

rake --tasks

and call them with e.g.

rake test:default

The test:all-robots task will fail only at the end of all tests, reporting which configuration actually failed. To stop at the first failure, pass a ‘0’ as argument, e.g.

rake 'test:all-robots[0]'

Finally, the ‘test:all’ target runs syskit test –all (i.e. runs all tests in the default robot configuration)

The ‘test’ target points by default to test:all-robots. See below to change this.

The following examples show how to fine-tune the creates tests:

Examples:

restrict the tests to run only under the

'only_this_configuration' configuration

   Roby::App::Rake::TestTask.new do |t|
       t.robot_names = ['only_this_configuration']
   end

create tasks under the roby_tests namespace instead of ‘test’


Roby::App::Rake::TestCase.new('roby_tests')

make ‘test’ point to ‘test:all’


Roby::App::Rake::TestCase.new do |t|
    t.all_by_default = true
end

Defined Under Namespace

Classes: Failed

Instance Attribute Summary collapse

Attributes inherited from BaseTestTask

#app, #base_dir, #config, #excludes, #force_discovery, #report_dir, #self_only, #task_name, #test_files, #ui

Instance Method Summary collapse

Methods inherited from BaseTestTask

#coverage?, #force_discovery?, #keep_logs?, #read_captured_output_from_pipe, #run_roby, #run_roby_test, #self_only?, #spawn_process, #spawn_process_capturing_output, #ui?, #use_junit?, #wait_process_with_captured_output, #write_captured_output

Constructor Details

#initialize(task_name = "test", robot_name:, robot_type: nil) {|_self| ... } ⇒ RobotTestTask

Returns a new instance of RobotTestTask.

Yields:

  • (_self)

Yield Parameters:



600
601
602
603
604
605
606
607
# File 'lib/roby/app/rake.rb', line 600

def initialize(task_name = "test", robot_name:, robot_type: nil)
    super(task_name)

    @robot_name = robot_name
    @robot_type = robot_type || robot_name
    yield self if block_given?
    define
end

Instance Attribute Details

#robot_nameObject

Returns the value of attribute robot_name.



598
599
600
# File 'lib/roby/app/rake.rb', line 598

def robot_name
  @robot_name
end

#robot_typeObject

Returns the value of attribute robot_type.



598
599
600
# File 'lib/roby/app/rake.rb', line 598

def robot_type
  @robot_type
end

Instance Method Details

#defineObject



611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
# File 'lib/roby/app/rake.rb', line 611

def define
    test_args = %i[keep_going synchronize_output omit_tests_success]

    desc "run the tests for configuration #{robot_name}:#{robot_type}"
    task task_name, test_args do |t, args|
        synchronize_output = args.fetch(:synchronize_output, "0") == "1"
        omit_tests_success = args.fetch(:omit_tests_success, "0") == "1"

        result = run_roby_test(
            "-r", "#{robot_name},#{robot_type}",
            coverage_name: task_name,
            report_name: "#{robot_name}:#{robot_type}",
            synchronize_output: synchronize_output,
            omit_success: omit_tests_success
        )
        unless result
            raise Failed.new("failed to run tests for "\
                             "#{robot_name}:#{robot_type}"),
                  "tests failed"
        end
    end
end