[{"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":"
\n

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.

\n

To 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.

\n

The 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.

\n

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

\n

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

\n
$ 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

\n
---\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.

\n

I 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.

\n\n\n
","text":" Lots of CPAN distributions require some kind of graphical envi-\n ronment. Some of them even pop up windows, which not only very\n annoying, but also sometimes fails if you're using a tiled win-\n dow manager.\n\n To test such distributions on a machine where no graphical environ-\n ment is available or on your desktop while you're working and don't\n want to get annoyed to death you can use a fake X server, like Xvfb.\n\n The easiest way to do that is to run\n\n lang:Bash $ xvfb-run -a make test\n\n instead of a plain make test. That'll automatically create a fake\n xserver, set up DISPLAY and run make test in that environment.\n\n That works well for manually installing modules. When installing us-\n ing CPAN.pm you can make things easier by writing a distropref.\n\n First, tell cpan where your distroprefs are. I use ~/.cpan/prefs:\n\n lang:Bash $ cpan cpan[1]> o conf init prefs_dir [...] \n Directory where to store default options/environment/dialogs for\n building modules that need some customization? [] /home/rafl/.c-\n pan/prefs cpan[3]> o conf commit commit: wrote '/home/rafl/.c-\n pan/CPAN/MyConfig.pm'\n\n Now write a distropref for the modules that need an X server and put\n it into your prefs dir as X11.yml\n\n ---\n match: distribution: | /(?x:Wx |Gtk2 |Gnome2\n |... other modules requiring an X server\n )-\\d| test: commandline: \"xvfb-run -a make test\"\n\n Now the tests for Wx, Gtk2, Gnome2 and all other distributions you\n list in that regex will be executed with a fake X server.\n\n I have yet to figure out how to write a distropref that just\n prepends to the test commandline instead of replacing it so I won't\n need to have another pref for all modules using Module::Build.\n","title":"Running tests that require an X server","type":"pod","guid":"13d6b55d-2935-43fe-a0fd-bfba692b06a0","raw":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\n=pod\n\nLots 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.\n\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.\n\nThe easiest way to do that is to run\n\n lang:Bash\n $ xvfb-run -a make test\n\ninstead of a plain C. That'll automatically create a fake\nxserver, set up C and run C in that environment.\n\nThat works well for manually installing modules. When installing using\nC you can make things easier by writing a distropref.\n\nFirst, tell cpan where your distroprefs are. I use C<~/.cpan/prefs>:\n\n lang:Bash\n $ cpan\n cpan[1]> o conf init prefs_dir\n [...]\n \n Directory where to store default options/environment/dialogs for\n building modules that need some customization? [] /home/rafl/.cpan/prefs\n cpan[3]> o conf commit\n commit: wrote '/home/rafl/.cpan/CPAN/MyConfig.pm'\n\nNow write a distropref for the modules that need an X server and put\nit into your prefs dir as C\n\n ---\n match:\n distribution: |\n /(?x:Wx\n |Gtk2\n |Gnome2\n |... other modules requiring an X server\n )-\\d|\n test:\n commandline: \"xvfb-run -a make test\"\n\nNow the tests for Wx, Gtk2, Gnome2 and all other distributions you\nlist in that regex will be executed with a fake X server.\n\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 C.\n\n=cut\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.6 (GNU/Linux)\n\niD8DBQFJ+HC9dC8qQo5jWl4RAl7JAJ4y9ubdkzkHw1fiH0gZYeKZG1Xm2wCfWY/P\nXj+fmSrSkoESejt0Cpykoms=\n=FtHr\n-----END PGP SIGNATURE-----\n"}]