Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems
returning to a specific upper lever

Posted by sarmstro (sarmstro), 10 August 2005
I'm writing a test automation framework in Expectk and I need help with a feature.

First, I'll explain the structure: a script called runTests.exp (called when a button in the Tk GUI is pressed) runs each test script in a list in turn and writes the result of the test in a database. In each test script there are calls to a testStep() function which reports test step passes or fails. I'd like to include a FATAL fail where the test script will then call a few lines of cleanup code (which may be different for each test script) and then return to the runTests.exp script which will run the next test script in the for loop.

So, it looks like this:
|_> for test in $testlist {
                source $test

Posted by sarmstro (sarmstro), 10 August 2005
whoops, sorry - hadn't finished

|_> for test in $testlist {
      source $test
                |-> testStep FATAL
                             |-> cleanup()
                                   continue in for loop

It is the "continue in for loop" part that's catching me - how can I return to a specified level a few levels up.

Any help will be much appreciated.


Posted by admin (Graham Ellis), 11 August 2005
I've looked at this a couple of times ... not totally convinced I'm following the question but ...

If you want to exit from several nested loops, or from nested procs, the best way is to use a flag variable and exit the levels one by one; yes, the coding isn't very short.

If the mechanism is in use throughout your program, then you might prefer to consider a global variable that you check after each return.

Finally, have a look at the uplevel and upvar commands that let you reference variables and run commands one level up ... and you CAN tell them to work multiple levels up.   Do this latter with care as it can lead to code that's obscure and very hard to maintain.

Posted by sarmstro (sarmstro), 18 October 2005
Revisiting this problem - if I use catch can i throw an error in the result of a FATAL fail and deal with it using catch {source <single test>...  ?

Posted by admin (Graham Ellis), 18 October 2005
Usually, yes.   You can't if the error is a syntax error such as incorrectly matched { and } within the catch.

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho