Class: Roby::App::AutotestConsoleReporter
- Defined in:
- lib/roby/app/autotest_console_reporter.rb
Overview
Reporter class for the Roby autotest, that outputs on an IO object
Instance Attribute Summary collapse
-
#io ⇒ #puts
readonly
The IO on which reporting should be done.
-
#manager ⇒ Autorespawn::Manager
readonly
The autorespawn slave manager.
-
#pid_to_slave ⇒ Hash<Integer,Autorespawn::Slave>
readonly
Mapping from a process ID to the slave object.
-
#server ⇒ App::TestServer
readonly
The test server.
-
#slave_to_id ⇒ Hash<Autorespawn::Slave,Integer>
readonly
Mapping from a slave to the unique ID associated with it.
Instance Method Summary collapse
-
#deregister_slave_pid(pid) ⇒ (Autorespawn::Slave,Integer)
private
Deregisters a slave-to-PID mapping.
-
#initialize(server, manager, io: STDOUT) ⇒ AutotestConsoleReporter
constructor
A new instance of AutotestConsoleReporter.
-
#register_slave(slave) ⇒ Integer
private
Register a new slave.
-
#register_slave_pid(slave) ⇒ Integer
private
Register a new slave-to-PID mapping.
-
#slave_from_pid(pid) ⇒ (Autorespawn::Slave,Integer)
private
Returns a slave from its PID.
-
#slave_to_s(slave) ⇒ Object
private
Converts a slave object to the string displayed to the user.
Constructor Details
#initialize(server, manager, io: STDOUT) ⇒ AutotestConsoleReporter
Returns a new instance of AutotestConsoleReporter.
93 94 95 96 97 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 |
# File 'lib/roby/app/autotest_console_reporter.rb', line 93 def initialize(server, manager, io: STDOUT) @io = io @slave_id = 0 @slave_to_id = {} @pid_to_slave = {} manager.on_slave_new do |slave| slave_id = register_slave(slave) io.puts "[##{slave_id}] new slave #{slave_to_s(slave)}" end manager.on_slave_start do |slave| slave_id = register_slave_pid(slave) io.puts "[##{slave_id}] slave #{slave_to_s(slave)} started (PID=#{slave.pid})" end manager.on_slave_finished do |slave| slave, slave_id = deregister_slave_pid(slave.pid) io.puts "[##{slave_id}] slave #{slave_to_s(slave)} finished (PID=#{slave.pid})" end server.on_exception do |pid, exception| slave, slave_id = slave_from_pid(pid) io.puts "[##{slave_id}] #{slave_to_s(slave)} reports exception" Roby.display_exception(io, exception) end server.on_discovery_start do |pid| slave, slave_id = slave_from_pid(pid) io.puts "[##{slave_id}] #{slave_to_s(slave)} started discovery" end server.on_discovery_finished do |pid| slave, slave_id = slave_from_pid(pid) io.puts "[##{slave_id}] #{slave_to_s(slave)} finished discovery" end server.on_test_start do |pid| slave, slave_id = slave_from_pid(pid) io.puts "[##{slave_id}] #{slave_to_s(slave)} started testing" end server.on_test_result do |pid, file, test_case_name, test_name, failures, assertions, time| slave, slave_id = slave_from_pid(pid) io.puts "[##{slave_id}] #{test_case_name}##{test_name}: #{failures.size} failures and #{assertions.size} assertions (#{time})" failures.each do |e| Roby.display_exception(io, e) end end server.on_test_finished do |pid| slave, slave_id = slave_from_pid(pid) io.puts "[##{slave_id}] #{slave_to_s(slave)} finished testing" end end |
Instance Attribute Details
#io ⇒ #puts (readonly)
Returns the IO on which reporting should be done.
8 9 10 |
# File 'lib/roby/app/autotest_console_reporter.rb', line 8 def io @io end |
#manager ⇒ Autorespawn::Manager (readonly)
Returns the autorespawn slave manager.
14 15 16 |
# File 'lib/roby/app/autotest_console_reporter.rb', line 14 def manager @manager end |
#pid_to_slave ⇒ Hash<Integer,Autorespawn::Slave> (readonly)
Returns mapping from a process ID to the slave object.
22 23 24 |
# File 'lib/roby/app/autotest_console_reporter.rb', line 22 def pid_to_slave @pid_to_slave end |
#server ⇒ App::TestServer (readonly)
Returns the test server.
11 12 13 |
# File 'lib/roby/app/autotest_console_reporter.rb', line 11 def server @server end |
#slave_to_id ⇒ Hash<Autorespawn::Slave,Integer> (readonly)
Returns mapping from a slave to the unique ID associated with it.
18 19 20 |
# File 'lib/roby/app/autotest_console_reporter.rb', line 18 def slave_to_id @slave_to_id end |
Instance Method Details
#deregister_slave_pid(pid) ⇒ (Autorespawn::Slave,Integer)
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.
Deregisters a slave-to-PID mapping
85 86 87 88 89 90 91 |
# File 'lib/roby/app/autotest_console_reporter.rb', line 85 def deregister_slave_pid(pid) if slave = pid_to_slave.delete(pid) [slave, slave_to_id[slave]] else raise ArgumentError, "no slave known for #{pid}" end end |
#register_slave(slave) ⇒ Integer
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.
Register a new slave
36 37 38 39 40 41 42 |
# File 'lib/roby/app/autotest_console_reporter.rb', line 36 def register_slave(slave) if slave_to_id[slave] raise ArgumentError, "#{slave} is already registered" end slave_to_id[slave] = (@slave_id += 1) end |
#register_slave_pid(slave) ⇒ Integer
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.
Register a new slave-to-PID mapping
52 53 54 55 56 57 58 59 |
# File 'lib/roby/app/autotest_console_reporter.rb', line 52 def register_slave_pid(slave) if slave_id = slave_to_id[slave] pid_to_slave[slave.pid] = slave slave_id else raise ArgumentError, "#{slave} has not been registered with #register_slave" end end |
#slave_from_pid(pid) ⇒ (Autorespawn::Slave,Integer)
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.
Returns a slave from its PID
69 70 71 72 73 74 75 |
# File 'lib/roby/app/autotest_console_reporter.rb', line 69 def slave_from_pid(pid) if slave = pid_to_slave[pid] [slave, slave_to_id[slave]] else raise ArgumentError, "no slave registered for PID #{pid}" end end |
#slave_to_s(slave) ⇒ 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.
Converts a slave object to the string displayed to the user
27 28 29 |
# File 'lib/roby/app/autotest_console_reporter.rb', line 27 def slave_to_s(slave) slave.name.sort_by(&:first).map { |k, v| "#{k}: #{v}" } end |