Bug 1253189 part 1 - Make import-tests.py compatible with Windows. r=dbaron
authorXidorn Quan <quanxunzhen@gmail.com>
Thu, 03 Mar 2016 18:30:35 +0800
changeset 340487 d940d6375fca9df1f3b111a4f7be45c32932f5d2
parent 340486 e782585f98babc97e4cade2f85c9f409a50bcf55
child 340488 a817bf8847db15c09dbd6c27c0fcbd091aac74f0
push id12980
push usertmielczarek@mozilla.com
push dateTue, 15 Mar 2016 13:03:24 +0000
reviewersdbaron
bugs1253189
milestone48.0a1
Bug 1253189 part 1 - Make import-tests.py compatible with Windows. r=dbaron MozReview-Commit-ID: DdnXqUOm2bC
layout/reftests/w3c-css/import-tests.py
--- a/layout/reftests/w3c-css/import-tests.py
+++ b/layout/reftests/w3c-css/import-tests.py
@@ -66,16 +66,19 @@ filemap = {}
 speclinkmap = {}
 propsaddedfor = []
 tests = []
 gOptions = None
 gArgs = None
 gTestfiles = []
 gTestFlags = {}
 
+def to_unix_path_sep(path):
+    return path.replace('\\', '/')
+
 def log_output_of(subprocess):
     global gLog
     subprocess.wait()
     if (subprocess.returncode != 0):
         raise StandardError("error while running subprocess")
     gLog.write(subprocess.stdout.readline().rstrip())
 
 def write_log_header():
@@ -116,17 +119,18 @@ def populate_test_files():
 
     gTestfiles.sort()
 
 def copy_file(test, srcfile, destname, isSupportFile=False):
     global gDestPath, gLog, gSrcPath
     if not srcfile.startswith(gSrcPath):
         raise StandardError("Filename " + srcfile + " does not start with " + gSrcPath)
     logname = srcfile[len(gSrcPath):]
-    gLog.write("Importing " + logname + " to " + destname + "\n")
+    gLog.write("Importing " + to_unix_path_sep(logname) +
+               " to " + to_unix_path_sep(destname) + "\n")
     destfile = os.path.join(gDestPath, destname)
     destdir = os.path.dirname(destfile)
     if not os.path.exists(destdir):
         os.makedirs(destdir)
     if os.path.exists(destfile):
         raise StandardError("file " + destfile + " already exists")
     copy_and_prefix(test, srcfile, destfile, gPrefixedProperties, isSupportFile)
 
@@ -210,18 +214,18 @@ def add_test_items(fn, spec):
     # Add chained references too
     for ref in refs:
         add_test_items(ref, spec=spec)
     for notref in notrefs:
         add_test_items(notref, spec=spec)
 
 def copy_and_prefix(test, aSourceFileName, aDestFileName, aProps, isSupportFile=False):
     global gTestFlags
-    newFile = open(aDestFileName, 'w')
-    unPrefixedFile = open(aSourceFileName)
+    newFile = open(aDestFileName, 'wb')
+    unPrefixedFile = open(aSourceFileName, 'rb')
     testName = aDestFileName[len(gDestPath)+1:]
     ahemFontAdded = False
     for line in unPrefixedFile:
         replacementLine = line
         searchRegex = "\s*<style\s*"
 
         if not isSupportFile and not ahemFontAdded and 'ahem' in gTestFlags[test] and re.search(searchRegex, line):
             # First put our ahem font declation before the first <style>
@@ -303,18 +307,24 @@ def main():
             if defaultPreferences is None:
                 listfile.write("\ndefault-preferences\n\n")
             else:
                 listfile.write("\ndefault-preferences {0}\n\n".format(defaultPreferences))
             lastDefaultPreferences = defaultPreferences
         key = 0
         while not test[key] in gTestFlags.keys() and key < len(test):
             key = key + 1
+        testFlags = gTestFlags[test[key]]
+        # Replace the Windows separators if any. Our internal strings
+        # all use the system separator, however the failure/skip lists
+        # and reftest.list always use '/' so we fix the paths here.
+        test[key] = to_unix_path_sep(test[key])
+        test[key + 1] = to_unix_path_sep(test[key + 1])
         testKey = test[key]
-        if 'ahem' in gTestFlags[testKey]:
+        if 'ahem' in testFlags:
             test = ["HTTP(../../..)"] + test
         if testKey in gFailList:
             test = ["fails"] + test
         listfile.write(" ".join(test) + "\n")
     listfile.close()
 
     gLog.close()