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

Fellow Monks, Generally I use Test; to test my libraries..I now want to use it to test a Gtk2 perl app I've written. I want to do things like select a bunch of items in a SimpleList and hit a button, this objects are global variables in my main program, call it foo.pl..whats the best, cleanest way to launch my program from within foo.t test and interact with it..I'd like to keep readability of the test at a maximum, at the cost of efficency of the test it's self if I must.

Thank you in advance,

daN.

Replies are listed 'Best First'.
Re: Including a Gtk2 app in a Test
by kvale (Monsignor) on Apr 26, 2004 at 17:48 UTC
    I would start by using some the test machinery in the Gtk2 module itself. For instance Gtk2::Test::Helper sets up a nice test environment for Gtk2 method calls. Also look at the tests used in proofing the Gtk2 module. They will give you hints regarding the exercising of your GUI.

    -Mark

      The actual Gtk2 code to load the window and run the main loop is in the body of my foo.pl ie not encapsulated in a function..All the examples I have seen show windows and what not being created in function calls in libraries so you can use the library and call the methode to build the window. Since I can't use a non-library ie my main perl program, and even if I could can't execute the body of said program which draws the interface, I can't figure out how to use any of the Gtk2::Test::Helper stuff to help me..


      daN.
        You can probably rewrite foo.pl like this:

        sub foo { # original foo.pl code here return "all right"; } foo() unless defined caller(); # call foo() unless require'd

        And then in your tests do something like

        # Test::More style used.... use Test::More tests => 1; require "foo.pl"; is(foo(),"all right","Foo() executed normally")
        Update: You'll probably not want everything in the foo() function, just the stuff that's needed to set up the gui.

        For instance, the run loop will probably be set up by the test module (but I'm only guessing, I've never used the Gtk test modules).

        Update 2:: Actually, most of the above is wrong. It will give you some hints on how to solve your problem, though. I'm going to eat something now.

        Joost.

Re: Including a Gtk2 app in a Test
by Fletch (Bishop) on Apr 26, 2004 at 17:49 UTC

    Look at what Mac::Carbon does for its gui tests. And check if $ENV{DISPLAY} is set and skip the tests if it's not.