# File lib/unit_diff.rb, line 62
  def parse_input(input, output)
    current = []
    data = []
    data << current
    print_lines = true

    term = "\nFinished".split(//).map { |c| c[0] }
    term_length = term.size

    old_sync = output.sync
    output.sync = true
    while line = input.gets
      case line
      when /^(Loaded suite|Started|# Running tests:)/ then
        print_lines = true
        output.puts line
        chars = []
        while c = input.getc do
          output.putc c
          chars << c
          tail = chars[-term_length..-1]
          break if chars.size >= term_length and tail == term
        end
        output.puts input.gets # the rest of "Finished in..."
        output.puts
        next
      when /^\s*$/, /^\(?\s*\d+\) (Failure|Error):/, /^\d+\)/ then
        print_lines = false
        current = []
        data << current
      when /^Finished in \d/ then
        print_lines = false
      end
      output.puts line if print_lines
      current << line
    end
    output.sync = old_sync
    data = data.reject { |o| o == ["\n"] or o.empty? }
    footer = data.pop

    data.map do |result|
      break if result.any? { |l| l =~ / expected( but was|, not)/ }

      header = result.find do |l|
        l =~ /^\(?\s*\d+\) (Failure|Error):/
      end

      break unless header

      message_index = result.index(header) + 2

      result[message_index..-1] = result[message_index..-1].join
    end

    return data, footer
  end