class Roby::Test::EventReporter
A event-logging compatible object that is used to
Attributes
received_events[R]
Public Class Methods
new(io, enabled: false)
click to toggle source
# File lib/roby/test/event_reporter.rb, line 10 def initialize(io, enabled: false) @io = io @enabled = enabled @filters = Array.new @filters_out = Array.new @received_events = Array.new end
Public Instance Methods
clear_filters()
click to toggle source
Remove all filters
# File lib/roby/test/event_reporter.rb, line 43 def clear_filters @filters.clear end
dump(m, time, *args)
click to toggle source
This is the API used by Roby
to actually log events
# File lib/roby/test/event_reporter.rb, line 61 def dump(m, time, *args) received_events << [m, time, *args] if enabled? && matches_filter?(m) @io.puts "#{time.to_hms} #{m}(#{args.map(&:to_s).join(", ")})" end end
dump_time()
click to toggle source
# File lib/roby/test/event_reporter.rb, line 18 def dump_time Time.now end
dump_timepoint(event, time, *args)
click to toggle source
# File lib/roby/test/event_reporter.rb, line 56 def dump_timepoint(event, time, *args) dump(event, time, *args) end
filter(pattern)
click to toggle source
Show only events matching this pattern
Patterns are OR-ed (i.e. an event is displayed if it matches at least one pattern)
# File lib/roby/test/event_reporter.rb, line 30 def filter(pattern) @filters << pattern end
filter_out(pattern)
click to toggle source
Hide events that match this pattern
Patterns are OR-ed (i.e. an event is displayed if it matches at least one pattern)
# File lib/roby/test/event_reporter.rb, line 38 def filter_out(pattern) @filters_out << pattern end
flush_cycle(m, *args)
click to toggle source
# File lib/roby/test/event_reporter.rb, line 78 def flush_cycle(m, *args) end
has_received_event?(expected_m, *expected_args)
click to toggle source
# File lib/roby/test/event_reporter.rb, line 68 def has_received_event?(expected_m, *expected_args) received_events.any? do |m, time, args| if args.size == expected_args.size [m, *args].zip([expected_m, *expected_args]).all? do |v, expected| expected === v end end end end
log_queue_size()
click to toggle source
# File lib/roby/test/event_reporter.rb, line 22 def log_queue_size 0 end
matches_filter?(event)
click to toggle source
Test
if an event matches the filters setup
It returns a match if no filters have been added
# File lib/roby/test/event_reporter.rb, line 50 def matches_filter?(event) if @filters.empty? || @filters.any? { |pattern| pattern === event.to_s } @filters_out.empty? || @filters_out.none? { |pattern| pattern === event.to_s } end end