class CrudeMutant::ResultPrinter

Public Class Methods

call(result, stream = $stdout) click to toggle source
# File lib/crude_mutant/result_printer.rb, line 8
def call(result, stream = $stdout)
  term_width = CrudeMutant::TerminalCalculator.new.calculate_length
  clear_string = ' ' * term_width
  stream.print clear_string
  stream.print "\r"

  number_of_line_digits = result.run_results.size > 0 ?
    Math.log10(result.run_results.size).to_i + 1 :
    0

  result.run_results.each do |run_result|
    line = "#{run_result.line_number.to_s.rjust(number_of_line_digits, ' ')}: "

    if run_result.success?
      line += "#{red(run_result.line_contents.slice(0, term_width - line.size))}"
    else
      line += "#{green(run_result.line_contents.slice(0, term_width - line.size))}"
    end

    line += "\n" if !line.include?("\n")
    stream.print "#{line}"
  end

  stream.print "\n"
  stream.print "Finished mutating #{result.file_path} in #{result.total_time.round(2)} seconds. ^^^ Results above ^^^\n"
  stream.print "Performed #{result.run_results.size} line mutations in total.\n"
  stream.print "There are #{red(result.successful_runs_even_with_mutations.size)} #{red('problematic lines')}:\n"

  stream.flush
end

Private Class Methods

colorize(str, color_code) click to toggle source
# File lib/crude_mutant/result_printer.rb, line 49
def colorize(str, color_code)
  "\e[#{color_code}m#{str}\e[0m"
end
green(str) click to toggle source
# File lib/crude_mutant/result_printer.rb, line 45
def green(str)
  colorize(str, 32)
end
red(str) click to toggle source
# File lib/crude_mutant/result_printer.rb, line 41
def red(str)
  colorize(str, 31)
end