kohljonathan
3/21/2005 5:06:00 PM
Joel VanderWerf wrote:
> Kirk Haines wrote:
> > Jonathan Kohl wrote:
> >
> >
> >>I've written a quick test that checks an input file for an
application.
> >>I have a "known good" baseline file, and I want to check the new
file
> >>against this. I attempted to serialize each conf file into objects
to
> >>do string compares. If the strings are not equal, then we need to
check
> >>the file for changes. If they are equal, the input file hasn't
changed.
> >
> >
> > This sounds like a job for YAML.
> >
> > -----
> > require 'yaml'
> >
> > a = {1,2,3,4,5,6}
> > b = {1,2,3,4,5,6}
> > aa = a.to_yaml
> > bb = b.to_yaml
> > puts "match" if aa == bb
> > -----
>
> I've had problems with both Marshal and YAML when comparing loaded
> objects. YAML, for instance, does some funny things with floats.
(Sorry,
> don't have specifics at hand.)
>
> To be safe, it is best to add an extra cycle:
>
> orig = MyObject.new...
>
> copy_for_test = Marshal.load(Marshal.dump(orig))
>
> copy_from_disk = Marshal.load(string_or_file)
>
> if copy_for_test == copy_from_disk ...
I'm finding that on one machine (Ruby v 1.8.0-10), the string
comparison works perfectly after I marshal the XML file contents for
both the baseline and new test files. On another machine, (Ruby v
1.8.1-11), it doesn't work if there are changes in the first two tags
of the test file, but catches differencs anywhere else in the file. A
diff says there is a difference between the files, but the string
compare doesn't see a difference, so I get a false positive for a test
result. In the binary files of each XML file after they are marshalled,
character 71 of 923 total is a null byte. I'm wondering if when I read
it in, IO sees this as the end of the file. The data that is different
in 1.8.0 might be falling ahead of the null byte, and in 1.8.1 might be
past it, so the string compare doesn't catch it. Does this sound
familiar to anyone? I'm going to test this out further on my own as
well and get more information.
I'm wondering if REXML has changed, or if the IO.read or string
compares have changed from 1.8.0 to 1.8.1?