Class: Roby::App::Rake::BaseTestTask
- Defined in:
- lib/roby/app/rake.rb
Overview
Common API for TestTask and RobotTestTask
TestTask is the historical helper for roby tests. It is trying to run all tests in a single shot. RobotTestTask is a single-robot implementation, which gives more flexibility and simplifies the code
This base class is meant to factor out the common parts
Direct Known Subclasses
Instance Attribute Summary collapse
-
#app ⇒ Object
The app.
-
#base_dir ⇒ String
The directory where the tests will be auto-discovered.
-
#config ⇒ Hash<String, String>
The hash with extra configuration to be inserted into Conf for the tests we are running.
-
#excludes ⇒ Array<String>
Patterns matching excluded test files.
-
#extra_robot_names ⇒ Array<String>
List of robot names that should be included in the test discovery.
-
#force_discovery ⇒ Object
writeonly
Sets whether the tests should be started with the --force-discovery flag.
-
#report_dir ⇒ Object
Path to the JUnit/Rubocop reports (if enabled).
-
#self_only ⇒ Object
writeonly
Only run tests that are present in this bundle.
-
#task_name ⇒ Object
readonly
The base test task name.
-
#test_files ⇒ Array<String>
The list of files that should be tested.
-
#ui ⇒ Object
writeonly
Sets whether the tests should be started with the --ui flag.
Instance Method Summary collapse
-
#coverage? ⇒ Boolean
Whether the tests should be started with the --self flag.
-
#force_discovery? ⇒ Boolean
Whether the tests should be started with the --force-discovery flag.
-
#initialize(task_name) ⇒ BaseTestTask
constructor
A new instance of BaseTestTask.
-
#keep_logs? ⇒ Boolean
Whether the tests should save the normal syskit logs as part of the test results.
- #read_captured_output_from_pipe(pid, read_pipe) ⇒ Object
- #run_roby(*args, synchronize_output: false, omit_success: false, report_name: "report", env: {}) ⇒ Object
- #run_roby_test(*args, report_name: "report", coverage_name: "roby", synchronize_output: false, omit_success: false) ⇒ Object
-
#self_only? ⇒ Boolean
Whether the tests should be started with the --self flag.
- #spawn_process(bin, *args, env: {}) ⇒ Object
- #spawn_process_capturing_output(bin, *args, env: {}) ⇒ Object
-
#ui? ⇒ Boolean
Whether the tests should be started with the --ui flag.
-
#use_junit? ⇒ Boolean
Whether the tests should generate a JUnit report in #report_dir.
-
#wait_process_with_captured_output(pid, read_pipe, args, synchronize_output:, omit_success:, report_name: "report") ⇒ Object
rubocop:disable Metrics/ParameterLists.
-
#write_captured_output(success, output, synchronize_output, omit_success, args, report_name: "report") ⇒ Object
rubocop:disable Metrics/ParameterLists.
Constructor Details
#initialize(task_name) ⇒ BaseTestTask
Returns a new instance of BaseTestTask.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/roby/app/rake.rb', line 211 def initialize(task_name) super() @task_name = task_name @app = Roby.app @config = {} @test_files = [] @excludes = [] @extra_robot_names = [] @ui = false @force_discovery = false @self_only = false @coverage = Rake.coverage? @use_junit = Rake.use_junit? @keep_logs = Rake.keep_logs? @report_dir = Rake.report_dir end |
Instance Attribute Details
#app ⇒ Object
The app
It defaults to Roby.app
142 143 144 |
# File 'lib/roby/app/rake.rb', line 142 def app @app end |
#base_dir ⇒ String
The directory where the tests will be auto-discovered
158 159 160 |
# File 'lib/roby/app/rake.rb', line 158 def base_dir @base_dir end |
#config ⇒ Hash<String, String>
The hash with extra configuration to be inserted into Conf for the tests we are running
148 149 150 |
# File 'lib/roby/app/rake.rb', line 148 def config @config end |
#excludes ⇒ Array<String>
Patterns matching excluded test files
It accepts any string that File.fnmatch? accepts
165 166 167 |
# File 'lib/roby/app/rake.rb', line 165 def excludes @excludes end |
#extra_robot_names ⇒ Array<String>
List of robot names that should be included in the test discovery
Roby test normally excludes any folder whose name is the name of a declared robot, if that robot is not the currently configured one. This flag allows to force the inclusion of such a name
174 175 176 |
# File 'lib/roby/app/rake.rb', line 174 def extra_robot_names @extra_robot_names end |
#force_discovery=(value) ⇒ Object (writeonly)
Sets whether the tests should be started with the --force-discovery flag
180 181 182 |
# File 'lib/roby/app/rake.rb', line 180 def force_discovery=(value) @force_discovery = value end |
#report_dir ⇒ Object
Path to the JUnit/Rubocop reports (if enabled)
236 237 238 |
# File 'lib/roby/app/rake.rb', line 236 def report_dir @report_dir end |
#self_only=(value) ⇒ Object (writeonly)
Only run tests that are present in this bundle
183 184 185 |
# File 'lib/roby/app/rake.rb', line 183 def self_only=(value) @self_only = value end |
#task_name ⇒ Object (readonly)
The base test task name
137 138 139 |
# File 'lib/roby/app/rake.rb', line 137 def task_name @task_name end |
#test_files ⇒ Array<String>
The list of files that should be tested.
153 154 155 |
# File 'lib/roby/app/rake.rb', line 153 def test_files @test_files end |
#ui=(value) ⇒ Object (writeonly)
Sets whether the tests should be started with the --ui flag
177 178 179 |
# File 'lib/roby/app/rake.rb', line 177 def ui=(value) @ui = value end |
Instance Method Details
#coverage? ⇒ Boolean
Whether the tests should be started with the --self flag
201 202 203 |
# File 'lib/roby/app/rake.rb', line 201 def coverage? @coverage end |
#force_discovery? ⇒ Boolean
Whether the tests should be started with the --force-discovery flag
191 192 193 |
# File 'lib/roby/app/rake.rb', line 191 def force_discovery? @force_discovery end |
#keep_logs? ⇒ Boolean
Whether the tests should save the normal syskit logs as part of the test results
207 208 209 |
# File 'lib/roby/app/rake.rb', line 207 def keep_logs? @keep_logs end |
#read_captured_output_from_pipe(pid, read_pipe) ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/roby/app/rake.rb', line 266 def read_captured_output_from_pipe(pid, read_pipe) output = [] begin while (output_fragment = read_pipe.read(512)) output << output_fragment end output.join "" rescue Interrupt Process.kill "INT", pid Process.waitpid pid end end |
#run_roby(*args, synchronize_output: false, omit_success: false, report_name: "report", env: {}) ⇒ Object
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/roby/app/rake.rb', line 352 def run_roby( *args, synchronize_output: false, omit_success: false, report_name: "report", env: {} ) roby_bin = File.( File.join("..", "..", "..", "bin", "roby"), __dir__ ) capture_output = synchronize_output || omit_success if capture_output pid, read_pipe = spawn_process_capturing_output( roby_bin, *args, env: env ) wait_process_with_captured_output( pid, read_pipe, args, synchronize_output: synchronize_output, omit_success: omit_success, report_name: report_name ) else puts "Running #{report_name}: roby #{args.join(' ')}" spawn_process(roby_bin, *args, env: env) end end |
#run_roby_test(*args, report_name: "report", coverage_name: "roby", synchronize_output: false, omit_success: false) ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/roby/app/rake.rb', line 304 def run_roby_test( *args, report_name: "report", coverage_name: "roby", synchronize_output: false, omit_success: false ) args += excludes.flat_map do |pattern| ["--exclude", pattern] end args += config.flat_map do |k, v| ["--set", "#{k}=#{v}"] end args += ["--base-dir", base_dir] if base_dir args << "--ui" if ui? args << "--force-discovery" if force_discovery? args << "--self" if self_only? args << "--coverage=#{coverage_name}" if coverage? unless extra_robot_names.empty? args << "--extra-robot-names=#{extra_robot_names.join(',')}" end env = {} if keep_logs? args << "--keep-logs" env["ROBY_BASE_LOG_DIR"] = report_dir FileUtils.mkdir_p report_dir end args << "--" if (minitest_opts = ENV["TESTOPTS"]) args.concat(Shellwords.split(minitest_opts)) end if use_junit? args += [ "--junit", "--junit-jenkins", "--junit-filename=#{report_dir}/#{report_name}.junit.xml" ] FileUtils.mkdir_p report_dir end args += test_files.map(&:to_s) run_roby("test", *args, synchronize_output: synchronize_output, omit_success: omit_success, report_name: report_name, env: env) end |
#self_only? ⇒ Boolean
Whether the tests should be started with the --self flag
196 197 198 |
# File 'lib/roby/app/rake.rb', line 196 def self_only? @self_only end |
#spawn_process(bin, *args, env: {}) ⇒ Object
293 294 295 296 297 298 299 300 301 302 |
# File 'lib/roby/app/rake.rb', line 293 def spawn_process(bin, *args, env: {}) pid = spawn(env, Gem.ruby, bin, *args) begin _, status = Process.waitpid2(pid) status.success? rescue Interrupt Process.kill "INT", pid Process.waitpid pid end end |
#spawn_process_capturing_output(bin, *args, env: {}) ⇒ Object
259 260 261 262 263 264 |
# File 'lib/roby/app/rake.rb', line 259 def spawn_process_capturing_output(bin, *args, env: {}) stdout_r, stdout_w = IO.pipe pid = spawn(env, Gem.ruby, bin, *args, out: stdout_w, err: stdout_w) stdout_w.close [pid, stdout_r] end |
#ui? ⇒ Boolean
Whether the tests should be started with the --ui flag
186 187 188 |
# File 'lib/roby/app/rake.rb', line 186 def ui? @ui end |
#use_junit? ⇒ Boolean
Whether the tests should generate a JUnit report in #report_dir
231 232 233 |
# File 'lib/roby/app/rake.rb', line 231 def use_junit? @use_junit end |
#wait_process_with_captured_output(pid, read_pipe, args, synchronize_output:, omit_success:, report_name: "report") ⇒ Object
rubocop:disable Metrics/ParameterLists
279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/roby/app/rake.rb', line 279 def wait_process_with_captured_output( # rubocop:disable Metrics/ParameterLists pid, read_pipe, args, synchronize_output:, omit_success:, report_name: "report" ) output = read_captured_output_from_pipe(pid, read_pipe) _, status = Process.waitpid2(pid) success = status.success? write_captured_output( success, output, synchronize_output, omit_success, args, report_name: report_name ) success end |
#write_captured_output(success, output, synchronize_output, omit_success, args, report_name: "report") ⇒ Object
rubocop:disable Metrics/ParameterLists
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/roby/app/rake.rb', line 238 def write_captured_output( # rubocop:disable Metrics/ParameterLists success, output, synchronize_output, omit_success, args, report_name: "report" ) if synchronize_output Rake.report_sync_mutex.synchronize do write_captured_output( success, output, false, omit_success, args, report_name: report_name ) end else puts "Running #{report_name}: roby #{args.join(' ')}" if omit_success && success puts "#{report_name} tests succeeded." else puts output end end end |