Sha256: fade03f0bfd4fadd979832890f466a264e6fc05094ea5a85e003b1125cb3d759

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

module ATP
  module Validators
    class MissingIDs < Validator
      def setup
        @referenced_ids = {}
        @present_ids ||= {}.with_indifferent_access
        @referenced_early = {}.with_indifferent_access
      end

      def on_completion
        failed = false
        @referenced_ids.each do |id, nodes|
          unless @present_ids[id]
            Origen.log.error "Test ID #{id} is referenced in flow #{flow.name} in the following lines, but it is never defined:"
            nodes.each do |node|
              Origen.log.error "  #{node.source}"
            end
            failed = true
            @referenced_early.delete(id)
          end
        end
        @referenced_early.each do |id, nodes|
          Origen.log.error "Test ID #{id} is referenced in flow #{flow.name} in the following line(s):"
          nodes.each do |node|
            Origen.log.error "  #{node.source}"
          end
          Origen.log.error 'but it was not defined until later:'
          Origen.log.error "  #{@present_ids[id].first.source}"
          failed = true
        end
        failed
      end

      def on_id(node)
        id = node.value
        @present_ids[id] ||= []
        @present_ids[id] << node
      end

      def on_test_executed(node)
        ids = node.to_a[0]
        [ids].flatten.each do |id|
          @referenced_ids[id] ||= []
          @referenced_ids[id] << node
          unless @present_ids[id]
            @referenced_early[id] ||= []
            @referenced_early[id] << node
          end
        end
        process_all(node)
      end
      alias_method :on_test_result, :on_test_executed
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
atp-0.3.1 lib/atp/validators/missing_ids.rb
atp-0.3.0 lib/atp/validators/missing_ids.rb
atp-0.2.1 lib/atp/validators/missing_ids.rb