From c91946f994ad8b734b09cf3023f1fc9671a7475a Mon Sep 17 00:00:00 2001
From: Brandon Chinn <brandonchinn178@gmail.com>
Date: Fri, 16 Feb 2024 17:19:18 -0800
Subject: [PATCH] Simplify regexes with raw strings

---
 testsuite/driver/testlib.py | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/testsuite/driver/testlib.py b/testsuite/driver/testlib.py
index 98e84e1e545f..79d2b15eecc7 100644
--- a/testsuite/driver/testlib.py
+++ b/testsuite/driver/testlib.py
@@ -1119,8 +1119,8 @@ def normalise_win32_io_errors(name, opts):
 def normalise_version_( *pkgs ):
     def normalise_version__( str ):
         # (name)(-version)(-hash)(-components)
-        return re.sub('(' + '|'.join(map(re.escape,pkgs)) + ')-[0-9.]+(-[0-9a-zA-Z\+]+)?(-[0-9a-zA-Z]+)?',
-                      '\\1-<VERSION>-<HASH>', str)
+        return re.sub('(' + '|'.join(map(re.escape,pkgs)) + r')-[0-9.]+(-[0-9a-zA-Z+]+)?(-[0-9a-zA-Z]+)?',
+                      r'\1-<VERSION>-<HASH>', str)
     return normalise_version__
 
 def normalise_version( *pkgs ):
@@ -1491,7 +1491,7 @@ async def do_test(name: TestName,
     if opts.expect not in ['pass', 'fail', 'missing-lib']:
         framework_fail(name, way, 'bad expected ' + opts.expect)
 
-    directory = re.sub('^\\.[/\\\\]', '', str(opts.testdir))
+    directory = re.sub(r'^\.[/\\]', '', str(opts.testdir))
 
     if way in opts.fragile_ways:
         if_verbose(1, '*** fragile test %s resulted in %s' % (full_name, 'pass' if result.passed else 'fail'))
@@ -1538,7 +1538,7 @@ def override_options(pre_cmd):
 
 def framework_fail(name: Optional[TestName], way: Optional[WayName], reason: str) -> None:
     opts = getTestOpts()
-    directory = re.sub('^\\.[/\\\\]', '', str(opts.testdir))
+    directory = re.sub(r'^\.[/\\]', '', str(opts.testdir))
     full_name = '%s(%s)' % (name, way)
     if_verbose(1, '*** framework failure for %s %s ' % (full_name, reason))
     name2 = name if name is not None else TestName('none')
@@ -1549,7 +1549,7 @@ def framework_fail(name: Optional[TestName], way: Optional[WayName], reason: str
 
 def framework_warn(name: TestName, way: WayName, reason: str) -> None:
     opts = getTestOpts()
-    directory = re.sub('^\\.[/\\\\]', '', str(opts.testdir))
+    directory = re.sub(r'^\.[/\\]', '', str(opts.testdir))
     full_name = name + '(' + way + ')'
     if_verbose(1, '*** framework warning for %s %s ' % (full_name, reason))
     t.framework_warnings.append(TestResult(directory, name, reason, way))
@@ -2599,7 +2599,7 @@ def normalise_errmsg(s: str) -> str:
     s = normalise_type_reps(s)
 
     # normalise slashes, minimise Windows/Unix filename differences
-    s = re.sub('\\\\', '/', s)
+    s = re.sub(r'\\', '/', s)
 
     # Normalize the name of the GHC executable. Specifically,
     # this catches the cases that:
@@ -2614,11 +2614,11 @@ def normalise_errmsg(s: str) -> str:
     #    the colon is there because it appears in error messages; this
     #    hacky solution is used in place of more sophisticated filename
     #    mangling
-    s = re.sub('([^\\s])\\.exe', '\\1', s)
+    s = re.sub(r'([^\s])\.exe', r'\1', s)
     # Same thing for .wasm modules generated by the Wasm backend
-    s = re.sub('([^\\s])\\.wasm', '\\1', s)
+    s = re.sub(r'([^\s])\.wasm', r'\1', s)
     # Same thing for .jsexe directories generated by the JS backend
-    s = re.sub('([^\\s])\\.jsexe', '\\1', s)
+    s = re.sub(r'([^\s])\.jsexe', r'\1', s)
 
     # hpc executable is given ghc suffix
     s = re.sub('hpc-ghc', 'hpc', s)
@@ -2628,8 +2628,8 @@ def normalise_errmsg(s: str) -> str:
     s = re.sub('ghc-stage[123]', 'ghc', s)
     # Remove platform prefix (e.g. javascript-unknown-ghcjs) for cross-compiled tools
     # (ghc, ghc-pkg, unlit, etc.)
-    s = re.sub('\\w+(-\\w+)*-ghc', 'ghc', s)
-    s = re.sub('\\w+(-\\w+)*-unlit', 'unlit', s)
+    s = re.sub(r'\w+(-\w+)*-ghc', 'ghc', s)
+    s = re.sub(r'\w+(-\w+)*-unlit', 'unlit', s)
 
     # On windows error messages can mention versioned executables
     s = re.sub('ghc-[0-9.]+', 'ghc', s)
@@ -2732,8 +2732,8 @@ def normalise_prof (s: str) -> str:
     return s
 
 def normalise_slashes_( s: str ) -> str:
-    s = re.sub('\\\\', '/', s)
-    s = re.sub('//', '/', s)
+    s = re.sub(r'\\', '/', s)
+    s = re.sub(r'//', '/', s)
     return s
 
 def normalise_exe_( s: str ) -> str:
@@ -2751,9 +2751,9 @@ def normalise_output( s: str ) -> str:
     # and .wasm extension (for the Wasm backend)
     # and .jsexe extension (for the JS backend)
     # This can occur in error messages generated by the program.
-    s = re.sub('([^\\s])\\.exe', '\\1', s)
-    s = re.sub('([^\\s])\\.wasm', '\\1', s)
-    s = re.sub('([^\\s])\\.jsexe', '\\1', s)
+    s = re.sub(r'([^\s])\.exe', r'\1', s)
+    s = re.sub(r'([^\s])\.wasm', r'\1', s)
+    s = re.sub(r'([^\s])\.jsexe', r'\1', s)
     s = normalise_callstacks(s)
     s = normalise_type_reps(s)
     # ghci outputs are pretty unstable with -fexternal-dynamic-refs, which is
@@ -2773,7 +2773,7 @@ def normalise_output( s: str ) -> str:
     s = re.sub('.*warning: argument unused during compilation:.*\n', '', s)
 
     # strip the cross prefix if any
-    s = re.sub('\\w+(-\\w+)*-ghc', 'ghc', s)
+    s = re.sub(r'\w+(-\w+)*-ghc', 'ghc', s)
 
     return s
 
-- 
GitLab