[{"date":"2009-04-29T15:20:03Z","categories":["Perl"],"author":{"name":"Florian Ragwitz","email":"rafl@fsfe.org","keyid":"742f2a428e635a5e"},"tags":[{"perl":0},{"cpan":0}],"modified":"2009-04-29T15:22:37Z","uri":"http://perldition.org/articles/Running%20tests%20that%20require%20an%20X%20server.pod","signed":1,"summary":" Lots of CPAN distributions require some kind of graphical …","xhtml":"
Lots of CPAN distributions require some kind of graphical\nenvironment. Some of them even pop up windows, which not only very\nannoying, but also sometimes fails if you're using a tiled window\nmanager.
\nTo test such distributions on a machine where no graphical environment\nis available or on your desktop while you're working and don't want to\nget annoyed to death you can use a fake X server, like Xvfb.
\nThe easiest way to do that is to run
\n$ xvfb-run -a make test\n\n
instead of a plain make test. That'll automatically create a fake\nxserver, set up DISPLAY and run make test in that environment.
That works well for manually installing modules. When installing using\nCPAN.pm you can make things easier by writing a distropref.
First, tell cpan where your distroprefs are. I use ~/.cpan/prefs:
$ cpan\ncpan[1]> o conf init prefs_dir\n[...]\n<prefs_dir>\nDirectory where to store default options/environment/dialogs for\nbuilding modules that need some customization? [] /home/rafl/.cpan/prefs\ncpan[3]> o conf commit\ncommit: wrote '/home/rafl/.cpan/CPAN/MyConfig.pm'\n\n
Now write a distropref for the modules that need an X server and put\nit into your prefs dir as X11.yml
---\nmatch:\n distribution: |\n /(?x:Wx\n |Gtk2\n |Gnome2\n |... other modules requiring an X server\n )-\\d|\ntest:\n commandline: "xvfb-run -a make test"\n\n
Now the tests for Wx, Gtk2, Gnome2 and all other distributions you\nlist in that regex will be executed with a fake X server.
\nI have yet to figure out how to write a distropref that just prepends\nto the test commandline instead of replacing it so I won't need to\nhave another pref for all modules using Module::Build.