Commit c53eec69 authored by Michael Arntzenius's avatar Michael Arntzenius

fix tests to use "# should_error" or catch-and-print as appropriate

parent 30300d6c
# should_error
# Expected failure: even though we could copy the "definedness" information in the assignment, # Expected failure: even though we could copy the "definedness" information in the assignment,
# that's actually an error. # that's actually an error.
......
# should_error
# Expected failure: stacktrace testing # Expected failure: stacktrace testing
print 5 % 0 print 5 % 0
# should_error
not_defined not_defined
# should_error
# Expected failure: adding things that can't be added # Expected failure: adding things that can't be added
1 + "" 1 + ""
# should_error
int.a = 1 int.a = 1
# should_error
i = 0 i = 0
i.a = 0 i.a = 0
...@@ -15,4 +15,7 @@ print C.b ...@@ -15,4 +15,7 @@ print C.b
print C.a print C.a
print o.c print o.c
print o.b print o.b
print o.a # this should error try:
print o.a
except AttributeError, e:
print e
# should_error
# This should raise a python level error, not an assertion in the compiler # This should raise a python level error, not an assertion in the compiler
x = 1 x = 1
......
# This should raise a python level error, not an assertion in the compiler # This should raise a python level error, not an assertion in the compiler
print int.doesnt_exist try:
print int.doesnt_exist
except AttributeError, e:
print e
...@@ -22,5 +22,11 @@ class C(object): ...@@ -22,5 +22,11 @@ class C(object):
return self.n return self.n
print len(C(1)) print len(C(1))
print len(1) try:
print len(C("hello world")) print len(1)
except TypeError, e:
print e
try:
print len(C("hello world"))
except TypeError, e:
print e
# should_error
# Make sure that overriding __file__ doesn't change the traceback # Make sure that overriding __file__ doesn't change the traceback
# TODO the tester doesn't currently check the traceback # TODO the tester doesn't currently check the traceback
......
# should_error
class C(object): class C(object):
pass pass
......
# should_error
def f(): def f():
if 0: if 0:
str = 0 str = 0
......
# should_error
def msg(): def msg():
print "msg()" print "msg()"
return "failure message" return "failure message"
......
...@@ -114,4 +114,7 @@ def f10(): ...@@ -114,4 +114,7 @@ def f10():
# This should error: the lhs is evaluated first # This should error: the lhs is evaluated first
x += [x for x in xrange(5)][0] x += [x for x in xrange(5)][0]
print x print x
f10() try:
f10()
except UnboundLocalError, e:
print e
...@@ -9,5 +9,8 @@ def f(): ...@@ -9,5 +9,8 @@ def f():
# Augassigns can change the type of the variable: # Augassigns can change the type of the variable:
i += IntLike() i += IntLike()
print i print i
i + 1 try:
i + 1
except TypeError, e:
print e
f() f()
...@@ -4,4 +4,7 @@ print isinstance(3, basestring) ...@@ -4,4 +4,7 @@ print isinstance(3, basestring)
print basestring.__doc__ print basestring.__doc__
# should raise an exception # should raise an exception
t = basestring.__new__(basestring) try:
t = basestring.__new__(basestring)
except TypeError, e:
print e
...@@ -157,4 +157,7 @@ try: ...@@ -157,4 +157,7 @@ try:
except SystemError, e: except SystemError, e:
print e print e
print c.foo() try:
print c.foo()
except SystemError, e:
print e
# should_error
# skip-if: sys.version_info < (2, 7, 4) # skip-if: sys.version_info < (2, 7, 4)
# - Error message changed in 2.7.4 # - Error message changed in 2.7.4
......
...@@ -6,5 +6,7 @@ def bad_addr3(_x): ...@@ -6,5 +6,7 @@ def bad_addr3(_x):
def g(y3): def g(y3):
return x3 + y3 return x3 + y3
return g return g
print bad_addr3(1)(2) try:
print bad_addr3(1)(2)
except NameError, e:
print e
...@@ -5,4 +5,7 @@ def _escape(): ...@@ -5,4 +5,7 @@ def _escape():
if code: if code:
return code return code
_escape() try:
_escape()
except NameError, e:
print e
...@@ -34,8 +34,8 @@ C.ndd = 7 ...@@ -34,8 +34,8 @@ C.ndd = 7
#TODO it would be nice to print these out (once __dict__ is implemented) #TODO it would be nice to print these out (once __dict__ is implemented)
#print C.__dict__['dd'] #print C.__dict__['dd']
#print C.__dict__['ndd'] #print C.__dict__['ndd']
print c.dd print C.dd
print c.ndd print C.ndd
# Repeat all of the above for subclasses of the descriptors # Repeat all of the above for subclasses of the descriptors
......
...@@ -4,4 +4,7 @@ def f(): ...@@ -4,4 +4,7 @@ def f():
# the del marks 'x' as a name written to in this scope # the del marks 'x' as a name written to in this scope
del x del x
print x print x
f() try:
f()
except NameError, e:
print e
# should_error
class BadException(Exception): class BadException(Exception):
def __str__(self): def __str__(self):
print "str" print "str"
...@@ -7,7 +8,7 @@ try: ...@@ -7,7 +8,7 @@ try:
# This will raise: # This will raise:
print BadException() print BadException()
assert 0 assert 0
except NotImplementedError: except NotImplementedError, e:
pass print e
raise BadException() raise BadException()
...@@ -18,4 +18,7 @@ def f2(y): ...@@ -18,4 +18,7 @@ def f2(y):
return x return x
return y return y
print g2(f2(2)) try:
print g2(f2(2))
except NameError, e:
print e
# should_error
from __future__ import rvalue_references # should cause syntax error from __future__ import rvalue_references # should cause syntax error
# should_error
"docstring" "docstring"
"not a docstring" "not a docstring"
......
# should_error
"docstring" "docstring"
def f(): def f():
......
...@@ -2,4 +2,7 @@ l = range(5) ...@@ -2,4 +2,7 @@ l = range(5)
print getattr(l, "pop")() print getattr(l, "pop")()
print getattr([], "a", "default") print getattr([], "a", "default")
print getattr([], "a") try:
print getattr([], "a")
except AttributeError, e:
print e
# should_error
print getattr([], []) print getattr([], [])
...@@ -21,4 +21,7 @@ c = C() ...@@ -21,4 +21,7 @@ c = C()
c.__getitem__ = gi c.__getitem__ = gi
print c[1] print c[1]
print 1[1] try:
print 1[1]
except TypeError, e:
print e
...@@ -4,7 +4,10 @@ def f(): ...@@ -4,7 +4,10 @@ def f():
print True # builtin, redefined print True # builtin, redefined
print False # builtin, not redefined print False # builtin, not redefined
print z # local print z # local
print y # non-builtin, not defined try:
print y # non-builtin, not defined
except NameError, e:
print e
x = 2 x = 2
z = 2 z = 2
......
# should_error
# As the test filename says, init functions must return None. # As the test filename says, init functions must return None.
# This file tests that; it also makes sure that it gets tested # This file tests that; it also makes sure that it gets tested
# when in a patchpoint. # when in a patchpoint.
......
...@@ -40,5 +40,7 @@ def f2(n, b): ...@@ -40,5 +40,7 @@ def f2(n, b):
f2(5, 0) f2(5, 0)
print i print i
f2(0, 1) f2(0, 1)
f2(0, 0) try:
f2(0, 0)
except UnboundLocalError, e:
print e
# should_error
# skip-if: sys.version_info < (2, 7, 4) # skip-if: sys.version_info < (2, 7, 4)
# - Error message changed in 2.7.4 # - Error message changed in 2.7.4
......
# should_error
class C(object): class C(object):
return return
...@@ -17,4 +17,7 @@ def si(k, v): ...@@ -17,4 +17,7 @@ def si(k, v):
c.__setitem__ = si c.__setitem__ = si
c[3] = 4 c[3] = 4
1[2] = 3 try:
1[2] = 3
except TypeError, e:
print e
# should_error
# Different ways of nesting exceptions # Different ways of nesting exceptions
import sys import sys
......
# should_error
# Int not iterable: # Int not iterable:
a, b, c = 1 a, b, c = 1
...@@ -17,4 +17,7 @@ class C(object): ...@@ -17,4 +17,7 @@ class C(object):
def f(a, b, c): def f(a, b, c):
print a, b, c print a, b, c
f(*C()) try:
f(*C())
except TypeError, e:
print e
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