Sha256: f6e84cf460aa84eb856daa73fa8fccb32d842bdffd0ddf1a2e3d03b4962bbe94

Contents?: true

Size: 1.67 KB

Versions: 41

Compression:

Stored size: 1.67 KB

Contents

module OrigenTesters::ATP
  module Validators
    class Flags < Validator
      def setup
        @open_if_nodes = []
        @open_unless_nodes = []
        @conflicting = []
      end

      def on_completion
        failed = false
        unless @conflicting.empty?
          error 'if_flag and unless_flag conditions cannot be nested and refer to the same flag unless it is declared as volatile'
          error "The following conflicts were found in flow #{flow.name}:"
          @conflicting.each do |a, b|
            a_condition = a.to_a[1] ? 'if_job:    ' : 'unless_job:'
            b_condition = b.to_a[1] ? 'if_job:    ' : 'unless_job:'
            error "  #{a.type}(#{a.to_a[0]}) #{a.source}"
            error "  #{b.type}(#{b.to_a[0]}) #{b.source}"
            error ''
          end
          failed = true
        end
        failed
      end

      def on_flow(node)
        extract_volatiles(node)
        process_all(node.children)
      end

      def on_if_flag(node)
        if volatile?(node.to_a[0])
          process_all(node.children)
        else
          if n = @open_unless_nodes.find { |n| n.to_a[0] == node.to_a[0] }
            @conflicting << [n, node]
          end
          @open_if_nodes << node
          process_all(node.children)
          @open_if_nodes.pop
        end
      end

      def on_unless_flag(node)
        if volatile?(node.to_a[0])
          process_all(node.children)
        else
          if n = @open_if_nodes.find { |n| n.to_a[0] == node.to_a[0] }
            @conflicting << [n, node]
          end
          @open_unless_nodes << node
          process_all(node.children)
          @open_unless_nodes.pop
        end
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
origen_testers-0.52.9 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.52.8 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.52.7 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.52.6 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.52.5 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.52.4 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.52.3 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.52.1 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.52.0 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.51.5 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.51.4 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.51.3 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.51.2 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.51.1 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.51.0 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.50.0 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.49.4 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.49.3 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.49.2 lib/origen_testers/atp/validators/flags.rb
origen_testers-0.49.1 lib/origen_testers/atp/validators/flags.rb