Commit 4a690b37 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #344 from rntz/tester-explicit-failure

Add should_error directive, for tests that should exit non-0
parents ede5dbc3 bd4a04ce
...@@ -149,6 +149,7 @@ static Box* importSub(const std::string& name, const std::string& full_name, Box ...@@ -149,6 +149,7 @@ static Box* importSub(const std::string& name, const std::string& full_name, Box
return module; return module;
} }
// TODO: these are a crude hack to help our tests, find a better way
if (name == "basic_test") if (name == "basic_test")
return importTestExtension("basic_test"); return importTestExtension("basic_test");
if (name == "descr_test") if (name == "descr_test")
......
# 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
......
...@@ -5,7 +5,7 @@ for k in sorted(dir(resource)): ...@@ -5,7 +5,7 @@ for k in sorted(dir(resource)):
continue continue
print k, getattr(resource, k) print k, getattr(resource, k)
TIME_LIMIT = 100 TIME_LIMIT = 5
resource.setrlimit(resource.RLIMIT_CPU, (TIME_LIMIT + 1, TIME_LIMIT + 1)) resource.setrlimit(resource.RLIMIT_CPU, (TIME_LIMIT + 1, TIME_LIMIT + 1))
MAX_MEM_MB = 100 MAX_MEM_MB = 100
......
# 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
...@@ -126,6 +126,7 @@ def run_test(fn, check_stats, run_memcheck): ...@@ -126,6 +126,7 @@ def run_test(fn, check_stats, run_memcheck):
jit_args = ["-rq"] + EXTRA_JIT_ARGS jit_args = ["-rq"] + EXTRA_JIT_ARGS
collect_stats = True collect_stats = True
expected = "success" expected = "success"
should_error = False
allow_warnings = [] allow_warnings = []
for l in open(fn): for l in open(fn):
l = l.strip() l = l.strip()
...@@ -141,6 +142,8 @@ def run_test(fn, check_stats, run_memcheck): ...@@ -141,6 +142,8 @@ def run_test(fn, check_stats, run_memcheck):
jit_args += l jit_args += l
elif l.startswith("# expected:"): elif l.startswith("# expected:"):
expected = l[len("# expected:"):].strip() expected = l[len("# expected:"):].strip()
elif l.startswith("# should_error"):
should_error = True
elif l.startswith("# fail-if:"): elif l.startswith("# fail-if:"):
condition = l.split(':', 1)[1].strip() condition = l.split(':', 1)[1].strip()
if eval(condition): if eval(condition):
...@@ -216,13 +219,29 @@ def run_test(fn, check_stats, run_memcheck): ...@@ -216,13 +219,29 @@ def run_test(fn, check_stats, run_memcheck):
if expected == "fail": if expected == "fail":
r += " Expected failure (got code %d, should be %d)" % (code, expected_code) r += " Expected failure (got code %d, should be %d)" % (code, expected_code)
return r return r
elif KEEP_GOING:
r += " \033[%dmFAILED\033[0m (%s)" % (color, msg)
failed.append(fn)
return r
else: else:
if KEEP_GOING: raise Exception("%s\n%s\n%s" % (msg, err, stderr))
r += " \033[%dmFAILED\033[0m (%s)" % (color, msg)
failed.append(fn) elif should_error == (code == 0):
return r color = 31 # red
else: if code == 0:
raise Exception("%s\n%s\n%s" % (msg, err, stderr)) msg = "Exited successfully; remove '# should_error' if this is expected"
else:
msg = "Exited with code %d; add '# should_error' if this is expected" % code
if KEEP_GOING:
r += " \033[%dmFAILED\033[0m (%s)" % (color, msg)
failed.append(fn)
return r
else:
# show last line of stderr so we have some idea went wrong
print "Last line of stderr: " + last_stderr_line
raise Exception(msg)
elif out != expected_out: elif out != expected_out:
if expected == "fail": if expected == "fail":
r += " Expected failure (bad output)" r += " Expected failure (bad output)"
......
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