forked from pmichaud/pmtcl
/
cmd_catch.t
executable file
·90 lines (75 loc) · 1.53 KB
/
cmd_catch.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Copyright (C) 2004-2007, The Parrot Foundation.
source lib/test_more.tcl
plan 13
eval_is {
catch {
error dead
}
set a ""
} {} {discard error}
eval_is {
catch {
error dead
} var
set var
} {dead} {error messsage}
eval_is {
catch {
set b 0
}
} 0 {error type: none}
eval_is {
catch {
error dead
}
} 1 {error type: error}
eval_is {
catch {
return
}
} 2 {error type: return}
eval_is {
catch {
break
}
} 3 {error type: break}
eval_is {
catch {
continue
}
} 4 {error type: continue}
eval_is {
set a [catch blorg var]
list $a $var
} {1 {invalid command name "blorg"}} {error, invalid command} {TODO NQPRX}
eval_is {catch} \
{wrong # args: should be "catch script ?resultVarName? ?optionVarName?"} \
{too few args}
eval_is {
list [catch {incr} msg] $msg
} {1 {wrong # args: should be "incr varName ?increment?"}} \
{catch {incr} msg}
eval_is {
namespace eval abc {
proc a {} {return "ok"}
proc b {} {catch {a} msg; return $msg }
b
}
} ok {catch should respect the namespace it is invoked in} {TODO NQPRX}
eval_is {
set a 3
catch {
set a 2
set a [
}
set a
} 2 {execute code as soon as possible, don't wait until the end of the block} {TODO NQPRX}
eval_is {
catch { return -errorcode 1 -errorinfo boo -code error -level 1 "eek" } msg opts
list $msg \
[dict get $opts -errorcode] \
[dict get $opts -errorinfo] \
[dict get $opts -code] \
[dict get $opts -level]
} {eek 1 boo 1 1} {basic opts handling} {TODO NQPRX}
# vim: filetype=tcl: