| |||
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: runTests.exp |_> for test in $testlist { source $test Posted by sarmstro (sarmstro), 10 August 2005 whoops, sorry - hadn't finishedrunTests.exp |_> 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. Thanks, Scott 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 www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
| |||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |