class Roby::App::Rake::TestTask
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:
@example 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
@example create tasks under the roby_tests namespace instead of 'test'
Roby::App::Rake::TestCase.new('roby_tests')
@example make 'test' point to 'test:all'
Roby::App::Rake::TestCase.new do |t| t.all_by_default = true end
Attributes
The app
It defaults to Roby.app
Patterns matching excluded test files
It accepts any string that File.fnmatch? accepts
@return [Array<String>]
The list of robot configurations on which we should run the tests
Use 'default' for the default configuration. It defaults to all the robots defined in config/robots/
@return [Array<String,(String,String)>]
The base test task name
Public Class Methods
# File lib/roby/app/rake.rb, line 86 def initialize(task_name = 'test', all_by_default: false) @task_name = task_name @app = Roby.app @all_by_default = all_by_default @robot_names = discover_robot_names @excludes = [] yield self if block_given? define end
Public Instance Methods
# File lib/roby/app/rake.rb, line 98 def define each_robot do |robot_name, robot_type| task_name = task_name_for_robot(robot_name, robot_type) desc "run the tests for configuration #{robot_name}:#{robot_type}" task task_name do if !run_roby_test('-r', "#{robot_name},#{robot_type}") raise Failed.new("failed to run tests for #{robot_name}:#{robot_type}") end end end desc "run tests for all known robots" task "#{task_name}:all-robots", [:keep_going] do |t, args| failures = Array.new keep_going = args.fetch(:keep_going, '1') == '1' each_robot do |robot_name, robot_type| if !run_roby_test('-r', "#{robot_name},#{robot_type}") if keep_going failures << [robot_name, robot_type] else raise Failed.new("failed to run tests for #{robot_name}:#{robot_type}") end end end if !failures.empty? raise Failed.new("failed to run the following test(s): #{failures.map { |name, type| "#{name}:#{type}" }.join(", ")}") end end desc "run all tests" task "#{task_name}:all" do if !run_roby_test raise Failed.new("failed to run tests") end end if all_by_default? desc "run all tests" task task_name => "#{task_name}:all" else desc "run all robot tests" task task_name => "#{task_name}:all-robots" end end
@api private
Discover which robots are available on the current app
# File lib/roby/app/rake.rb, line 179 def discover_robot_names if !app.app_dir app.guess_app_dir end app.setup_robot_names_from_config_dir app.robots.each.to_a end
Enumerate the robots on which tests should be run
# File lib/roby/app/rake.rb, line 172 def each_robot(&block) robot_names.each(&block) end
# File lib/roby/app/rake.rb, line 159 def run_roby(*args) pid = spawn(Gem.ruby, File.expand_path(File.join('..', '..', '..', 'bin', 'roby'), __dir__), *args) begin _, status = Process.waitpid2(pid) status.success? rescue Interrupt Process.kill pid Process.waitpid(pid) end end
# File lib/roby/app/rake.rb, line 152 def run_roby_test(*args) args = args + excludes.flat_map do |pattern| ["--exclude", pattern] end run_roby('test', *args) end
# File lib/roby/app/rake.rb, line 144 def task_name_for_robot(robot_name, robot_type) if robot_name == robot_type "#{task_name}:#{robot_name}" else "#{task_name}:#{robot_name}-#{robot_type}" end end