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

Update: solved, ++Athanasius

Hello learned friends,

I have a module that outputs encoded data. I am testing the output. The tests pass on newer Perl versions, but fail on some old ones. I cannot spot the reason, since the test output appears to be the same, when reported as different. Can anyone please help me spot the issue?

Test code:


use strict; use warnings;
use Test::More; use Test::More::UTF8;
use Encode;
use Capture::Tiny 'capture_stderr';
use FindBin '$RealBin';

my $expected = q!{
  'i中文' => '也許你的生活很有趣',
  'Ελληνικά' => 'ἓν οἶδα ὅτι οὐδὲν οἶδα',
  'русский' => 'доверяй, но проверяй',
}
!;

subtest 'imported via class function' => sub {
    my $dump = capture_stderr(sub {
        qx{perl $RealBin/import-via-class-function.pl}
    });

    is( decode_utf8($dump), $expected, 'output ok' );
};

done_testing;
__END__

Output:


    #   Failed test 'output ok'
    #   at t/import-via-class-function.t line 21.
    #          got: '{
    #   'i中文' => '也許你的生活很有趣',
    #   'Ελληνικά' => 'ἓν οἶδα ὅτι οὐδὲν οἶδα',
    #   'русский' => 'доверяй, но проверяй'
    # }
    # '
    #     expected: '{
    #   'i中文' => '也許你的生活很有趣',
    #   'Ελληνικά' => 'ἓν οἶδα ὅτι οὐδὲν οἶδα',
    #   'русский' => 'доверяй, но проверяй',
    # }
    # '

Thank you for any assistance!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re: Test output diff ?
by Athanasius (Archbishop) on Apr 14, 2020 at 15:11 UTC

    Hello 1nickt,

    The only difference I can see between the “got” and the “expected” is that the former is missing a comma at the end of the third line.

    (If that doesn’t solve the problem, you will need to show the contents of import-via-class-function.pl.)

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Gosh, could it be that? Thank you for looking! I'm on a work computer now so cannot check, but I *think* that is a pasting typo.

      ... hm I will *have* to check, back in a bit :-)

      Thank you!


      Bless you a thousand time, brother Athanasius!

      I just could not see the lack of the trailing comma; my eyes had been looking at the (correct) test output for hours. Once you pointed it out (geez, I should have diffed :-/), I quickly figured it out.

      From the Data::Dumper Changes file:

      2.160 (Jul 3 2016)
      ...
          Add Trailingcomma option. This is as suggested in RT#126813.
      

      So I updated my Makefile to specify the Data::Dumper minimum version, and all tests pass on old perls.

      Thanks again!


      The way forward always starts with a minimal test.