choroba has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Headless testing of Tk under Xvfb (Solved)
by choroba (Cardinal) on Feb 19, 2025 at 15:50 UTC | |
by cavac (Prior) on Feb 20, 2025 at 14:34 UTC |