Patchwork check-config: mention the file and line of the error

login
register
mail settings
Submitter Ryan McElroy
Date July 18, 2017, 1:28 p.m.
Message ID <461c59c5d100b983cdd2.1500384484@devbig314.prn1.facebook.com>
Download mbox | patch
Permalink /patch/22489/
State Accepted
Headers show

Comments

Ryan McElroy - July 18, 2017, 1:28 p.m.
# HG changeset patch
# User Ryan McElroy <rmcelroy@fb.com>
# Date 1500384456 25200
#      Tue Jul 18 06:27:36 2017 -0700
# Node ID 461c59c5d100b983cdd2eed5222cd23d0370a8f5
# Parent  9c4e2aa0a2392947850dcddeb32e8801e07b7787
check-config: mention the file and line of the error

I used this to more quickly track down a failing test-check-config.t issue
in another repo. I thought it might be useful more generally, so I'm sending
it out in case others think it's a worthwhile change.

Patch

diff --git a/contrib/check-config.py b/contrib/check-config.py
--- a/contrib/check-config.py
+++ b/contrib/check-config.py
@@ -48,7 +48,9 @@  def main(args):
         prevname = ''
         confsect = ''
         carryover = ''
+        linenum = 0
         for l in open(f):
+            linenum += 1
 
             # check topic-like bits
             m = re.match('\s*``(\S+)``', l)
@@ -110,9 +112,10 @@  def main(args):
                     default = '<variable>'
                 if (name in foundopts and (ctype, default) != foundopts[name]
                     and name not in allowinconsistent):
-                    print(l)
+                    print(l.rstrip())
                     print("conflict on %s: %r != %r" % (name, (ctype, default),
                                                         foundopts[name]))
+                    print("at %s:%d:" % (f, linenum))
                 foundopts[name] = (ctype, default)
                 carryover = ''
             else:
diff --git a/tests/test-check-config.t b/tests/test-check-config.t
--- a/tests/test-check-config.t
+++ b/tests/test-check-config.t
@@ -32,8 +32,8 @@  Sanity check check-config.py
 
   $ $PYTHON contrib/check-config.py < $TESTTMP/files
   foo = ui.configint('ui', 'intdefault', default=42)
-  
   conflict on ui.intdefault: ('int', '42') != ('int', '1')
+  at $TESTTMP/testfile.py:12: (glob)
   undocumented: ui.doesnotexist (str)
   undocumented: ui.intdefault (int) [42]
   undocumented: ui.intdefault2 (int) [42]