tests/test-check-code.t
author Yuya Nishihara <yuya@tcha.org>
Sat, 25 Dec 2010 21:59:00 +0900
branchstable
changeset 13225 e3bf16703e26
parent 12632 6c98107f787e
child 13026 53391819f195
permissions -rw-r--r--
util: fix ellipsis() not to break multi-byte sequence (issue2564) It tries to convert localstr to unicode before truncating. Because we cannot assume that the given text is encoded in local encoding, it falls back to raw string in case of unicode error.
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)
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    25
  > 
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    26
  > # Do not complain about our own definition
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    27
  > def any(x):
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    28
  >     pass
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    29
  > EOF
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    30
  $ check_code="$TESTDIR"/../contrib/check-code.py
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    31
  $ "$check_code" ./wrong.py ./correct.py ./quote.py ./non-py24.py
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    32
  ./wrong.py:1:
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    33
   > def toto( arg1, arg2):
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    34
   gratuitous whitespace in () or []
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    35
  ./wrong.py:2:
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    36
   >     del(arg2)
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    37
   del isn't a function
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    38
  ./wrong.py:3:
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    39
   >     return ( 5+6, 9)
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    40
   missing whitespace in expression
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    41
   gratuitous whitespace in () or []
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    42
  ./quote.py:5:
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    43
   > '"""', 42+1, """and
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    44
   missing whitespace in expression
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    45
  ./non-py24.py:2:
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    46
   > if any():
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    47
   any/all/format not available in Python 2.4
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    48
  ./non-py24.py:3:
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    49
   >     x = all()
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    50
   any/all/format not available in Python 2.4
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    51
  ./non-py24.py:4:
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    52
   >     y = format(x)
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    53
   any/all/format not available in Python 2.4
6c98107f787e tests: unify test-check-code
Brodie Rao <brodie@bitheap.org>
parents: 11822
diff changeset
    54
  [1]