Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
tcltest Tk Applications
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  13 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bob Techentin  
View profile  
 More options May 26 2005, 9:59 am
Newsgroups: comp.lang.tcl
From: "Bob Techentin" <techentin.rob...@mayo.edu>
Date: Thu, 26 May 2005 08:59:51 -0500
Local: Thurs, May 26 2005 9:59 am
Subject: tcltest Tk Applications
I think I might have finally hit on a formula for testing my Tk
applications.  And I would be interested in comments on this approach.

I've used tcltest for exercising procedures and objects.  But I had
never really figured out how to use it to functionally test a whole
application.  If you [source main.tcl] in a test, it will load the
code, build the GUI and start the application.  But shutting down the
application is more difficult.  There is typically a lot of state left
in the interpreter, and if you destroy the Tk application (by wm
deleting "."), then it gets really hard to start over again.

I considered a GUI-driving test program like android or tkreplay, but
I don't necessarily want to drive the GUI widgets.  I want to exercise
the application's API, which is called by the widgets' -command
options.  Instead of "black box" testing the GUI, I want to "white
box" test the application logic, peeking and poking at the internal
state of the application.

Suddenly, it is obvious to me that the answer is to use slave
interpreters.  Each test creates a slave interpreter and uses it to
source the mainline code.  The slave loads Tk and other extensions,
builds the GUI, and initializes the application.  The test code can
then use [$slave eval] to command and probe the state of the
application.  Cleanup is done by simply deleting the slave
interpreter.

For example, for the TNT application, I can create a standard -setup
and -cleanup script like this:

  set mainProgram ../tnt.tcl

  set startTNT {
      set app [interp create]
      $app alias exit return "application called 'exit'"
      $app eval source $mainProgram
      update
  }

  set stopTNT {
      catch {interp delete $app}
  }

Now I can write tests which start the application, twiddle its
innards, and clean it up, no matter what state it is left in.

  test tnt-1.1 {run application} -body {
      # if the application started, it set this global variable
      $app eval info exists TNT_VERSION
  } -setup $startTNT -cleanup $stopTNT -result {1}

  test tnt-1.2 {normal exit, as called from File->Exit menu} -body {
      $app eval _exit
  } -setup $startTNT -cleanup $stopTNT -result {application called
'exit'}

There are some "gotchas."  My setup script should alias [exit] to
prevent the application from aborting the tests.  It must set argv0,
argv, and argc.  And I also need to be aware that the environment
array (::env) is shared between all interpreters.  But are there other
things that are going to sneak up and bite me?  Or is this a good
approach for application testing?

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
GlennH  
View profile  
 More options May 26 2005, 5:15 pm
Newsgroups: comp.lang.tcl
From: GlennH <gl...@nospam.glennh.com>
Date: Thu, 26 May 2005 22:15:18 +0100
Local: Thurs, May 26 2005 5:15 pm
Subject: Re: tcltest Tk Applications

Hi Bob,

I think the slave interpreter approach is a good one.  It stops your
test from polluting your test control environment and as you say allows
an easy gauranteed cleanup for each test.

We've been using an in house developed test exec for several years that
runs our test scripts in slave interpreters.

Glenn


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Leunissen  
View profile  
 More options May 30 2005, 4:13 am
Newsgroups: comp.lang.tcl
From: Erik Leunissen <l...@the.footer.invalid>
Date: Mon, 30 May 2005 10:13:45 +0200
Local: Mon, May 30 2005 4:13 am
Subject: Re: tcltest Tk Applications

Bob Techentin wrote:
> But are there other
> things that are going to sneak up and bite me?  Or is this a good
> approach for application testing?

I also once used the setup that you describe, using a slave interp. In
such a setup, tests that check stdout and stderr appear not to don't
work; tests that use -output and -errorOuput fail.

I tried to cure this by loading tcltest also into the slave interp, but
to no avail. Appended you find a small script that exercises the failure.

Greetings,

Erik Leunissen
==============

package require tcltest 2.2
namespace import -force tcltest::*
tcltest::configure -verbose {body pass error}

set setupScript {
        interp create slave
        # This did not help:
        # slave eval [list package require tcltest 2.2]

}

set cleanupScript {
        interp delete slave

}

test errorOutput-1.1 {writes to stderr from main interp} -body {
        puts stderr "Do you read stderr (master)?"
} -errorOutput "Do you read stderr (master)?\n" \

                -result ""

test errorOutput-1.2 {writes to stderr from slave interp} -body {
        slave eval [list puts stderr "Do you read stderr (slave)?"]

} -errorOutput "Do you read stderr (slave)?\n" \

                -result "" -setup $setupScript -cleanup $cleanupScript

--
   leunissen@       nl | Merge the left part of these two lines into one,
e.          hccnet.   | respecting a character's position in a line.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Leunissen  
View profile  
 More options May 30 2005, 7:11 am
Newsgroups: comp.lang.tcl
From: Erik Leunissen <l...@the.footer.invalid>
Date: Mon, 30 May 2005 13:11:56 +0200
Local: Mon, May 30 2005 7:11 am
Subject: Re: tcltest Tk Applications
I just found a fix for the problem that I addressed in the previous
posting. See the code inside "setupScript" in the test script below.

Greetings,

Erik Leunissen
==============

package require tcltest 2.2
namespace import -force tcltest::*
tcltest::configure -verbose {body pass error}

set setupScript {
        interp create slave
        # But this does help:
        slave alias puts puts; # <------- FIX

}

set cleanupScript {
        interp delete slave

}

test errorOutput-1.1 {writes to stderr from main interp} -body {
        puts stderr "Do you read stderr (master)?"
} -errorOutput "Do you read stderr (master)?\n" \

                -result ""

test errorOutput-1.2 {writes to stderr from slave interp} -body {
        slave eval [list puts stderr "Do you read stderr (slave)?"]

} -errorOutput "Do you read stderr (slave)?\n" \

                -result "" -setup $setupScript -cleanup $cleanupScript

--
   leunissen@       nl | Merge the left part of these two lines into one,
e.          hccnet.   | respecting a character's position in a line.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Leunissen  
View profile  
 More options May 30 2005, 9:10 am
Newsgroups: comp.lang.tcl
From: Erik Leunissen <l...@the.footer.invalid>
Date: Mon, 30 May 2005 15:10:19 +0200
Local: Mon, May 30 2005 9:10 am
Subject: Re: tcltest Tk Applications

Erik Leunissen wrote:
> I just found a fix for the problem that I addressed in the previous
> posting. See the code inside "setupScript" in the test script below.

But all access to files other than stdout, stderr and stdin will remain
a very big

                      PITA

The following example test "writeToFile" will cause an error because the
call to puts in [writeToFile] requires the channel $fd to exist. While
that is the case in a normal execution environment, it is not in a slave
interpreter unless you make it explicitly available using [interp
transfer]. Since the [puts] immediately follows the opening of the file,
there is no way to do that in a timely fashion when you're writing the
test script. You could of course insert it into the proc to take into
account that in the future it may be executed in a test environment that
uses slave interpreters, but ... good heavens, NO.

Are there any people who see a workable solution here?

Or should we conclude that the best thing is not to use slave
interpreters when the code that you want to test accesses files other
than the standard ones?

set proc writeToFile {txt} {
     set fd [open ./testFile w]
     puts $fd $txt
     close $fd

}

set setupScript {
     interp create slave
     slave alias puts puts
}

set cleanupScript {
     interp delete slave

}

test writeToFile {exercises a file access error} \
     -setup $setupScript -body {
        slave eval writeToFile tralala

} -result "" -returnCodes ok -cleanup $cleanupScript

--
   leunissen@       nl | Merge the left part of these two lines into one,
e.          hccnet.   | respecting a character's position in a line.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Leunissen  
View profile  
 More options May 30 2005, 9:17 am
Newsgroups: comp.lang.tcl
From: Erik Leunissen <l...@the.footer.invalid>
Date: Mon, 30 May 2005 15:17:03 +0200
Local: Mon, May 30 2005 9:17 am
Subject: Re: tcltest Tk Applications

GlennH wrote:

> We've been using an in house developed test exec for several years that
> runs our test scripts in slave interpreters.

Did your code access files other than stdout, stderr, stdin ?
If so, how did you solve issues regarding non-accessible channels in
slave interpreters (please see my other postings in this thread today)?

Thanks in advance for sharing your experience,

Erik Leunissen
--
   leunissen@       nl | Merge the left part of these two lines into one,
e.          hccnet.   | respecting a character's position in a line.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Leunissen  
View profile  
 More options May 30 2005, 10:13 am
Newsgroups: comp.lang.tcl
From: Erik Leunissen <l...@the.footer.invalid>
Date: Mon, 30 May 2005 16:13:36 +0200
Local: Mon, May 30 2005 10:13 am
Subject: Re: tcltest Tk Applications

Erik Leunissen wrote:

> While
> that is the case in a normal execution environment, it is not in a slave
> interpreter unless you make it explicitly available using [interp
> transfer].

Correction:

In general, channels are accessible in slave interps. But apparently it
is not in my case.

Erik Leunissen.
--
   leunissen@       nl | Merge the left part of these two lines into one,
e.          hccnet.   | respecting a character's position in a line.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Techentin  
View profile  
 More options May 31 2005, 11:41 am
Newsgroups: comp.lang.tcl
From: "Bob Techentin" <techentin.rob...@mayo.edu>
Date: Tue, 31 May 2005 10:41:35 -0500
Local: Tues, May 31 2005 11:41 am
Subject: Re: tcltest Tk Applications
"Erik Leunissen" <l...@the.footer.invalid> wrote

> > I just found a fix for the problem that I addressed in the
previous
> > posting. See the code inside "setupScript" in the test script
below.

> But all access to files other than stdout, stderr and stdin will
remain
> a very big ... PITA

Thanks, Erik, for the caution and workaround on standard channels and
slave interps.  That's one issue I hadn't considered, but could be
included in the strategy.

But I don't see that as a serious problem for many file I/O tests.
The example you provide (proc writeToFile) could be handled with
regular tcltests, without the use of slave interps.  My proposed use
of slave interps was to facilitate full Tk applications.  Stdin/stdout
could be a significant issue.  But most file I/O shouldn't be a
problem, because all the code will be run by the slave.  (It won't
have to straddle interpreters.)

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Techentin  
View profile  
 More options Jun 1 2005, 11:12 am
Newsgroups: comp.lang.tcl
From: "Bob Techentin" <techentin.rob...@mayo.edu>
Date: Wed, 1 Jun 2005 10:12:13 -0500
Local: Wed, Jun 1 2005 11:12 am
Subject: Re: tcltest Tk Applications
Erik Leunissen" <l...@the.footer.invalid> wrote

> In general, channels are accessible in slave interps. But
> apparently it is not in my case.

I've taken a look at the tcltest code, and I see that tcltest defines
tcltest::Replace::puts which buffers stdout and stderr so that the
test suite can capture -output and -errorOutput.  So the slave interp
test setup script would need to do something similar:  define a new
puts command which would redirect all stdout/stderr output to the
master interp (probably via an alias), and use the default puts
command for everything else.

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Leunissen  
View profile  
 More options Jun 1 2005, 12:37 pm
Newsgroups: comp.lang.tcl
From: Erik Leunissen <l...@the.footer.invalid>
Date: Wed, 01 Jun 2005 18:37:17 +0200
Local: Wed, Jun 1 2005 12:37 pm
Subject: Re: tcltest Tk Applications

Bob Techentin wrote:

   So the slave interp

> test setup script would need to do something similar:  define a new
> puts command which would redirect all stdout/stderr output to the
> master interp (probably via an alias), and use the default puts
> command for everything else.

Bob,

Did you see the fix that I suggested in an earlier posting in this
thread?  (look for "<----- FIX")

That fix does what you propose here.

In the meantime, I resolved the issues with non-standard files too and
fixed a problem that had been created when defining the alias for puts.

In case you're interested: I've attached the complete setup for using
slave interps with tcltest to this message. It contains a self test also.

Greetings,

Erik Leunissen
--
   leunissen@       nl | Merge the left part of these two lines into one,
e.          hccnet.   | respecting a character's position in a line.

  slavetest.tcl
1K Download

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Leunissen  
View profile  
 More options Jun 1 2005, 12:41 pm
Newsgroups: comp.lang.tcl
From: Erik Leunissen <l...@the.footer.invalid>
Date: Wed, 01 Jun 2005 18:41:27 +0200
Local: Wed, Jun 1 2005 12:41 pm
Subject: Re: tcltest Tk Applications

Bob Techentin wrote:

   So the slave interp

> test setup script would need to do something similar:  define a new
> puts command which would redirect all stdout/stderr output to the
> master interp (probably via an alias), and use the default puts
> command for everything else.

Bob,

Did you see the fix that I suggested in an earlier posting in this
thread?  (look for "<----- FIX")

That fix does what you propose here.

In the meantime, I resolved the issues with non-standard files too and
fixed a problem that had been created when defining the alias for puts.

In case you're interested: I've attached the complete setup for using
slave interps with tcltest to this message. It contains a self test also.

Greetings,

Erik Leunissen
--
   leunissen@       nl | Merge the left part of these two lines into one,
e.          hccnet.   | respecting a character's position in a line.

  slavetest.tcl
1K Download

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Leunissen  
View profile  
 More options Jun 1 2005, 12:45 pm
Newsgroups: comp.lang.tcl
From: Erik Leunissen <l...@the.footer.invalid>
Date: Wed, 01 Jun 2005 18:45:38 +0200
Local: Wed, Jun 1 2005 12:45 pm
Subject: Re: tcltest Tk Applications

Bob Techentin wrote:

   So the slave interp

> test setup script would need to do something similar:  define a new
> puts command which would redirect all stdout/stderr output to the
> master interp (probably via an alias), and use the default puts
> command for everything else.

> Bob

Bob,

Did you see the code that I suggested in an earlier posting in this
thread?  (look for "slave alias puts puts")

That line does what you propose here.

In the meantime, I resolved the issues with non-standard files too and
fixed a problem that had been created when defining the alias for puts.

In case you're interested: I've attached the complete setup for using
slave interps with tcltest to this message. It contains a self test also.

Greetings,

Erik Leunissen

--
   leunissen@       nl | Merge the left part of these two lines into one,
e.          hccnet.   | respecting a character's position in a line.

  slavetest.tcl
1K Download

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Techentin  
View profile  
 More options Jun 1 2005, 4:54 pm
Newsgroups: comp.lang.tcl
From: "Bob Techentin" <techentin.rob...@mayo.edu>
Date: Wed, 1 Jun 2005 15:54:37 -0500
Local: Wed, Jun 1 2005 4:54 pm
Subject: Re: tcltest Tk Applications
"Erik Leunissen" <l...@the.footer.invalid> wrote

> Did you see the code that I suggested in an earlier posting
> in this thread?  (look for "slave alias puts puts")

Yes, I saw your earlier alias of puts.  I was suggesting something
just a little more complex.  The slave puts would check for stderr and
stdout, and direct those to the master interp, where tcltest could
capture and buffer the output.  All other puts commands would get
routed through the slave interp's default puts.

But your code that opens and shares between master and slave should
also work.  (And its clever, too.)

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google