choroba has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
I'm trying to install Tk from CPAN. Sometimes, everything goes just OK, but sometimes, a test fails:
Test Summary Report ------------------- t/text.t (Wstat: 0 Tests: 415 Failed: 0) TODO passed: 121 Files=1, Tests=415, 2 wallclock secs ( 0.20 usr 0.02 sys + 0.98 cus +r 0.05 csys = 1.25 CPU) Result: PASS t/text.t .. 289/415 Stack moved 887d7ec => 887d7f0 t/text.t .. ok All tests successful.
versus
Test Summary Report ------------------- t/text.t (Wstat: 0 Tests: 415 Failed: 0) TODO passed: 121 Files=1, Tests=415, 2 wallclock secs ( 0.22 usr 0.01 sys + 0.94 cus +r 0.05 csys = 1.22 CPU) Result: PASS t/text.t .. 247/415 # Failed test at t/text.t line 1548. # '' # doesn't match '(?-xism:PRIMARY\ selection\ doesn\'t\ exist\ or\ +form\ \"STRING\"\ not\ defined)' Stack moved 887d934 => 887d938 t/text.t .. 403/415 # Looks like you failed 1 test of 415. t/text.t .. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/415 subtests (less 32 skipped subtests: 382 okay) (1 TODO test unexpectedly succeeded)
The sometimes failing test is this one:
{ $t2->destroy if Tk::Exists($t2); $t2 = $mw->Text; $t2->insert('1.0', "abcdef\nghijk\n1234"); $t2->tagAdd('sel', '1.0', '1.3'); is($mw->SelectionGet, 'abc'); $mw->SelectionClear; # * eval { $mw->SelectionGet }; like($@, qr{\QPRIMARY selection doesn't exist or form "STRING" not + defined}); $t2->tagAdd('sel', '1.0', '1.3'); is($mw->SelectionGet, 'abc'); }
If I add a sleep 1; before the eval line (marked with *), the test passes everytimes. The question is: is this a bug? Or just a poorly written test? Or...?
Running perl 5.12.1, openSUSE 11.3 with KDE 4.4.4.

Replies are listed 'Best First'.
Re: Tk: Cannot install from CPAN sometimes.
by zentara (Cardinal) on Oct 28, 2010 at 17:16 UTC
    It could be a bug, but Perl/Tk has had a bad habit for failing the tests done after installation, even though the installations work Ok.

    Have you tried to run the example scripts, or the program called widget. If "widget" runs, and you try the various demos in it, and they perform, then you are Ok.

    I urge you to download the latest Tk tarball from CPAN, and manually build it..... you will see quite a few errors go by in the self-test, but the Tk install works as advertised.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      It is exactly what I did. Sometimes, the tests are OK and installation is possible, sometimes it is not. I tried running just the single test for many times, without the sleep, it just randomly fails.
      For example: Or, shorter:
      root@weed# for a in {1..25} ; do /usr/bin/perl "-It" "-MTkTest" "-MExt +Utils::Command::MM" "-e" "check_display_harness; test_harness(0, 'bli +b/lib', 'blib/arch')" t/text.t ; done 2>/dev/null | grep Result: | s +ort | uniq -c 22 Result: FAIL 3 Result: PASS
        It must be some peculiarity of your system. Instead of your odd test command:
        root@weed# for a in {1..25} ; do /usr/bin/perl "-It" "-MTkTest" "-MExt +Utils::Command::MM" "-e" "check_display_harness; test_harness(0, 'bli +b/lib', 'blib/arch')" t/text.t ; done 2>/dev/null | grep Result: | s +ort | uniq -c
        Can you do this:

        unpack the tarball, perl Makefile.PL, make, make test, make install (as root)?


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh
Re: Tk: Cannot install from CPAN sometimes.
by thundergnat (Deacon) on Oct 29, 2010 at 15:32 UTC

    My suspicion is that you are running into erratic timing issues in the Tk event loop. I'd bet that sticking a $mw->update; in where you were putting the sleep command would also mitigate the problem. That would force the event loop to empty the queued task buffer and ensure it actually performs the task before it checks that the task results are correct.

    If that turns out to be the case, it is probably worth submitting a bug report. Slaven has been pretty responsive about fixing problems in the past, especially if you include a patch.

      Yes, I tried that later, too. It solved the problem as you guessed.
      Update: I'll try to file the bugreport.