Patchwork [5,of,6,v2] run_tests: know how to match Windows //?/C:\Something paths

login
register
mail settings
Submitter Kostia Balytskyi
Date Sept. 19, 2017, 4:57 p.m.
Message ID <29007a29700f107b7fd5.1505840269@devvm1416.lla2.facebook.com>
Download mbox | patch
Permalink /patch/24028/
State Deferred, archived
Headers show

Comments

Kostia Balytskyi - Sept. 19, 2017, 4:57 p.m.
# HG changeset patch
# User Kostia Balytskyi <ikostia@fb.com>
# Date 1505837708 25200
#      Tue Sep 19 09:15:08 2017 -0700
# Node ID 29007a29700f107b7fd5bf139fa192f9528d6349
# Parent  59578c527e95704396e044444e77435cbab6a966
run_tests: know how to match Windows //?/C:\Something paths

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -964,7 +964,19 @@  class Test(unittest.TestCase):
 
     def _escapepath(self, p):
         if os.name == 'nt':
+            # Explanation of the clowntown below:
+            # We want to match NT prefix \\?\ (see MSDN on Windows File Names).
+            # In order to match a signle \ in re, we need to escape it with
+            # another \, thus re has to receive \\ for each \ we want to match.
+            # Also, to match ?, re has to receive \?. But since we're
+            # concatenating strings, we can't use r'', so we have to also
+            # python-string-escape everything. Therefore:
+            # Want to match  |  re must receive  |  python str must contain
+            #       /        |         //        |         ////
+            #       ?        |         /?        |         //?
+            #     //?/       |      /////?//     |    //////////?////
             return (
+                b'(\\\\\\\\\\?\\\\){0,1}' +
                 (b''.join(c.isalpha() and b'[%s%s]' % (c.lower(), c.upper()) or
                     c in b'/\\' and br'[/\\]' or c.isdigit() and c or b'\\' + c
                     for c in p))