tests/test-check-code.t
author Sean Farley <sean.michael.farley@gmail.com>
Fri, 02 Aug 2013 16:46:23 -0500
changeset 19540 7b864da00e21
parent 19501 725507cd5216
child 19998 289bbb294e82
permissions -rw-r--r--
basectx: move __str__ from changectx
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12632
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
     1
  $ cat > correct.py <<EOF
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
     2
  > def toto(arg1, arg2):
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
     3
  >     del arg2
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
     4
  >     return (5 + 6, 9)
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
     5
  > EOF
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
     6
  $ cat > wrong.py <<EOF
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
     7
  > def toto( arg1, arg2):
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
     8
  >     del(arg2)
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
     9
  >     return ( 5+6, 9)
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    10
  > EOF
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    11
  $ cat > quote.py <<EOF
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    12
  > # let's use quote in comments
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    13
  > (''' ( 4x5 )
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    14
  > but """\\''' and finally''',
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    15
  > """let's fool checkpatch""", '1+2',
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    16
  > '"""', 42+1, """and
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    17
  > ( 4-1 ) """, "( 1+1 )\" and ")
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    18
  > a, '\\\\\\\\', "\\\\\\" x-2", "c-1"
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    19
  > EOF
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    20
  $ cat > non-py24.py <<EOF
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    21
  > # Using builtins that does not exist in Python 2.4
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    22
  > if any():
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    23
  >     x = all()
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    24
  >     y = format(x)
19501
725507cd5216 check-code: add a check for the next() builtin, which was new in 2.6
Augie Fackler <raf@durin42.com>
parents: 19494
diff changeset
    25
  >     # next(generator) is new in 2.6
725507cd5216 check-code: add a check for the next() builtin, which was new in 2.6
Augie Fackler <raf@durin42.com>
parents: 19494
diff changeset
    26
  >     z = next(x)
725507cd5216 check-code: add a check for the next() builtin, which was new in 2.6
Augie Fackler <raf@durin42.com>
parents: 19494
diff changeset
    27
  >     # but generator.next() is okay
725507cd5216 check-code: add a check for the next() builtin, which was new in 2.6
Augie Fackler <raf@durin42.com>
parents: 19494
diff changeset
    28
  >     x.next()
725507cd5216 check-code: add a check for the next() builtin, which was new in 2.6
Augie Fackler <raf@durin42.com>
parents: 19494
diff changeset
    29
  >     # and we can make our own next
725507cd5216 check-code: add a check for the next() builtin, which was new in 2.6
Augie Fackler <raf@durin42.com>
parents: 19494
diff changeset
    30
  >     def next(stuff):
725507cd5216 check-code: add a check for the next() builtin, which was new in 2.6
Augie Fackler <raf@durin42.com>
parents: 19494
diff changeset
    31
  >         pass
12632
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    32
  > 
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    33
  > # Do not complain about our own definition
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    34
  > def any(x):
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    35
  >     pass
15285
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    36
  > 
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    37
  > # try/except/finally block does not exist in Python 2.4
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    38
  >     try:
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    39
  >         pass
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    40
  >     except StandardError, inst:
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    41
  >         pass
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    42
  >     finally:
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    43
  >         pass
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    44
  > 
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    45
  > # nested try/finally+try/except is allowed
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    46
  >     try:
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    47
  >         try:
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    48
  >             pass
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    49
  >         except StandardError, inst:
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    50
  >             pass
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    51
  >     finally:
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
    52
  >         pass
17620
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
    53
  > 
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
    54
  > # yield inside a try/finally block is not allowed in Python 2.4
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
    55
  >     try:
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
    56
  >         pass
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
    57
  >         yield 1
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
    58
  >     finally:
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
    59
  >         pass
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
    60
  >     try:
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
    61
  >         yield
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
    62
  >         pass
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
    63
  >     finally:
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
    64
  >         pass
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
    65
  > 
12632
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    66
  > EOF
14763
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
    67
  $ cat > classstyle.py <<EOF
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
    68
  > class newstyle_class(object):
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
    69
  >     pass
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
    70
  > 
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
    71
  > class oldstyle_class:
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
    72
  >     pass
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
    73
  > 
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
    74
  > class empty():
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
    75
  >     pass
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
    76
  > 
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
    77
  > no_class = 1:
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
    78
  >     pass
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
    79
  > EOF
12632
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    80
  $ check_code="$TESTDIR"/../contrib/check-code.py
14763
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
    81
  $ "$check_code" ./wrong.py ./correct.py ./quote.py ./non-py24.py ./classstyle.py
12632
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    82
  ./wrong.py:1:
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    83
   > def toto( arg1, arg2):
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    84
   gratuitous whitespace in () or []
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    85
  ./wrong.py:2:
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    86
   >     del(arg2)
13077
6b8d2ee24ce2 coding style: fix yield used as a function
Thomas Arendsen Hein <thomas@jtah.de>
parents: 13026
diff changeset
    87
   Python keyword is not a function
12632
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    88
  ./wrong.py:3:
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    89
   >     return ( 5+6, 9)
15281
aeeb2afcdc25 check-code: support multiline matches like try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 14763
diff changeset
    90
   gratuitous whitespace in () or []
12632
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    91
   missing whitespace in expression
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    92
  ./quote.py:5:
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    93
   > '"""', 42+1, """and
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    94
   missing whitespace in expression
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    95
  ./non-py24.py:2:
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    96
   > if any():
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    97
   any/all/format not available in Python 2.4
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    98
  ./non-py24.py:3:
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    99
   >     x = all()
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
   100
   any/all/format not available in Python 2.4
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
   101
  ./non-py24.py:4:
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
   102
   >     y = format(x)
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
   103
   any/all/format not available in Python 2.4
19501
725507cd5216 check-code: add a check for the next() builtin, which was new in 2.6
Augie Fackler <raf@durin42.com>
parents: 19494
diff changeset
   104
  ./non-py24.py:6:
725507cd5216 check-code: add a check for the next() builtin, which was new in 2.6
Augie Fackler <raf@durin42.com>
parents: 19494
diff changeset
   105
   >     z = next(x)
725507cd5216 check-code: add a check for the next() builtin, which was new in 2.6
Augie Fackler <raf@durin42.com>
parents: 19494
diff changeset
   106
   no next(foo) in Python 2.4 and 2.5, use foo.next() instead
725507cd5216 check-code: add a check for the next() builtin, which was new in 2.6
Augie Fackler <raf@durin42.com>
parents: 19494
diff changeset
   107
  ./non-py24.py:18:
15285
42e71f5852ee test-check-code.t: test matching try/except/finally introduced in aeeb2afcdc25
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15281
diff changeset
   108
   >     try:
17428
72803c8edaa4 avoid using abbreviations that look like spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 15502
diff changeset
   109
   no try/except/finally in Python 2.4
19501
725507cd5216 check-code: add a check for the next() builtin, which was new in 2.6
Augie Fackler <raf@durin42.com>
parents: 19494
diff changeset
   110
  ./non-py24.py:35:
17620
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
   111
   >     try:
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
   112
   no yield inside try/finally in Python 2.4
19501
725507cd5216 check-code: add a check for the next() builtin, which was new in 2.6
Augie Fackler <raf@durin42.com>
parents: 19494
diff changeset
   113
  ./non-py24.py:40:
17620
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
   114
   >     try:
efd1a4378b64 check-code: catch yield inside try/finally (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17428
diff changeset
   115
   no yield inside try/finally in Python 2.4
14763
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
   116
  ./classstyle.py:4:
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
   117
   > class oldstyle_class:
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
   118
   old-style class, use class foo(object)
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
   119
  ./classstyle.py:7:
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
   120
   > class empty():
b071cd58af50 check-code: fix class style checking (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13077
diff changeset
   121
   class foo() not available in Python 2.4, use class foo(object)
12632
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
   122
  [1]
18183
e1caaeb5a2ed check-code: disallow defunct <> operator
Augie Fackler <raf@durin42.com>
parents: 18180
diff changeset
   123
  $ cat > python3-compat.py << EOF
e1caaeb5a2ed check-code: disallow defunct <> operator
Augie Fackler <raf@durin42.com>
parents: 18180
diff changeset
   124
  > foo <> bar
e1caaeb5a2ed check-code: disallow defunct <> operator
Augie Fackler <raf@durin42.com>
parents: 18180
diff changeset
   125
  > reduce(lambda a, b: a + b, [1, 2, 3, 4])
e1caaeb5a2ed check-code: disallow defunct <> operator
Augie Fackler <raf@durin42.com>
parents: 18180
diff changeset
   126
  > EOF
e1caaeb5a2ed check-code: disallow defunct <> operator
Augie Fackler <raf@durin42.com>
parents: 18180
diff changeset
   127
  $ "$check_code" python3-compat.py
e1caaeb5a2ed check-code: disallow defunct <> operator
Augie Fackler <raf@durin42.com>
parents: 18180
diff changeset
   128
  python3-compat.py:1:
e1caaeb5a2ed check-code: disallow defunct <> operator
Augie Fackler <raf@durin42.com>
parents: 18180
diff changeset
   129
   > foo <> bar
e1caaeb5a2ed check-code: disallow defunct <> operator
Augie Fackler <raf@durin42.com>
parents: 18180
diff changeset
   130
   <> operator is not available in Python 3+, use !=
e1caaeb5a2ed check-code: disallow defunct <> operator
Augie Fackler <raf@durin42.com>
parents: 18180
diff changeset
   131
  python3-compat.py:2:
e1caaeb5a2ed check-code: disallow defunct <> operator
Augie Fackler <raf@durin42.com>
parents: 18180
diff changeset
   132
   > reduce(lambda a, b: a + b, [1, 2, 3, 4])
e1caaeb5a2ed check-code: disallow defunct <> operator
Augie Fackler <raf@durin42.com>
parents: 18180
diff changeset
   133
   reduce is not available in Python 3+
e1caaeb5a2ed check-code: disallow defunct <> operator
Augie Fackler <raf@durin42.com>
parents: 18180
diff changeset
   134
  [1]
13026
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   135
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   136
  $ cat > is-op.py <<EOF
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   137
  > # is-operator comparing number or string literal
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   138
  > x = None
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   139
  > y = x is 'foo'
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   140
  > y = x is "foo"
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   141
  > y = x is 5346
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   142
  > y = x is -6
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   143
  > y = x is not 'foo'
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   144
  > y = x is not "foo"
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   145
  > y = x is not 5346
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   146
  > y = x is not -6
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   147
  > EOF
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   148
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   149
  $ "$check_code" ./is-op.py
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   150
  ./is-op.py:3:
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   151
   > y = x is 'foo'
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   152
   object comparison with literal
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   153
  ./is-op.py:4:
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   154
   > y = x is "foo"
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   155
   object comparison with literal
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   156
  ./is-op.py:5:
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   157
   > y = x is 5346
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   158
   object comparison with literal
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   159
  ./is-op.py:6:
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   160
   > y = x is -6
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   161
   object comparison with literal
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   162
  ./is-op.py:7:
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   163
   > y = x is not 'foo'
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   164
   object comparison with literal
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   165
  ./is-op.py:8:
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   166
   > y = x is not "foo"
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   167
   object comparison with literal
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   168
  ./is-op.py:9:
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   169
   > y = x is not 5346
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   170
   object comparison with literal
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   171
  ./is-op.py:10:
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   172
   > y = x is not -6
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   173
   object comparison with literal
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   174
  [1]
53391819f195 check-code: catch Python 'is' comparing number or string literals
Adrian Buehlmann <adrian@cadifra.com>
parents: 12632
diff changeset
   175
18762
a91387a37f05 check-code: do not prepend "warning" to a failure message
Simon Heimberg <simohe@besonet.ch>
parents: 18183
diff changeset
   176
  $ cat > for-nolineno.py <<EOF
15502
7917a104a285 check-code: add --nolineno option for hiding line numbers
Mads Kiilerich <mads@kiilerich.com>
parents: 15285
diff changeset
   177
  > except:
7917a104a285 check-code: add --nolineno option for hiding line numbers
Mads Kiilerich <mads@kiilerich.com>
parents: 15285
diff changeset
   178
  > EOF
18762
a91387a37f05 check-code: do not prepend "warning" to a failure message
Simon Heimberg <simohe@besonet.ch>
parents: 18183
diff changeset
   179
  $ "$check_code" for-nolineno.py --nolineno
a91387a37f05 check-code: do not prepend "warning" to a failure message
Simon Heimberg <simohe@besonet.ch>
parents: 18183
diff changeset
   180
  for-nolineno.py:0:
15502
7917a104a285 check-code: add --nolineno option for hiding line numbers
Mads Kiilerich <mads@kiilerich.com>
parents: 15285
diff changeset
   181
   > except:
18762
a91387a37f05 check-code: do not prepend "warning" to a failure message
Simon Heimberg <simohe@besonet.ch>
parents: 18183
diff changeset
   182
   naked except clause
15502
7917a104a285 check-code: add --nolineno option for hiding line numbers
Mads Kiilerich <mads@kiilerich.com>
parents: 15285
diff changeset
   183
  [1]
18180
c582a71457e5 check-code: disallow two-argument form of raise
Augie Fackler <raf@durin42.com>
parents: 17620
diff changeset
   184
19422
d9e86d656017 check-code: automatically preppend "warning: " to all warning messages
Simon Heimberg <simohe@besonet.ch>
parents: 18762
diff changeset
   185
  $ cat > warning.t <<EOF
d9e86d656017 check-code: automatically preppend "warning: " to all warning messages
Simon Heimberg <simohe@besonet.ch>
parents: 18762
diff changeset
   186
  >   $ function warnonly {
d9e86d656017 check-code: automatically preppend "warning: " to all warning messages
Simon Heimberg <simohe@besonet.ch>
parents: 18762
diff changeset
   187
  >   > }
d9e86d656017 check-code: automatically preppend "warning: " to all warning messages
Simon Heimberg <simohe@besonet.ch>
parents: 18762
diff changeset
   188
  > EOF
d9e86d656017 check-code: automatically preppend "warning: " to all warning messages
Simon Heimberg <simohe@besonet.ch>
parents: 18762
diff changeset
   189
  $ "$check_code" warning.t
d9e86d656017 check-code: automatically preppend "warning: " to all warning messages
Simon Heimberg <simohe@besonet.ch>
parents: 18762
diff changeset
   190
  $ "$check_code" --warn warning.t
d9e86d656017 check-code: automatically preppend "warning: " to all warning messages
Simon Heimberg <simohe@besonet.ch>
parents: 18762
diff changeset
   191
  warning.t:1:
d9e86d656017 check-code: automatically preppend "warning: " to all warning messages
Simon Heimberg <simohe@besonet.ch>
parents: 18762
diff changeset
   192
   >   $ function warnonly {
d9e86d656017 check-code: automatically preppend "warning: " to all warning messages
Simon Heimberg <simohe@besonet.ch>
parents: 18762
diff changeset
   193
   warning: don't use 'function', use old style
d9e86d656017 check-code: automatically preppend "warning: " to all warning messages
Simon Heimberg <simohe@besonet.ch>
parents: 18762
diff changeset
   194
  [1]
18180
c582a71457e5 check-code: disallow two-argument form of raise
Augie Fackler <raf@durin42.com>
parents: 17620
diff changeset
   195
  $ cat > raise-format.py <<EOF
c582a71457e5 check-code: disallow two-argument form of raise
Augie Fackler <raf@durin42.com>
parents: 17620
diff changeset
   196
  > raise SomeException, message
c582a71457e5 check-code: disallow two-argument form of raise
Augie Fackler <raf@durin42.com>
parents: 17620
diff changeset
   197
  > # this next line is okay
c582a71457e5 check-code: disallow two-argument form of raise
Augie Fackler <raf@durin42.com>
parents: 17620
diff changeset
   198
  > raise SomeException(arg1, arg2)
c582a71457e5 check-code: disallow two-argument form of raise
Augie Fackler <raf@durin42.com>
parents: 17620
diff changeset
   199
  > EOF
19494
3119dc155ac2 check-code: do not abort on an unreadable file, only report this
Simon Heimberg <simohe@besonet.ch>
parents: 19422
diff changeset
   200
  $ "$check_code" not-existing.py raise-format.py
3119dc155ac2 check-code: do not abort on an unreadable file, only report this
Simon Heimberg <simohe@besonet.ch>
parents: 19422
diff changeset
   201
  Skipping*not-existing.py* (glob)
18180
c582a71457e5 check-code: disallow two-argument form of raise
Augie Fackler <raf@durin42.com>
parents: 17620
diff changeset
   202
  raise-format.py:1:
c582a71457e5 check-code: disallow two-argument form of raise
Augie Fackler <raf@durin42.com>
parents: 17620
diff changeset
   203
   > raise SomeException, message
c582a71457e5 check-code: disallow two-argument form of raise
Augie Fackler <raf@durin42.com>
parents: 17620
diff changeset
   204
   don't use old-style two-argument raise, use Exception(message)
c582a71457e5 check-code: disallow two-argument form of raise
Augie Fackler <raf@durin42.com>
parents: 17620
diff changeset
   205
  [1]
19494
3119dc155ac2 check-code: do not abort on an unreadable file, only report this
Simon Heimberg <simohe@besonet.ch>
parents: 19422
diff changeset
   206