Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tcltest - global variables

25 views
Skip to first unread message

Antonio Ceballos

unread,
Aug 30, 2005, 1:44:55 PM8/30/05
to
Hi all,

How do you write test cases with tcltest for procedures or methods that
access and/or modify global variables or itcl member fields?

Cheers,
Antonio


Bob Techentin

unread,
Aug 31, 2005, 11:53:13 AM8/31/05
to
"Antonio Ceballos" <ceba...@iies.es> wrote

>
> How do you write test cases with tcltest for procedures or methods that
> access and/or modify global variables or itcl member fields?

Globals are easy. Tcltests run in the global scope, so setting variables
will automatically set global variables.

If you want to control Incr Tcl objects from Tcltests, that is easy too.
But you are generally testing the object interface, and not setting or
testing member fields directly.

Bob
--
Bob Techentin techenti...@NOSPAMmayo.edu
Mayo Foundation (507) 538-5495
200 First St. SW FAX (507) 284-9171
Rochester MN, 55901 USA http://www.mayo.edu/sppdg/

Don Porter

unread,
Aug 31, 2005, 12:51:45 PM8/31/05
to
Bob Techentin wrote:
> Globals are easy. Tcltests run in the global scope, so setting variables
> will automatically set global variables.

No, a tcltest test is run in the scope of the caller of the
[::tcltest::test] command.

--
| Don Porter Mathematical and Computational Sciences Division |
| donald...@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|

Antonio Ceballos

unread,
Aug 31, 2005, 2:00:06 PM8/31/05
to
Thank you. My question was also a bit about methodology. Could you let me
see a piece of code where tcltest is used to check such procedures?

Cheers,
Antonio


"Don Porter" <d...@email.nist.gov> escribió en el mensaje
news:slrndhbo1...@clover.cam.nist.gov...

Antonio Ceballos

unread,
Aug 31, 2005, 2:00:28 PM8/31/05
to
Thanks a lot. My question was also a bit about methodology. Could you let me

see a piece of code where tcltest is used to check such procedures?

Cheers,
Antonio


"Don Porter" <d...@email.nist.gov> escribió en el mensaje
news:slrndhbo1...@clover.cam.nist.gov...

Bob Techentin

unread,
Aug 31, 2005, 4:26:48 PM8/31/05
to
"Antonio Ceballos" <ceba...@iies.es> wrote

> Thank you. My question was also a bit about methodology. Could you let me
> see a piece of code where tcltest is used to check such procedures?
>
> "Don Porter" <d...@email.nist.gov> wrote:
> > Bob Techentin wrote:
> >> Globals are easy. Tcltests run in the global scope, so setting
variables
> >> will automatically set global variables.
> >
> > No, a tcltest test is run in the scope of the caller of the
> > [::tcltest::test] command.

You are, of course, correct, Don. (All my tests run in the global scope.)

Here are two examples:

package require tcltest 2
package require Itcl

set globalvar 2

tcltest::test global-1 {test global variable} {
set ::globalvar
} {2}

itcl::class Foo {
public method bar {} {return "foobar"}
}

tcltest::test object-1 {exercise method} -setup {
Foo f1
} -body {
f1 bar
} -cleanup {
itcl::delete object f1
} -result {foobar}

tcltest::cleanupTests

Antonio Ceballos

unread,
Sep 2, 2005, 2:57:50 PM9/2/05
to
Thanks for the example, Bob. It let me start up with a working tcltest
script.

Antonio

"Bob Techentin" <techenti...@mayo.edu> escribió en el mensaje
news:df53q9$glh$1...@tribune.mayo.edu...

0 new messages