<commit_before>require "testjour/progressbar"
require "testjour/colorer"
require "testjour/result_set"

module Testjour
  class ResultsFormatter
    
    def initialize(step_counter)
      @progress_bar = ProgressBar.new("0 failures", step_counter.count)
      @result_set   = ResultSet.new(step_counter)
    end
  
    def missing_backtrace_lines
      @result_set.missing_backtrace_lines
    end
    
    def result(result)
      @result_set.record(result)
      log_result(result)
      update_progress_bar
    end
    
    def update_progress_bar
      @progress_bar.colorer = colorer
      @progress_bar.title   = title
      @progress_bar.inc
      STDOUT.flush
    end
    
    def log_result(result)
      return unless result.char == "F"
      
      erase_current_line
      print Testjour::Colorer.failed("#{@result_set.errors.size}) ")
      puts Testjour::Colorer.failed(result.message)
      puts result.backtrace
      puts
    end

    def colorer
      if failed?
        Testjour::Colorer.method(:failed).to_proc
      else
        Testjour::Colorer.method(:passed).to_proc
      end<commit_msg>print out the server id when failures<commit_after>require "testjour/progressbar"
require "testjour/colorer"
require "testjour/result_set"

module Testjour
  class ResultsFormatter
    
    def initialize(step_counter)
      @progress_bar = ProgressBar.new("0 failures", step_counter.count)
      @result_set   = ResultSet.new(step_counter)
    end
  
    def missing_backtrace_lines
      @result_set.missing_backtrace_lines
    end
    
    def result(result)
      @result_set.record(result)
      log_result(result)
      update_progress_bar
    end
    
    def update_progress_bar
      @progress_bar.colorer = colorer
      @progress_bar.title   = title
      @progress_bar.inc
      STDOUT.flush
    end
    
    def log_result(result)
      return unless result.char == "F"
      
      erase_current_line
      print Testjour::Colorer.failed("#{@result_set.errors.size}) ")
      puts Testjour::Colorer.failed(result.message)
      puts result.backtrace
      puts "from: " + result.server_id
      puts
    end

    def colorer
      if failed?
        Testjour::Colorer.method(:failed).to_proc
      else
        Testjour::Colorer.method(:passed).to_proc
      end
{'fraction_non_alphanumeric': 0.08082131935342944, 'fraction_numerical': 0.0008737439930100481, 'mean_word_length': 2.687600644122383, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6625446', 'n_tokens_mistral': 706, 'n_tokens_neox': 706, 'n_words': 130}