Mercurial > hg
changeset 10727:62b8f15683f2
check-code: more tests and more robust python filtering
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Thu, 18 Mar 2010 16:32:03 +0100 |
parents | bedef1c228d3 |
children | 71cf11f03b3d |
files | contrib/check-code.py tests/test-check-code tests/test-check-code.out |
diffstat | 3 files changed, 14 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/check-code.py Thu Mar 18 01:59:53 2010 +0100 +++ b/contrib/check-code.py Thu Mar 18 16:32:03 2010 +0100 @@ -14,6 +14,12 @@ t = re.sub(r"[^\sx]", "o", t) return m.group('quote') + t + m.group('quote') +def reppython(m): + comment = m.group('comment') + if comment: + return "#" * len(comment) + return repquote(m) + def repcomment(m): return m.group(1) + "#" * len(m.group(2)) @@ -96,10 +102,10 @@ ] pyfilters = [ - (r"""(?msx)(?P<quote>('''|\"\"\"|(?<!')'(?!')|(?<!")"(?!"))) - (?P<text>(.*?)) - (?<!\\)(?P=quote)""", repquote), - (r"( *)(#([^\n]*\S)?)", repcomment), + (r"""(?msx)(?P<comment>\#.*?$)| + ((?P<quote>('''|\"\"\"|(?<!')'(?!')|(?<!")"(?!"))) + (?P<text>(([^\\]|\\.)*?)) + (?P=quote))""", reppython), ] cpats = [
--- a/tests/test-check-code Thu Mar 18 01:59:53 2010 +0100 +++ b/tests/test-check-code Thu Mar 18 16:32:03 2010 +0100 @@ -13,11 +13,13 @@ EOF cat > quote.py <<EOF +# let's use quote in comments (''' ( 4x5 ) -but """\''' and finally''', +but """\\''' and finally''', """let's fool checkpatch""", '1+2', '"""', 42+1, """and ( 4-1 ) """, "( 1+1 )\" and ") +a, '\\\\\\\\', "\\\\\\" x-2", "c-1" EOF check_code=`dirname $0`/../contrib/check-code.py
--- a/tests/test-check-code.out Thu Mar 18 01:59:53 2010 +0100 +++ b/tests/test-check-code.out Thu Mar 18 16:32:03 2010 +0100 @@ -8,6 +8,6 @@ > return ( 5+6, 9) missing whitespace in expression gratuitous whitespace in () or [] -./quote.py:4: +./quote.py:5: > '"""', 42+1, """and missing whitespace in expression