[PATCH 1 of 1] check-code: automatically preppend "warning: " to all warning messages

Simon Heimberg simohe at besonet.ch
Tue Jul 16 15:53:29 CDT 2013


# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1373930954 -7200
# Node ID 1d526fa8e0455fbfe1da5726d01671e06f186f80
# Parent  2f2a1caf1e123a5a3764d0454b909a965459fc41
check-code: automatically preppend "warning: " to all warning messages

Some warnings had "warning: " at the beginning of their message. Now this
is done consistent for all messages.
Especially in test-check-code-hg.t it is an advantage to see warnings at once
because only exceptions to them are tolerated. It is (almost) as obvious as
before a6180647ea.

The prefix will not remain when a warning is changed to a failure. A change
like a91387a37f will not be necessary anymore.

diff -r 2f2a1caf1e12 -r 1d526fa8e045 contrib/check-code.py
--- a/contrib/check-code.py	Mon Jul 15 23:50:57 2013 +0200
+++ b/contrib/check-code.py	Die Jul 16 01:29:14 2013 +0200
@@ -137,7 +137,7 @@
   # warnings
   [
     (r'^  [^*?/\n]* \(glob\)$',
-     "warning: glob match with no glob character (?*/)"),
+     "glob match with no glob character (?*/)"),
   ]
 ]
 
@@ -421,6 +421,7 @@
             break
         for p, r in filters:
             post = re.sub(p, r, post)
+        nerrs = len(pats[0]) # nerr elements are errors
         if warnings:
             pats = pats[0] + pats[1]
         else:
@@ -432,7 +433,7 @@
 
         prelines = None
         errors = []
-        for pat in pats:
+        for i, pat in enumerate(pats):
             if len(pat) == 3:
                 p, msg, ignore = pat
             else:
@@ -471,6 +472,8 @@
                         bl, bu, br = blamecache[n]
                         if bl == l:
                             bd = '%s@%s' % (bu, br)
+                if i >= nerrs:
+                    msg = "warning: " + msg
                 errors.append((f, lineno and n + 1, l, msg, bd))
                 result = False
 
diff -r 2f2a1caf1e12 -r 1d526fa8e045 tests/test-check-code.t
--- a/tests/test-check-code.t	Mon Jul 15 23:50:57 2013 +0200
+++ b/tests/test-check-code.t	Die Jul 16 01:29:14 2013 +0200
@@ -184,3 +184,13 @@
    don't use old-style two-argument raise, use Exception(message)
   [1]
 
+  $ cat > warning.t <<EOF
+  >   $ function warnonly {
+  >   > }
+  > EOF
+  $ "$check_code" warning.t
+  $ "$check_code" --warn warning.t
+  warning.t:1:
+   >   $ function warnonly {
+   warning: don't use 'function', use old style
+  [1]


More information about the Mercurial-devel mailing list