Patchwork check-code: prepend warning prefix only once, but for each warning

login
register
mail settings
Submitter Simon Heimberg
Date Nov. 11, 2013, 10:22 p.m.
Message ID <93e5a876c2ff2095c079.1384208539@lapsi.heimberg.home>
Download mbox | patch
Permalink /patch/2911/
State Accepted
Commit 22154ec6fb8b7bba40f609b43c89cb00957fc322
Headers show

Comments

Simon Heimberg - Nov. 11, 2013, 10:22 p.m.
# HG changeset patch
# User Simon Heimberg <simohe@besonet.ch>
# Date 1383988880 -3600
#      Sat Nov 09 10:21:20 2013 +0100
# Node ID 93e5a876c2ff2095c07944aaf3426b509eb498f5
# Parent  0fa50746de5f2bb3c621f8a7454c93d54cbfe4ec
check-code: prepend warning prefix only once, but for each warning

The code adding the prefix is now run once per pattern. It was run once per
file (after the change 3e1e4a8aec1e).
Demonstrate that it is working now by extending the test. Raise two different
warnings, one of them twice.
Matt Mackall - Nov. 13, 2013, 8:56 p.m.
On Mon, 2013-11-11 at 23:22 +0100, Simon Heimberg wrote:
> # HG changeset patch
> # User Simon Heimberg <simohe@besonet.ch>
> # Date 1383988880 -3600
> #      Sat Nov 09 10:21:20 2013 +0100
> # Node ID 93e5a876c2ff2095c07944aaf3426b509eb498f5
> # Parent  0fa50746de5f2bb3c621f8a7454c93d54cbfe4ec
> check-code: prepend warning prefix only once, but for each warning

Queued for stable, to keep the other set of patches happy.

Patch

diff -r 0fa50746de5f -r 93e5a876c2ff contrib/check-code.py
--- a/contrib/check-code.py	Sat Nov 09 10:21:02 2013 +0100
+++ b/contrib/check-code.py	Sat Nov 09 10:21:20 2013 +0100
@@ -468,6 +468,8 @@ 
             else:
                 p, msg = pat
                 ignore = None
+            if i >= nerrs:
+                msg = "warning: " + msg
 
             pos = 0
             n = 0
@@ -475,8 +477,6 @@ 
                 if prelines is None:
                     prelines = pre.splitlines()
                     postlines = post.splitlines(True)
-                    if i >= nerrs:
-                        msg = "warning: " + msg
 
                 start = m.start()
                 while n < len(postlines):
diff -r 0fa50746de5f -r 93e5a876c2ff tests/test-check-code.t
--- a/tests/test-check-code.t	Sat Nov 09 10:21:02 2013 +0100
+++ b/tests/test-check-code.t	Sat Nov 09 10:21:20 2013 +0100
@@ -185,12 +185,20 @@ 
   $ cat > warning.t <<EOF
   >   $ function warnonly {
   >   > }
+  >   $ diff -N aaa
+  >   $ function onwarn {}
   > EOF
   $ "$check_code" warning.t
   $ "$check_code" --warn warning.t
   warning.t:1:
    >   $ function warnonly {
    warning: don't use 'function', use old style
+  warning.t:3:
+   >   $ diff -N aaa
+   warning: don't use 'diff -N'
+  warning.t:4:
+   >   $ function onwarn {}
+   warning: don't use 'function', use old style
   [1]
   $ cat > raise-format.py <<EOF
   > raise SomeException, message