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, log_timepoints: false) ⇒ EventReporter

Returns a new instance of EventReporter.



12
13
14
15
16
17
18
19
# File 'lib/roby/test/event_reporter.rb', line 12

def initialize(io, enabled: false, log_timepoints: false)
    @io = io
    @enabled = enabled
    @filters = []
    @filters_out = []
    @received_events = []
    @log_timepoints = log_timepoints
end

Instance Attribute Details

#received_eventsObject (readonly)

Returns the value of attribute received_events.



10
11
12
# File 'lib/roby/test/event_reporter.rb', line 10

def received_events
  @received_events
end

Instance Method Details

#clear_filtersObject

Remove all filters



50
51
52
# File 'lib/roby/test/event_reporter.rb', line 50

def clear_filters
    @filters.clear
end

#dump(m, time, args) ⇒ Object

This is the API used by Roby to actually log events



72
73
74
75
76
77
# File 'lib/roby/test/event_reporter.rb', line 72

def dump(m, time, args)
    received_events << [m, time, args]
    return unless enabled? && matches_filter?(m)

    @io.puts "#{time.to_hms} #{m}(#{args.map(&:to_s).join(', ')})"
end

#dump_timeObject



25
26
27
# File 'lib/roby/test/event_reporter.rb', line 25

def dump_time
    Time.now
end

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



67
68
69
# File 'lib/roby/test/event_reporter.rb', line 67

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)



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

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)



45
46
47
# File 'lib/roby/test/event_reporter.rb', line 45

def filter_out(pattern)
    @filters_out << pattern
end

#flush_cycle(m, *args) ⇒ Object



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

def flush_cycle(m, *args); end

#has_received_event?(expected_m, *expected_args) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
85
86
87
# File 'lib/roby/test/event_reporter.rb', line 79

def has_received_event?(expected_m, *expected_args)
    received_events.any? do |m, _, 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



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

def log_queue_size
    0
end

#log_timepoints?Boolean

Returns:

  • (Boolean)


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

def log_timepoints?
    @log_timepoints
end

#matches_filter?(event) ⇒ Boolean

Test if an event matches the filters setup

It returns a match if no filters have been added

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
# File 'lib/roby/test/event_reporter.rb', line 57

def matches_filter?(event)
    included = @filters.empty? ||
               @filters.any? { |pattern| pattern === event.to_s }
    return unless included

    excluded = !@filters_out.empty? &&
               @filters_out.none? { |pattern| pattern === event.to_s }
    !excluded
end