--- 
author: 
  email: rafl@fsfe.org
  keyid: 742f2a428e635a5e
  name: Florian Ragwitz
categories: 
  - Perl
date: 2009-04-29T15:20:03Z
guid: 13d6b55d-2935-43fe-a0fd-bfba692b06a0
modified: 2009-04-29T15:22:37Z
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<make test>. That'll automatically create a fake\nxserver, set up C<DISPLAY> and run C<make test> in that environment.\n\nThat works well for manually installing modules. When installing using\nC<CPAN.pm> 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  <prefs_dir>\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<X11.yml>\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<Module::Build>.\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"
signed: 1
summary: " Lots of CPAN distributions require some kind of graphical …"
tags: 
  - 
    perl: 0
  - 
    cpan: 0
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 [...] <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
uri: http://perldition.org/articles/Running%20tests%20that%20require%20an%20X%20server.pod
xhtml: "<div class=\"pod\">\n<p>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.</p>\n<p>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.</p>\n<p>The easiest way to do that is to run</p>\n<pre><span class=\"Normal\">$ xvfb-run -a </span><span class=\"BString\">make</span><span class=\"Normal\"> </span><span class=\"Reserved\">test</span>\n</pre>\n<p>instead of a plain <code>make test</code>. That'll automatically create a fake\nxserver, set up <code>DISPLAY</code> and run <code>make test</code> in that environment.</p>\n<p>That works well for manually installing modules. When installing using\n<code>CPAN.pm</code> you can make things easier by writing a distropref.</p>\n<p>First, tell cpan where your distroprefs are. I use <code>~/.cpan/prefs</code>:</p>\n<pre><span class=\"Normal\">$ cpan</span><span class=\"Normal\">\n</span><span class=\"Normal\">cpan[1]</span><span class=\"Operator\">&gt;</span><span class=\"Normal\"> o conf init prefs_dir</span><span class=\"Normal\">\n</span><span class=\"Normal\">[...]</span><span class=\"Normal\">\n</span><span class=\"Operator\">&lt;</span><span class=\"Normal\">prefs_dir</span><span class=\"Operator\">&gt;</span><span class=\"Normal\">\n</span><span class=\"Normal\">Directory where to store default options/environment/dialogs </span><span class=\"Keyword\">for</span><span class=\"Normal\">\n</span><span class=\"Normal\">building modules that need some customization? [] /home/rafl/.cpan/prefs</span><span class=\"Normal\">\n</span><span class=\"Normal\">cpan[3]</span><span class=\"Operator\">&gt;</span><span class=\"Normal\"> o conf commit</span><span class=\"Normal\">\n</span><span class=\"Normal\">commit: wrote </span><span class=\"String\">&apos;/home/rafl/.cpan/CPAN/MyConfig.pm&apos;</span>\n</pre>\n<p>Now write a distropref for the modules that need an X server and put\nit into your prefs dir as <code>X11.yml</code></p>\n<pre><span class=\"Normal\">---</span><span class=\"Normal\">\n</span><span class=\"Normal\">match:</span><span class=\"Normal\">\n</span><span class=\"Normal\">  distribution: </span><span class=\"Keyword\">|</span><span class=\"Normal\">\n</span><span class=\"Normal\">    /</span><span class=\"Keyword\">(</span><span class=\"Normal\">?x:Wx</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Keyword\">|</span><span class=\"Normal\">Gtk2</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Keyword\">|</span><span class=\"Normal\">Gnome2</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Keyword\">|</span><span class=\"Normal\">..</span><span class=\"Keyword\">.</span><span class=\"Normal\"> other modules requiring an X server</span><span class=\"Normal\">\n</span><span class=\"Normal\">    </span><span class=\"Keyword\">)</span><span class=\"Normal\">-\\d</span><span class=\"Keyword\">|</span><span class=\"Normal\">\n</span><span class=\"Normal\">test:</span><span class=\"Normal\">\n</span><span class=\"Normal\">  commandline: </span><span class=\"String\">&quot;xvfb-run -a make test&quot;</span>\n</pre>\n<p>Now the tests for Wx, Gtk2, Gnome2 and all other distributions you\nlist in that regex will be executed with a fake X server.</p>\n<p>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 <code>Module::Build</code>.</p>\n\n\n</div>"
