Hi all. I'm trying to give an old Tk application some love, and I noticed it had many tests that nobody had run for many years: many of them were failing.

I fixed all of them, and to prevent the same situation in the future, I decided to run the tests in GitHub Actions. One of the tests needs the Tk application to run, so I decided to run it headless in Xvfb.

The test failed in Xvfb, not only in GH Actions, but even when I ran it locally. In a real X session, it passed.

I was able to reduce the test to the following:

#!/usr/bin/perl use strict; use warnings; use Tk; my $mw = 'Tk::MainWindow'->new; my $current = 0; my @buttons = map { my $i = $_; $mw->Button(-text => $i, -command => sub { $current = $i } )->pack } 1, 2; $mw->after(100, sub { $mw->eventGenerate('<KeyPress>', -keysym => $_) for qw( Tab Return ); $mw->idletasks(); $mw->DESTROY; }); Tk::MainLoop(); use Test::More tests => 1; is $current, 1, 'Events processed';

Steps to reproduce:

$ tktest.pl 1..1 ok 1 - Events processed $ Xvfb :19 & $ pid=$! $ DISPLAY=:19 tktest.pl 1..1 not ok 1 - Events processed # Failed test 'Events processed' # at /home/choroba/tktest.pl line 27. # got: '0' # expected: '1' # Looks like you failed 1 test of 1. $ kill $pid

Update: Under Xvnc, the behaviour is the same as under Xvfb, i.e. the events are ignored, even when I run the test from an xterm in a vnc viewer.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

In reply to Headless testing of Tk under Xvfb (Solved) by choroba

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.