Class: Roby::App::Rake::TestTask
- 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:
Defined Under Namespace
Classes: Failed
Instance Attribute Summary collapse
-
#app ⇒ Object
The app.
-
#excludes ⇒ Array<String>
Patterns matching excluded test files.
-
#robot_names ⇒ Array<String,(String,String)>
The list of robot configurations on which we should run the tests.
-
#task_name ⇒ Object
readonly
The base test task name.
Instance Method Summary collapse
- #define ⇒ Object
-
#discover_robot_names ⇒ Object
private
Discover which robots are available on the current app.
-
#each_robot(&block) ⇒ Object
Enumerate the robots on which tests should be run.
-
#initialize(task_name = 'test', all_by_default: false) {|_self| ... } ⇒ TestTask
constructor
A new instance of TestTask.
- #run_roby(*args) ⇒ Object
- #run_roby_test(*args) ⇒ Object
- #task_name_for_robot(robot_name, robot_type) ⇒ Object
Constructor Details
#initialize(task_name = 'test', all_by_default: false) {|_self| ... } ⇒ TestTask
Returns a new instance of TestTask.
86 87 88 89 90 91 92 93 94 |
# 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 |
Instance Attribute Details
#app ⇒ Object
The app
It defaults to Roby.app
65 66 67 |
# File 'lib/roby/app/rake.rb', line 65 def app @app end |
#excludes ⇒ Array<String>
Patterns matching excluded test files
It accepts any string that File.fnmatch? accepts
80 81 82 |
# File 'lib/roby/app/rake.rb', line 80 def excludes @excludes end |
#robot_names ⇒ Array<String,(String,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/
73 74 75 |
# File 'lib/roby/app/rake.rb', line 73 def robot_names @robot_names end |
#task_name ⇒ Object (readonly)
The base test task name
60 61 62 |
# File 'lib/roby/app/rake.rb', line 60 def task_name @task_name end |
Instance Method Details
#define ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# 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 |
#discover_robot_names ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Discover which robots are available on the current app
179 180 181 182 183 184 185 |
# 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 |
#each_robot(&block) ⇒ Object
Enumerate the robots on which tests should be run
172 173 174 |
# File 'lib/roby/app/rake.rb', line 172 def each_robot(&block) robot_names.each(&block) end |
#run_roby(*args) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/roby/app/rake.rb', line 159 def run_roby(*args) pid = spawn(Gem.ruby, File.(File.join('..', '..', '..', 'bin', 'roby'), __dir__), *args) begin _, status = Process.waitpid2(pid) status.success? rescue Interrupt Process.kill pid Process.waitpid(pid) end end |
#run_roby_test(*args) ⇒ Object
152 153 154 155 156 157 |
# 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 |
#task_name_for_robot(robot_name, robot_type) ⇒ Object
144 145 146 147 148 149 150 |
# 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 |