# File lib/unit_diff.rb, line 151
  def unit_diff(input=ARGF, output=$stdout)
    $b = false unless defined? $b
    $c = false unless defined? $c
    $k = false unless defined? $k
    $l = false unless defined? $l
    $u = false unless defined? $u

    data, footer = self.parse_input(input, output)

    output = []

    # Output
    data.each do |result|
      first = []
      second = []

      if result.first !~ /Failure/ then
        output.push result.join('')
        next
      end

      prefix, expect, butwas = parse_diff(result)

      output.push prefix.compact.map {|line| line.strip}.join("\n")

      if butwas then
        Tempfile.open("expect") do |a|
          a.write(massage(expect))
          a.rewind
          Tempfile.open("butwas") do |b|
            b.write(massage(butwas))
            b.rewind

            diff_flags = $u ? "-u" : $c ? "-c" : ""
            diff_flags += " -b" if $b

            result = `#{DIFF} #{diff_flags} #{a.path} #{b.path}`
            if result.empty? then
              output.push "[no difference--suspect ==]"
            else
              output.push result.map { |line| line.chomp }
            end

            if $k then
              warn "moving #{a.path} to #{a.path}.keep"
              File.rename a.path, a.path + ".keep"
              warn "moving #{b.path} to #{b.path}.keep"
              File.rename b.path, b.path + ".keep"
            end
          end
        end

        output.push ''
      else
        output.push expect.join('')
      end
    end

    if footer then
      footer.shift if footer.first.strip.empty?# unless footer.first.nil?
      output.push footer.compact.map {|line| line.strip}.join("\n")
    end

    return output.flatten.join("\n")
  end