[Git][ghc/ghc][master] 3 commits: Remove duplicate code normalising slashes

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Tue Mar 12 23:26:25 UTC 2024



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
b85a4631 by Brandon Chinn at 2024-03-12T19:25:56-04:00
Remove duplicate code normalising slashes

- - - - -
c91946f9 by Brandon Chinn at 2024-03-12T19:25:56-04:00
Simplify regexes with raw strings

- - - - -
1a5f53c6 by Brandon Chinn at 2024-03-12T19:25:57-04:00
Don't normalize backslashes in characters

- - - - -


7 changed files:

- testsuite/driver/testlib.py
- testsuite/tests/parser/should_fail/T21843a.stderr
- testsuite/tests/parser/should_fail/T21843b.stderr
- testsuite/tests/parser/should_fail/T21843c.stderr
- testsuite/tests/parser/should_fail/T21843d.stderr
- testsuite/tests/parser/should_fail/T21843e.stderr
- testsuite/tests/parser/should_fail/T21843f.stderr


Changes:

=====================================
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))
@@ -2598,8 +2598,9 @@ def normalise_errmsg(s: str) -> str:
     s = normalise_callstacks(s)
     s = normalise_type_reps(s)
 
-    # normalise slashes, minimise Windows/Unix filename differences
-    s = re.sub('\\\\', '/', s)
+    # normalise slashes to minimise Windows/Unix filename differences,
+    # but don't normalize backslashes in chars
+    s = re.sub(r"(?!')\\", '/', s)
 
     # Normalize the name of the GHC executable. Specifically,
     # this catches the cases that:
@@ -2614,14 +2615,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)
-
-    # normalise slashes, minimise Windows/Unix filename differences
-    s = re.sub('\\\\', '/', s)
+    s = re.sub(r'([^\s])\.jsexe', r'\1', s)
 
     # hpc executable is given ghc suffix
     s = re.sub('hpc-ghc', 'hpc', s)
@@ -2631,8 +2629,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)
@@ -2735,8 +2733,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:
@@ -2754,9 +2752,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
@@ -2776,7 +2774,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
 


=====================================
testsuite/tests/parser/should_fail/T21843a.stderr
=====================================
@@ -1,4 +1,4 @@
 
 T21843a.hs:3:13: [GHC-31623]
-    Unicode character '“' ('/8220') looks like '"' (Quotation Mark), but it is not
+    Unicode character '“' ('\8220') looks like '"' (Quotation Mark), but it is not
 


=====================================
testsuite/tests/parser/should_fail/T21843b.stderr
=====================================
@@ -1,3 +1,3 @@
 
 T21843b.hs:3:11: [GHC-31623]
-    Unicode character '‘' ('/8216') looks like ''' (Single Quote), but it is not
+    Unicode character '‘' ('\8216') looks like ''' (Single Quote), but it is not


=====================================
testsuite/tests/parser/should_fail/T21843c.stderr
=====================================
@@ -1,6 +1,6 @@
 
 T21843c.hs:3:19: [GHC-31623]
-    Unicode character '”' ('/8221') looks like '"' (Quotation Mark), but it is not
+    Unicode character '”' ('\8221') looks like '"' (Quotation Mark), but it is not
 
 T21843c.hs:3:20: [GHC-21231]
-    lexical error in string/character literal at character '/n'
+    lexical error in string/character literal at character '\n'


=====================================
testsuite/tests/parser/should_fail/T21843d.stderr
=====================================
@@ -1,3 +1,3 @@
 
 T21843d.hs:3:13: [GHC-31623]
-    Unicode character '’' ('/8217') looks like ''' (Single Quote), but it is not
+    Unicode character '’' ('\8217') looks like ''' (Single Quote), but it is not


=====================================
testsuite/tests/parser/should_fail/T21843e.stderr
=====================================
@@ -1,3 +1,3 @@
 
 T21843e.hs:3:15: [GHC-31623]
-    Unicode character '”' ('/8221') looks like '"' (Quotation Mark), but it is not
+    Unicode character '”' ('\8221') looks like '"' (Quotation Mark), but it is not


=====================================
testsuite/tests/parser/should_fail/T21843f.stderr
=====================================
@@ -1,3 +1,3 @@
 
 T21843f.hs:3:13: [GHC-31623]
-    Unicode character '‘' ('/8216') looks like ''' (Single Quote), but it is not
+    Unicode character '‘' ('\8216') looks like ''' (Single Quote), but it is not



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0590764c73841115fc567757e370d5c9dc7e6478...1a5f53c6d4f3812835b8b72f36d9d23004b38f1f

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0590764c73841115fc567757e370d5c9dc7e6478...1a5f53c6d4f3812835b8b72f36d9d23004b38f1f
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/20240312/85363106/attachment-0001.html>


More information about the ghc-commits mailing list