Sha256: 9b6baf041b0772ac568a521c1c646295db749d49197632dd089d6f28226e0041

Contents?: true

Size: 1.91 KB

Versions: 4

Compression:

Stored size: 1.91 KB

Contents

require 'colored'
module ATP
  module Formatters
    # Outputs the given AST to something resembling an ATE datalog,
    # this can optionally be rendered to a file or the console (the default).
    class Datalog < Formatter
      def on_flow(node)
        str = 'Number'.ljust(15)
        str += 'Result'.ljust(9)
        str += 'Name'.ljust(55)
        str += 'Test'.ljust(55)
        str += 'ID'
        puts str
        process_all(node.children)
      end

      def on_test(node)
        str = "#{node.find(:number).try(:value)}".ljust(15)
        if node.find(:failed)
          str += 'FAIL'.ljust(9).red
        else
          str += 'PASS'.ljust(9)
        end
        str += "#{node.find(:name).value}".ljust(55)
        str += "#{node.find(:object).value}".ljust(55)
        str += "#{node.find(:id).value}"
        puts str
      end

      def on_render(node)
        puts '************ Directly rendered flow snippet ************'
        puts node.value
        puts '********************************************************'
      end

      def on_log(node)
        puts "// #{node.value}"
      end

      def on_set_result(node)
        bin = node.find(:bin).try(:value)
        sbin = node.find(:softbin).try(:value)
        desc = node.find(:description).try(:value)

        if node.to_a[0] == 'pass'
          str = "               PASS     #{bin}      #{sbin}"
          color = :green
        else
          str = "               FAIL     #{bin}      #{sbin}"
          color = :red
        end
        str += "      (#{desc})" if desc

        puts '---------------------------------------------------------------------------------------------------------------------------------------------------------'
        puts str.send(color)
        puts '---------------------------------------------------------------------------------------------------------------------------------------------------------'
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
atp-0.3.3 lib/atp/formatters/datalog.rb
atp-0.3.2 lib/atp/formatters/datalog.rb
atp-0.3.1 lib/atp/formatters/datalog.rb
atp-0.3.0 lib/atp/formatters/datalog.rb