Running tests that require an X server

Posted on 2009-4-29 (水) at 5:20 pm by Florian Ragwitz [SIGNED]

Posted in: Perl

Lots of CPAN distributions require some kind of graphical environment. Some of them even pop up windows, which not only very annoying, but also sometimes fails if you're using a tiled window manager.

To test such distributions on a machine where no graphical environment is available or on your desktop while you're working and don't want to get annoyed to death you can use a fake X server, like Xvfb.

The easiest way to do that is to run

$ xvfb-run -a make test

instead of a plain make test. That'll automatically create a fake xserver, set up DISPLAY and run make test in that environment.

That works well for manually installing modules. When installing using CPAN.pm you can make things easier by writing a distropref.

First, tell cpan where your distroprefs are. I use ~/.cpan/prefs:

$ cpan
cpan[1]> o conf init prefs_dir
[...]
<prefs_dir>
Directory where to store default options/environment/dialogs for
building modules that need some customization? [] /home/rafl/.cpan/prefs
cpan[3]> o conf commit
commit: wrote '/home/rafl/.cpan/CPAN/MyConfig.pm'

Now write a distropref for the modules that need an X server and put it into your prefs dir as X11.yml

---
match:
  distribution: |
    /(?x:Wx
      |Gtk2
      |Gnome2
      |... other modules requiring an X server
    )-\d|
test:
  commandline: "xvfb-run -a make test"

Now the tests for Wx, Gtk2, Gnome2 and all other distributions you list in that regex will be executed with a fake X server.

I have yet to figure out how to write a distropref that just prepends to the test commandline instead of replacing it so I won't need to have another pref for all modules using Module::Build.


Last modified: 2009-4-29 (水) at 5:22 pm


  • Re: Running tests that require an X server

    Written by Anonymous Coward (0) on 2009-4-30 (木) at 6:54 pm

    That's a great tip. I've added a link from the CPAN Testers wiki at Tips and Tricks

    -- dagolden

  • Re: Running tests that require an X server

    Written by Anonymous Coward (0) on 2009-5-1 (金) at 5:55 pm

    COMMENT

    This is awesome.

    LOGIN FAIL

    I tried to log in for a while, but angerwhale claims I'm not 0x9a0cda99... and I most certainly am. That login either needs better directions or smarter behaviors -- otherwise, openid is probably a better option.

    • Re: Re: Running tests that require an X server

      Written by Florian Ragwitz (742f2a428e635a5e) [SIGNED] on 2009-5-1 (金) at 11:18 pm

      The login currently uses Crypg::OpenPGP, which is rather broken. Porting to Crypt::GpgME has been discussed, but it's probably not going to happen soon. I'd love to see Angerwhale support OpenID, but I'd rather just be blogging and have anonymous comments instead of wasting a lot of time on this. Sorry. :-/

  • Re: Running tests that require an X server

    Written by Anonymous Coward (0) on 2009-5-3 (日) at 11:11 pm

    I encountered the same problem (and the same solution) a few years ago.

    I created Test::NeedsDisplay which goes some way towards automating the spawning of xvfb-run when the host has no DISPLAY.


Navigation

Categories

Tags

Login