Class: Roby::Test::EventReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/test/event_reporter.rb

Overview

A event-logging compatible object that is used to

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, enabled: false) ⇒ EventReporter

Returns a new instance of EventReporter.



10
11
12
13
14
15
16
# 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

Instance Attribute Details

#received_eventsObject (readonly)

Returns the value of attribute received_events.



8
9
10
# File 'lib/roby/test/event_reporter.rb', line 8

def received_events
  @received_events
end

Instance Method Details

#clear_filtersObject

Remove all filters



43
44
45
# File 'lib/roby/test/event_reporter.rb', line 43

def clear_filters
    @filters.clear
end

#dump(m, time, *args) ⇒ Object

This is the API used by Roby to actually log events



61
62
63
64
65
66
# 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_timeObject



18
19
20
# File 'lib/roby/test/event_reporter.rb', line 18

def dump_time
    Time.now
end

#dump_timepoint(event, time, *args) ⇒ Object



56
57
58
# File 'lib/roby/test/event_reporter.rb', line 56

def dump_timepoint(event, time, *args)
    dump(event, time, *args)
end

#filter(pattern) ⇒ Object

Show only events matching this pattern

Patterns are OR-ed (i.e. an event is displayed if it matches at least one pattern)



30
31
32
# File 'lib/roby/test/event_reporter.rb', line 30

def filter(pattern)
    @filters << pattern
end

#filter_out(pattern) ⇒ Object

Hide events that match this pattern

Patterns are OR-ed (i.e. an event is displayed if it matches at least one pattern)



38
39
40
# File 'lib/roby/test/event_reporter.rb', line 38

def filter_out(pattern)
    @filters_out << pattern
end

#flush_cycle(m, *args) ⇒ Object



78
79
# File 'lib/roby/test/event_reporter.rb', line 78

def flush_cycle(m, *args)
end

#has_received_event?(expected_m, *expected_args) ⇒ Boolean

Returns:



68
69
70
71
72
73
74
75
76
# 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_sizeObject



22
23
24
# File 'lib/roby/test/event_reporter.rb', line 22

def log_queue_size
    0
end

#matches_filter?(event) ⇒ Boolean

Test if an event matches the filters setup

It returns a match if no filters have been added

Returns:



50
51
52
53
54
# 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