[Git][ghc/ghc][ghc-9.8] 2 commits: Simplify regexes with raw strings

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Sun Oct 20 12:23:38 UTC 2024



Ben Gamari pushed to branch ghc-9.8 at Glasgow Haskell Compiler / GHC


Commits:
f41b0bda by Brandon Chinn at 2024-10-19T08:13:42-04:00
Simplify regexes with raw strings

(cherry picked from commit c91946f994ad8b734b09cf3023f1fc9671a7475a)

- - - - -
72e04175 by Ben Gamari at 2024-10-19T08:41:21-04:00
testsuite: More aggressive version number normalization

Component names can sometimes have hashes.

- - - - -


1 changed file:

- testsuite/driver/testlib.py


Changes:

=====================================
testsuite/driver/testlib.py
=====================================
@@ -1019,8 +1019,12 @@ 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)
+        pkg_names = '(' + '|'.join(map(re.escape,pkgs)) + ')'
+        version = r'[0-9\.]+'
+        pkg_hash = r'(-[0-9a-zA-Z\+]+)'
+        component = r'(-[0-9a-zA-Z]+(\+[0-9a-zA-Z]+)?)'
+        return re.sub(f'{pkg_names}-{version}{pkg_hash}?{component}?',
+                      r'\1-<VERSION>-<HASH>', str)
     return normalise_version__
 
 def normalise_version( *pkgs ):
@@ -1393,7 +1397,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'))
@@ -1440,7 +1444,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')
@@ -1451,7 +1455,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))
@@ -2476,7 +2480,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:
@@ -2491,11 +2495,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)
 
     # normalise slashes, minimise Windows/Unix filename differences
     s = re.sub('\\\\', '/', s)
@@ -2508,8 +2512,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)
@@ -2610,8 +2614,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:
@@ -2629,9 +2633,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
@@ -2651,7 +2655,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
 



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/24e765b4be020c6c3c9641d7c9a2d3da347d45a6...72e041753f8d2c5b1fae0465277b187c61f17634

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/24e765b4be020c6c3c9641d7c9a2d3da347d45a6...72e041753f8d2c5b1fae0465277b187c61f17634
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241020/46fc9b77/attachment-0001.html>


More information about the ghc-commits mailing list