8000 compile: more tests on exception handling · go-python/gpython@5ceac9c · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ceac9c

Browse files
committed
compile: more tests on exception handling
1 parent bf0f523 commit 5ceac9c

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

compile/compile_data_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3851,6 +3851,40 @@ var compileTestData = []struct {
38513851
Firstlineno: 1,
38523852
Lnotab: "\x0c\x01\x0c\x01",
38533853
}, nil, ""},
3854+
{"ok = False\ntry:\n raise SyntaxError\nexcept SyntaxError:\n ok = True\nassert ok\n", "exec", &py.Code{
3855+
Argcount: 0,
3856+
Kwonlyargcount: 0,
3857+
Nlocals: 0,
3858+
Stacksize: 11,
3859+
Flags: 64,
3860+
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",
3861+
Consts: []py.Object{py.False, py.True, py.None},
3862+
Names: []string{"ok", "SyntaxError", "AssertionError"},
3863+
Varnames: []string{},
3864+
Freevars: []string{},
3865+
Cellvars: []string{},
3866+
Filename: "<string>",
3867+
Name: "<module>",
3868+
Firstlineno: 1,
3869+
Lnotab: "\x06\x01\x03\x01\x0a\x01\x0d\x01\x0b\x01",
3870+
}, nil, ""},
3871+
{"ok = False\ntry:\n raise SyntaxError\nexcept SyntaxError as e:\n ok = True\nassert ok\n", "exec", &py.Code{
3872+
Argcount: 0,
3873+
Kwonlyargcount: 0,
3874+
Nlocals: 0,
3875+
Stacksize: 16,
3876+
Flags: 64,
3877+
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",
3878+
Consts: []py.Object{py.False, py.True, py.None},
3879+
Names: []string{"ok", "SyntaxError", "e", "AssertionError"},
3880+
Varnames: []string{},
3881+
Freevars: []string{},
3882+
Cellvars: []string{},
3883+
Filename: "<string>",
3884+
Name: "<module>",
3885+
Firstlineno: 1,
3886+
Lnotab: "\x06\x01\x03\x01\x0a\x01\x12\x01\x19\x01",
3887+
}, nil, ""},
38543888
{"try:\n f()\nexcept Exception:\n h()\n", "exec", &py.Code{
38553889
Argcount: 0,
< F577 div aria-hidden="true" class="position-absolute top-0 d-flex user-select-none DiffLineTableCellParts-module__comment-indicator--eI0hb">
38563890
Kwonlyargcount: 0,

compile/make_compile_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,22 @@ class DeRefTest:
328328
''', "exec"),
329329
# try/except/finally/else
330330
('''\
331+
ok = False
332+
try:
333+
raise SyntaxError
334+
except SyntaxError:
335+
ok = True
336+
assert ok
337+
''', "exec"),
338+
('''\
339+
ok = False
340+
try:
341+
raise SyntaxError
342+
except SyntaxError as e:
343+
ok = True
344+
assert ok
345+
''', "exec"),
346+
('''\
331347
try:
332348
f()
333349
except Exception:

0 commit comments

Comments
 (0)
0