Commit 8f4fc76e authored by Stefan Behnel's avatar Stefan Behnel

more error tests, some failing

parent f714831a
__doc__ = u"""
>>> call2()
>>> call3()
>>> call4()
"""
import sys, re
if sys.version_info >= (2,6):
__doc__ = re.sub(u"Error: (.*)exactly(.*)", u"Error: \\1at most\\2", __doc__)
# the calls:
def call2():
b(1,2)
def call3():
b(1,2,3)
def call4():
b(1,2,3,4)
# the called function:
cdef b(a, b, c=1, d=2):
pass
def f():
cdef int int1, int3
cdef int *ptr1, *ptr2, *ptr3
ptr1 = ptr2 + ptr3 # error
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_addop.pyx:4:13: Invalid operand types for '+' (int *; int *)
"""
cdef spam(int i, char *s = "blarg", float f): # can't have default value
pass
def swallow(x, y = 42, z): # non-default after default
pass
cdef class Grail:
def __add__(x, y = 42): # can't have default value
pass
_ERRORS = u"""
1:9: Non-default argument follows default argument
9:16: This argument cannot have a default value
4:23: Non-default argument following default argument
"""
cdef void foo(obj):
cdef int i1
cdef char *p1
cdef int *p2
i1 = p1 # error
p2 = obj # error
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_ass.pyx:5:16: Cannot assign type 'char *' to 'int'
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_ass.pyx:6:17: Cannot convert Python object to 'int *'
"""
cdef void spam():
None = 42
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_assnone.pyx:2:1: Cannot assign to or delete this
"""
def f():
cdef int int1, int2
cdef char *ptr
int1 = int2 | ptr # error
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_bitop.pyx:4:13: Invalid operand types for '|' (int; char *)
"""
cdef int
cdef extern from *:
void f(int)
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors3/e_cdef_missing_declarator.pyx:1:8: Empty declarator
"""
cdef struct spam:
pass
ctypedef union eggs:
pass
cdef enum ham:
pass
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cdefemptysue.pyx:1:5: Empty struct or union definition not allowed outside a 'cdef extern from' block
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cdefemptysue.pyx:4:0: Empty struct or union definition not allowed outside a 'cdef extern from' block
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cdefemptysue.pyx:7:5: Empty enum definition not allowed outside a 'cdef extern from' block
"""
cdef enum Spam:
a, b, c
cdef void f():
global a
a = 42 # assignment to non-lvalue
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cenum.pyx:6:3: Assignment to non-lvalue 'a'
"""
cdef class C:
cdef void f(self):
pass
cdef class D(C):
cdef void f(self, int x):
pass
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors3/e_cmethbasematch.pyx:6:6: Signature does not match previous declaration
/Local/Projects/D/Pyrex/Source/Tests/Errors3/e_cmethbasematch.pyx:2:6: Previous declaration is here
"""
cdef void foo():
cdef int bool, int1
cdef char *ptr2
cdef int *ptr3
bool = int1 == ptr2 # error
bool = ptr2 == ptr3 # error
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cmp.pyx:5:13: Invalid types for '==' (int, char *)
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cmp.pyx:6:13: Invalid types for '==' (char *, int *)
"""
cdef struct Spam:
int i
char c
float *p[42]
obj # error - py object
cdef struct Spam: # error - redefined
int j
cdef struct Grail
cdef void eggs(Spam s):
cdef int j
cdef Grail *gp
j = s.k # error - undef attribute
j = s.p # type error
s.p = j # type error
j = j.i # error - no attributes
j.i = j # error - no attributes
j = gp.x # error - incomplete type
gp.x = j # error - incomplete type
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cstruct.pyx:5:36: C struct/union member cannot be a Python object
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cstruct.pyx:7:5: 'Spam' already defined
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cstruct.pyx:15:6: Object of type 'Spam' has no attribute 'k'
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cstruct.pyx:16:6: Cannot assign type 'float *[42]' to 'int'
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cstruct.pyx:17:21: Cannot assign type 'int' to 'float *[42]'
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cstruct.pyx:18:6: Object of type 'int' has no attribute 'i'
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cstruct.pyx:19:2: Object of type 'int' has no attribute 'i'
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cstruct.pyx:20:7: Cannot select attribute of incomplete type 'Grail'
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_cstruct.pyx:21:3: Cannot select attribute of incomplete type 'Grail'
"""
ctypedef struct Spam
ctypedef class Eggs
cdef extern from *:
ctypedef struct Ham
ctypedef struct Spam:
int i
ctypedef class Eggs:
pass
ctypedef struct Spam
ctypedef class Eggs
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_ctypedefforward.pyx:1:0: Forward-referenced type must use 'cdef', not 'ctypedef'
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_ctypedefforward.pyx:2:0: Forward-referenced type must use 'cdef', not 'ctypedef'
"""
cdef struct Foo
ctypedef struct Foo:
int i
ctypedef struct Blarg:
char c
cdef struct Blarg
cdef class Spam
ctypedef class Spam:
pass
cdef Foo f
cdef Blarg b
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_ctypedefornot.pyx:3:0: 'Foo' previously declared using 'cdef'
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_ctypedefornot.pyx:9:5: 'Blarg' previously declared using 'ctypedef'
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_ctypedefornot.pyx:13:0: 'Spam' previously declared using 'cdef'
"""
cdef extern void fa[5]()
cdef extern int af()[5]
cdef extern int ff()()
cdef void f():
cdef void *p
cdef int (*h)()
h = <int ()()>f
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors3/e_declarations.pyx:1:19: Array element cannot be a function
/Local/Projects/D/Pyrex/Source/Tests/Errors3/e_declarations.pyx:2:18: Function cannot return an array
/Local/Projects/D/Pyrex/Source/Tests/Errors3/e_declarations.pyx:3:18: Function cannot return a function
/Local/Projects/D/Pyrex/Source/Tests/Errors3/e_declarations.pyx:8:10: Function cannot return a function
/Local/Projects/D/Pyrex/Source/Tests/Errors3/e_declarations.pyx:8:5: Cannot cast to a function type
"""
cdef struct S:
int m
def f(a):
cdef int i, x[2]
cdef S s
global j
del f() # error
del i # error: deletion of non-Python object
del j # error: deletion of non-Python object
del a # error: deletion of local name not supported
del x[i] # error: deletion of non-Python object
del s.m # error: deletion of non-Python object
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_del.pyx:8:6: Cannot assign to or delete this
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_del.pyx:9:45: Deletion of non-Python object
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_del.pyx:12:6: Deletion of non-Python object
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_del.pyx:13:6: Deletion of non-Python object
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_del.pyx:11:52: Deletion of local or C global name not supported
"""
ctypedef int (*spamfunc)(int, char *) except 42
ctypedef int (*grailfunc)(int, char *)
cdef grailfunc grail
cdef spamfunc spam
grail = spam # type mismatch
spam = grail # type mismatch
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_excvalfunctype.pyx:7:28: Cannot assign type 'e_excvalfunctype.spamfunc' to 'e_excvalfunctype.grailfunc'
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_excvalfunctype.pyx:8:28: Cannot assign type 'e_excvalfunctype.grailfunc' to 'e_excvalfunctype.spamfunc'
"""
cdef class Spam:
answer = 42
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_exestmtinexttype.pyx:2:1: Executable statement not allowed here
"""
cdef class Spam:
cdef public Spam e
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_extmember.pyx:2:18: Non-generic Python attribute cannot be exposed for writing from Python
"""
cdef class C:
cdef object __weakref__
cdef class D:
cdef public object __weakref__
cdef class E:
cdef readonly object __weakref__
cdef void f():
cdef C c
cdef object x
x = c.__weakref__
c.__weakref__ = x
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_extweakref.pyx:5:20: Special attribute __weakref__ cannot be exposed to Python
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_extweakref.pyx:8:22: Special attribute __weakref__ cannot be exposed to Python
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_extweakref.pyx:13:6: Illegal use of special attribute __weakref__
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_extweakref.pyx:14:2: Illegal use of special attribute __weakref__
"""
def f(obj1, obj2):
cdef int int1, int2, int3
cdef float flt1, *ptr1
cdef int array1[42]
int1 = array1[flt1] # error
int1 = array1[ptr1] # error
int1 = int2[int3] # error
obj1 = obj2[ptr1] # error
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_index.pyx:5:14: Invalid index type 'float'
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_index.pyx:6:14: Invalid index type 'float *'
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_index.pyx:7:12: Attempting to index non-array type 'int'
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_index.pyx:8:17: Cannot convert 'float *' to Python object
"""
def f():
cdef float flt1, flt2, flt3
flt1 = flt2 % flt3 # error
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_modop.pyx:3:13: Invalid operand types for '%' (float; float)
"""
def f(obj1a, obj1b):
cdef int int1, int2, int3
cdef int *ptr2
int1, int3, obj1a = int2, ptr2, obj1b # error
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_multass.pyx:4:31: Cannot assign type 'int *' to 'int'
"""
cdef extern grail(char *s, int i)
cdef extern spam(char *s, int i,...)
cdef f():
grail() # too few args
grail("foo") # too few args
grail("foo", 42, 17) # too many args
spam() # too few args
spam("blarg") # too few args
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_nargs.pyx:5:6: Call with wrong number of arguments (expected 2, got 0)
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_nargs.pyx:6:6: Call with wrong number of arguments (expected 2, got 1)
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_nargs.pyx:7:6: Call with wrong number of arguments (expected 2, got 3)
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_nargs.pyx:8:5: Call with wrong number of arguments (expected at least 2, got 0)
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_nargs.pyx:9:5: Call with wrong number of arguments (expected at least 2, got 1)
"""
cdef class C:
cdef void f(self):
pass
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors3/e_nogilcmeth.pyx:2:6: Signature does not match previous declaration
/Local/Projects/D/Pyrex/Source/Tests/Errors3/e_nogilcmeth.pxd:2:12: Previous declaration is here
"""
cdef extern from *:
cdef void f() nogil
cdef void (*fp)()
fp = f
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors3/e_nogilfunctype.pyx:5:6: Cannot assign type 'void (void) nogil' to 'void (*)(void)'
"""
cdef extern class Grail.Shrubbery
cdef void spam(Shrubbery sh not None):
pass
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_notnone.pyx:3:15: 'not None' only allowed in Python functions
"""
def eggs(int x not None, y not None):
pass
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_notnone2.pyx:1:0: Only extension type arguments can have 'not None'
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_notnone2.pyx:1:0: Only extension type arguments can have 'not None'
"""
def f():
cdef int int1, int2
cdef int *ptr
int1 = int2 * ptr # error
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_numop.pyx:4:13: Invalid operand types for '*' (int; int *)
"""
def f():
cdef char *str1
cdef float flt1, flt2, flt3
flt1 = str1 ** flt3 # error
flt1 = flt2 ** str1 # error
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_powop.pyx:4:13: Invalid operand types for '**' (char *; float)
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_powop.pyx:5:13: Invalid operand types for '**' (float; char *)
"""
cdef struct spam:
object parrot
def f():
cdef spam s
s.parrot = x
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_pyobinstruct.pyx:2:8: C struct/union member cannot be a Python object
"""
class C:
def f(self):
pass
def f(self):
pass
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_redeclmeth.pyx:4:1: 'f' already declared
"""
cdef void g():
cdef int i
return i # error
cdef int h():
cdef int *p
return # error
return p # error
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_return.pyx:3:17: Return with value in void function
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_return.pyx:7:1: Return value required
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_return.pyx:8:17: Cannot assign type 'int *' to 'int'
"""
cdef struct unbekannt
cdef int n
n = sizeof(unbekannt)
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_sizeofincomplete.pyx:3:4: Cannot take sizeof incomplete type 'unbekannt'
"""
def f(obj2):
cdef int *ptr1
obj1 = obj2[ptr1::] # error
obj1 = obj2[:ptr1:] # error
obj1 = obj2[::ptr1] # error
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_slice.pyx:3:17: Cannot convert 'int *' to Python object
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_slice.pyx:4:18: Cannot convert 'int *' to Python object
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_slice.pyx:5:19: Cannot convert 'int *' to Python object
"""
def f():
cdef int int2
cdef char *ptr1, *ptr2, *ptr3
ptr1 = int2 - ptr3 # error
ptr1 = ptr2 - ptr3 # error
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_subop.pyx:4:13: Invalid operand types for '-' (int; char *)
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_subop.pyx:5:13: Cannot assign type 'int' to 'char *'
"""
def foo(obj):
cdef int *p
p = <int *>blarg # okay
p = <int *>(foo + blarg) # error - temporary
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_tempcast.pyx:4:5: Casting temporary Python object to non-Python type
"""
cdef class Spam
cdef extern class external.Eggs
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_undefexttype.pyx:1:5: C class 'Spam' is declared but not defined
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_undefexttype.pyx:2:5: C class 'Eggs' is declared but not defined
"""
def f():
cdef int int1
cdef char *str2
int1 = -str2 # error
int1 = ~str2 # error
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_unop.pyx:4:8: Invalid operand type for '-' (char *)
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_unop.pyx:5:8: Invalid operand type for '~' (char *)
"""
def f(a, b):
cdef int i
break # error
continue # error
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_while.pyx:3:1: break statement not inside loop
/Local/Projects/D/Pyrex/Source/Tests/Errors2/e_while.pyx:4:1: continue statement not inside loop
"""
cdef class C:
cdef void f(self):
pass
_ERRORS = u"""
2:6: Signature does not match previous declaration
"""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment