From b203d6438d1be438c576d16571c004bb800c7cc6 Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Fri, 4 Nov 2016 14:57:13 +0000 Subject: [PATCH] prism-auto: Use line ending agnostic file compare The previously used filecmp.cmp opens the files to be compared in 'rb' mode, i.e., it will tell us that two files that differ only in the line-ending encoding (CRLF vs LF) are not equivalent. However, we'd like to get the export tests to succeed on Windows, regardless of the line endings. So, we provide our own file comparison method that opens the file in 'rU' mode (universal newline mode), which converts all the newline encodings to '\n' transparently. git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@11880 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/etc/scripts/prism-auto | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/prism/etc/scripts/prism-auto b/prism/etc/scripts/prism-auto index a119c48d..3e032de4 100755 --- a/prism/etc/scripts/prism-auto +++ b/prism/etc/scripts/prism-auto @@ -11,7 +11,7 @@ # Run "prism-auto -h" for details of further options. -import os,sys,re,subprocess,signal,tempfile,functools,filecmp,logging,time,platform +import os,sys,re,subprocess,signal,tempfile,functools,logging,time,platform from pipes import quote from optparse import OptionParser @@ -24,6 +24,22 @@ def isWindows(): s = platform.system() return s == 'Windows' or re.match('CYGWIN', s) != None +# compare two files (with filenames f1,f2) for equality +def compareFiles(f1,f2): + # We open the files in 'rU' mode (universal newline mode), + # which automatically converts all the different newline + # encodings to '\n'. + # This allow the two files to differ in their + # line ending encodings without affecting equality + with open(f1, 'rU') as fp1, open(f2, 'rU') as fp2: + while True: + s1 = fp1.readline() + s2 = fp2.readline() + if s1 != s2: # mismatch + return False + if s1 == '': # EOF (in both files) + return True + # returns a sorted list of files / directories in dir def sortedListDir(dir): list = os.listdir(dir); @@ -429,7 +445,7 @@ def verifyAndCleanupExports(outFiles, exportPrefix): if options.noExportTests: msg = msg + "SKIPPED" os.remove(expFile) - elif filecmp.cmp(outFile, expFile): + elif compareFiles(outFile, expFile): # If successful, notify and delete exported file msg = msg + "PASS" os.remove(expFile)