From: Jonathan Kohl Date: 2005-03-19T07:14:52+09:00 Subject: Advice on ASCII representation of objects for testing using string compares? 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. I'm using marshal to serialize each file, but I'm finding that my test case has some false positives and false negatives using this method. If I marshal the base line file in one script and store the string in a file for later use, then with another script read in the configuration file from the new build and do a comparison, I never get a comparison of the two strings to be equal. If I do all of the above in one script: -read in base-line file, marshal to a base-line file -read in new conf file, marshal to a temp file -read in both as strings, do a comparison (string1 == string2) It works most of the time, but sometimes it doesn't work when there is a change, or when the files are equal. The same thing happens with checksum. Any ideas on what might be going on? I'm wondering if with marshal there are differences in the serialization operation which result in slightly different strings in some cases. Is there a better way of reading in these XML conf files and making a simple ASCII representation for accurate string compares for a fast failure kind of test? Are there library functions that would do this reliably? This is what the code looks like, I could very well be doing something wrong here: require 'rexml/document' #serialize baseline file xml = REXML::Document.new(File.open("xml/demo.xml")) File.open("baseline/xml_baseline", "w") do | file | Marshal.dump(xml, file) end #serialize test file xml2 = REXML::Document.new(File.open("xml/test_demo.xml")) File.open("temp", "w") do | file | Marshal.dump(xml2, file) end line1 = IO.read("baseline/xml_baseline") puts "line1.id.to_s" + line1.id.to_s #line1 = file1.readline puts "xml_baseline is: #{line1.size} characters." puts "xml_baseline is: #{line1.sum.to_s} checksum." #file1.close line2 = IO.read("temp") #line2 = file2.readline puts "test_demo is: #{line2.size} characters." puts "test_demo is: #{line2.sum.to_s} checksum." #file2.close puts "line2.id.to_s" + line2.id.to_s #string compare section if line1 == line2 puts "EQUAL!" else puts "NOT EQUAL! test_demo: " + line2 + "\n" puts "xml_baseline: " + line1 + "\n" end #end of sting compare section Thanks; -Jonathan