<commit_before>require 'cucumber'
require 'rcov'

module Cucover
  module Formatter
    class Lazy < Cucumber::Ast::Visitor

      def initialize(step_mother, io, options)
        super(step_mother)
        @io = io
        @options = options
        @analyzer = Rcov::CodeCoverageAnalyzer.new
      end

      def visit_features(features)
        @features = features
        super
        @io.puts
        print_counts(features)
      end

      def visit_feature(feature)
        @analyzer.run_hooked do
          super
        end
        @io.puts feature.file
        analyzed_files.each do |f|
          @io.puts "  #{f}"
        end
      end
      
      private 
      
      def analyzed_files
        interesting_files = @analyzer.analyzed_files.map{ |f| File.expand_path(f) }.reject{ |f| boring?(f) }
        interesting_files.map do |file|
          file.gsub(/^#{Dir.pwd}\//, '')
        end
      end
      
      def boring?(file)
        file.match /gem/
      end
      
      def print_counts(features)
        @io.puts dump_count(features.scenarios.length, "scenario")

        [:failed, :skipped, :undefined, :pending, :passed].each do |status|
          if features.steps[status].any?
            count_string = dump_count(features.steps[status].length, "step", status.to_s)
            @io.puts count_string
            @io.flush
          end
        end
      end
      
      def dump_count(count, what, state=nil)
        [count, state, "#{what}#{count == 1 ? '' : 's'}"].compact.join(" ")
      end
      

    end
  end
end
<commit_msg>Working on better output for dogfooding<commit_after>require 'cucumber'
require 'rcov'

module Cucover
  
  module FeaturesExtensions
    def run_logs
      @features.map{ |f| f.last_run }
    end    
  end
  
  module FeatureExtensions
    attr_accessor :last_run
    attr_accessor :analyzed_files
  end
  
  module LooksLikeTerminal
    def tty?
      true
    end
  end
  
  module Formatter
    
    class CoverageReporter
      def initialize(io)
        @io = io
      end
      
      def visit_features(features)
        @io.puts
        @io.puts
        @io.puts "Coverage"
        @io.puts "--------"
        @io.puts
        features.accept(self)
        @io.puts
      end
      
      def visit_feature(feature)
        @io.puts feature.file
        feature.analyzed_files.each do |f|
          @io.puts "  #{f}"
        end
      end
    end
    
    class Lazy < Cucumber::Ast::Visitor

      def initialize(step_mother, io, options)
        super(step_mother)
        @io = io
        @options = options
        @analyzer = Rcov::CodeCoverageAnalyzer.new
        @pretty_io = StringIO.new.extend(LooksLikeTerminal)
        @pretty_formatter = Cucumber::Formatter::Pretty.new(step_mother, @pretty_io, @options)
      end

      def visit_features(features)
        features.extend(FeaturesExtensions)
        super
        
        CoverageReporter.new(@io).visit_features(features)

        print_counts(features)
        @io.puts
      end

      def visit_feature(feature)
        feature.extend(FeatureExtensions)
        @analyzer.run_hooked do
          super
        end
        feature.analyzed_files = analyzed_files
        
        @pretty_formatter.visit_feature(feature)
        feature.last_run = @pretty_io.string
        @pretty_io.string == ""
        @io.puts feature.last_run
        @io.puts
        
      end
      
      private 
      
      def analyzed_files
        interesting_files = @analyzer.analyzed_files.map{ |f| File.expand_path(f) }.reject{ |f| boring?(f) }
        interesting_files.map do |file|
          file.gsub(/^#{Dir.pwd}\//, '')
        end
      end
      
      def boring?(file)
        file.match /gem/
      end
      
      def print_counts(features)
        @io.puts dump_count(features.scenarios.length, "scenario")

        [:failed, :skipped, :undefined, :pending, :passed].each do |status|
          if features.steps[status].any?
            count_string = dump_count(features.steps[status].length, "step", status.to_s)
            @io.puts count_string
            @io.flush
          end
        end
      end
      
      def dump_count(count, what, state=nil)
        [count, state, "#{what}#{count == 1 ? '' : 's'}"].compact.join(" ")
      end

    end
  end
end

{'fraction_non_alphanumeric': 0.10239145576967727, 'fraction_numerical': 0.0004643603436266543, 'mean_word_length': 1.8286277084701248, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3686593', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1348, 'n_words': 274}