output copy of BSON on error

This commit is contained in:
Jim Menard 2009-01-12 11:11:58 -05:00
parent 991dfb29e1
commit b6b819fe89
2 changed files with 7 additions and 6 deletions

View File

@ -245,7 +245,7 @@ class BSON
bytes = buf.get(len)
str = ''
bytes.each { |c| str << c.chr }
str
str.to_mongo_binary
end
def serialize_eoo_element(buf)

View File

@ -74,16 +74,14 @@ class RoundTripTest < Test::Unit::TestCase
# from the file.
bson_from_ruby = BSON.new.serialize(obj).to_a
# # DEBUG
# File.open(File.join(dir, "#{name}_out.bson"), 'wb') { |f|
# bson_from_ruby.each { |b| f.putc(b) }
# }
begin
assert_equal bson.length, bson_from_ruby.length
assert_equal bson, bson_from_ruby
rescue => ex
$stderr.puts "failure while round-tripping (A) #{dir}/#{name}" # DEBUG
File.open(File.join(dir, "#{name}_out_a.bson"), 'wb') { |f| # DEBUG
bson_from_ruby.each { |b| f.putc(b) }
}
raise ex
end
@ -103,6 +101,9 @@ class RoundTripTest < Test::Unit::TestCase
assert_equal bson, bson_from_ruby
rescue => ex
$stderr.puts "failure while round-tripping (B) #{dir}/#{name}" # DEBUG
File.open(File.join(dir, "#{name}_out_b.bson"), 'wb') { |f| # DEBUG
bson_from_ruby.each { |b| f.putc(b) }
}
raise ex
end
}