def diff
@diff ||= begin
@paths = case options[:source]
when 'strings'
[tempfile(string1), tempfile(string2)]
when 'files'
[string1, string2]
end
if WINDOWS
cmd = sprintf '"%s" %s %s', diff_bin, diff_options.join(' '), @paths.map { |s| %("#{s}") }.join(' ')
diff = `#{cmd}`
else
diff = Open3.popen3(diff_bin, *(diff_options + @paths)) { |i, o, e| o.read }
end
diff.force_encoding('ASCII-8BIT') if diff.respond_to?(:valid_encoding?) && !diff.valid_encoding?
if diff =~ /\A\s*\Z/ && !options[:allow_empty_diff]
diff = case options[:source]
when 'strings' then string1
when 'files' then File.read(string1)
end.gsub(/^/, " ")
end
diff
end
ensure
if defined? @tempfiles
Array(@tempfiles).each do |t|
begin
t.unlink if t.path && File.exist?(t.path)
rescue => e
warn "#{e.class}: #{e}"
warn e.backtrace.join("\n")
end
end
end
end