Skip to content

Commit

Permalink
compile: more tests on exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ncw committed May 21, 2015
1 parent bf0f523 commit 5ceac9c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
34 changes: 34 additions & 0 deletions compile/compile_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3851,6 +3851,40 @@ var compileTestData = []struct {
Firstlineno: 1,
Lnotab: "\x0c\x01\x0c\x01",
}, nil, ""},
{"ok = False\ntry:\n raise SyntaxError\nexcept SyntaxError:\n ok = True\nassert ok\n", "exec", &py.Code{
Argcount: 0,
Kwonlyargcount: 0,
Nlocals: 0,
Stacksize: 11,
Flags: 64,
Code: "\x64\x00\x00\x5a\x00\x00\x79\x0a\x00\x65\x01\x00\x82\x01\x00\x57\x6e\x18\x00\x04\x65\x01\x00\x6b\x0a\x00\x72\x2a\x00\x01\x01\x01\x64\x01\x00\x5a\x00\x00\x59\x6e\x01\x00\x58\x65\x00\x00\x73\x37\x00\x74\x02\x00\x82\x01\x00\x64\x02\x00\x53",
Consts: []py.Object{py.False, py.True, py.None},
Names: []string{"ok", "SyntaxError", "AssertionError"},
Varnames: []string{},
Freevars: []string{},
Cellvars: []string{},
Filename: "<string>",
Name: "<module>",
Firstlineno: 1,
Lnotab: "\x06\x01\x03\x01\x0a\x01\x0d\x01\x0b\x01",
}, nil, ""},
{"ok = False\ntry:\n raise SyntaxError\nexcept SyntaxError as e:\n ok = True\nassert ok\n", "exec", &py.Code{
Argcount: 0,
Kwonlyargcount: 0,
Nlocals: 0,
Stacksize: 16,
Flags: 64,
Code: "\x64\x00\x00\x5a\x00\x00\x79\x0a\x00\x65\x01\x00\x82\x01\x00\x57\x6e\x2b\x00\x04\x65\x01\x00\x6b\x0a\x00\x72\x3d\x00\x01\x5a\x02\x00\x01\x7a\x0b\x00\x64\x01\x00\x5a\x00\x00\x57\x59\x64\x02\x00\x64\x02\x00\x5a\x02\x00\x5b\x02\x00\x58\x6e\x01\x00\x58\x65\x00\x00\x73\x4a\x00\x74\x03\x00\x82\x01\x00\x64\x02\x00\x53",
Consts: []py.Object{py.False, py.True, py.None},
Names: []string{"ok", "SyntaxError", "e", "AssertionError"},
Varnames: []string{},
Freevars: []string{},
Cellvars: []string{},
Filename: "<string>",
Name: "<module>",
Firstlineno: 1,
Lnotab: "\x06\x01\x03\x01\x0a\x01\x12\x01\x19\x01",
}, nil, ""},
{"try:\n f()\nexcept Exception:\n h()\n", "exec", &py.Code{
Argcount: 0,
Kwonlyargcount: 0,
Expand Down
16 changes: 16 additions & 0 deletions compile/make_compile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,22 @@ class DeRefTest:
''', "exec"),
# try/except/finally/else
('''\
ok = False
try:
raise SyntaxError
except SyntaxError:
ok = True
assert ok
''', "exec"),
('''\
ok = False
try:
raise SyntaxError
except SyntaxError as e:
ok = True
assert ok
''', "exec"),
('''\
try:
f()
except Exception:
Expand Down

0 comments on commit 5ceac9c

Please sign in to comment.