antifun has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on some new mega-widgets in Perl/Tk as part of a decent-sized application, and I'm looking for some way to automate testing these widgets.

The tools available for testing, like the Test modules, would appear to not be of much use since the Tk MainLoop effectively blocks the execution of the test script.

Programatically triggering the UI elements is not especially difficult, but you need to see if there were any die()s in the callback and check the expected result before doing the ok().

Does anyone have any strategies for dealing with this kind of testing? It really needs to be automatic, because there are a lot of cases to cover when you consider the need to validate input, check edge conditions, etc.

Thanks in advance for any suggestions.
---
"I hate it when I think myself into a corner."
Matt Mitchell

Replies are listed 'Best First'.
Re: Perl/Tk and Test?
by chromatic (Archbishop) on Mar 21, 2003 at 19:21 UTC

    Write your own MainLoop. Either replace Tk::MainLoop with a sub of your devising or prevent Tk from being loaded at all. I'd prefer the former:

    my $old = *{Tk::MainLoop}{CODE}; *Tk::MainLoop = sub { ... };
Re: Perl/Tk and Test?
by jasonk (Parson) on Mar 21, 2003 at 19:33 UTC

    Or use DoOneEvent() instead of MainLoop(), to run only one event loop at a time. An even better idea would be to look at the test suite for Tk, and see how they handled it...


    We're not surrounded, we're in a target-rich environment!
Re: Perl/Tk and Test?
by smackdab (Pilgrim) on Mar 24, 2003 at 05:25 UTC
    You can also use a $mw->repeat() function to call you a few times a second...that is what I do.

    BTW, if the widgets can be run stand alone, I would be happy to take a look at them.

    Plus you can get a lot of good feedback if you post it to comp.lang.perl.tk

Re: Perl/Tk and Test?
by Anonymous Monk on Mar 26, 2003 at 08:48 UTC
    What about "dejagnu" ? As far is a read about it, it is a gui-testing toolkit. Murat