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.
-
#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
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/roby/app/rake.rb', line 202 def initialize(task_name) super() @task_name = task_name @app = Roby.app @config = {} @test_files = [] @excludes = [] @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 |
#force_discovery=(value) ⇒ Object (writeonly)
Sets whether the tests should be started with the –force-discovery flag
171 172 173 |
# File 'lib/roby/app/rake.rb', line 171 def force_discovery=(value) @force_discovery = value end |
#report_dir ⇒ Object
Path to the JUnit/Rubocop reports (if enabled)
226 227 228 |
# File 'lib/roby/app/rake.rb', line 226 def report_dir @report_dir end |
#self_only=(value) ⇒ Object (writeonly)
Only run tests that are present in this bundle
174 175 176 |
# File 'lib/roby/app/rake.rb', line 174 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
168 169 170 |
# File 'lib/roby/app/rake.rb', line 168 def ui=(value) @ui = value end |
Instance Method Details
#coverage? ⇒ Boolean
Whether the tests should be started with the –self flag
192 193 194 |
# File 'lib/roby/app/rake.rb', line 192 def coverage? @coverage end |
#force_discovery? ⇒ Boolean
Whether the tests should be started with the –force-discovery flag
182 183 184 |
# File 'lib/roby/app/rake.rb', line 182 def force_discovery? @force_discovery end |
#keep_logs? ⇒ Boolean
Whether the tests should save the normal syskit logs as part of the test results
198 199 200 |
# File 'lib/roby/app/rake.rb', line 198 def keep_logs? @keep_logs end |
#read_captured_output_from_pipe(pid, read_pipe) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/roby/app/rake.rb', line 256 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
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/roby/app/rake.rb', line 339 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
294 295 296 297 298 299 300 301 302 303 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 |
# File 'lib/roby/app/rake.rb', line 294 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? 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
187 188 189 |
# File 'lib/roby/app/rake.rb', line 187 def self_only? @self_only end |
#spawn_process(bin, *args, env: {}) ⇒ Object
283 284 285 286 287 288 289 290 291 292 |
# File 'lib/roby/app/rake.rb', line 283 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
249 250 251 252 253 254 |
# File 'lib/roby/app/rake.rb', line 249 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
177 178 179 |
# File 'lib/roby/app/rake.rb', line 177 def ui? @ui end |
#use_junit? ⇒ Boolean
Whether the tests should generate a JUnit report in #report_dir
221 222 223 |
# File 'lib/roby/app/rake.rb', line 221 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
269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/roby/app/rake.rb', line 269 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
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/roby/app/rake.rb', line 228 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 |