#!perl
# Copyright (C) 2004-2007, The Perl Foundation.
# $Id: cmd_catch.t 21247 2007-09-13 06:31:01Z paultcochrane $
# the following lines re-execute this as a tcl script
# the \ at the end of these lines makes them a comment in tcl \
use lib qw(languages/tcl/lib tcl/lib lib ../lib ../../lib); # \
use Tcl::Test; #\
__DATA__
source lib/test_more.tcl
plan 11
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}
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 {needs fixing, used to work}}
syntax highlighted by Code2HTML, v. 0.9.1