Bug 1253189 part 1 - Make import-tests.py compatible with Windows. r=dbaron draft
authorXidorn Quan <quanxunzhen@gmail.com>
Thu, 03 Mar 2016 18:30:35 +0800
changeset 340442 461609bee3f7dfe086629dfbd1f8da42c65ed6d7
parent 340441 d328e155cb1272fa5ce1e6234be654e768522cb1
child 340443 0a0530a881207af87a82ef64cde3f80fa19bbd13
push id12962
push userxquan@mozilla.com
push dateTue, 15 Mar 2016 08:22:36 +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()