Tests should not fail due to EOL differences across platforms

So, I now had a chance to go back, and look at another one of the modules that failed to build during a cpan-outdated | cpanm -v session on my Windows 8 laptop.

Here is why Module::Install failed to build:

#   Failed test 'has author'
#   at t\18_all_from.t line 33.


#   Failed test 'has one author'
#   at t\20_authors_with_special_characters.t line 51.
# String: #     AUTHOR => [q[First 'Middle' Last ]]

#   Failed test at t\20_authors_with_special_characters.t line 58.
#     Structures begin differing at:
#          $got->[0] = 'First 'Middle' Last
#     $expected->[0] = 'First 'Middle' Last'

#   Failed test at t\20_authors_with_special_characters.t line 103.
#     Structures begin differing at:
#          $got->[0] = 'Olivier Mengu?
#     $expected->[0] = 'Olivier Mengu\xE9'

Let’s first look at the first failure, line 33 in t\18_all_from.t.

my $file = makefile();
ok(-f $file);
my $content = _read($file);
ok($content, 'file is not empty');
ok($content =~ /#\s*ABSTRACT => q\[A test module\]/, 'has abstract');
ok($content =~ author_makefile_re("Foo Bar"), 'has author');
ok($content =~ /#\s*VERSION => q\[3\.21\]/, 'has version');

Both author_makefile_re and _read are from t/lib/Test.pm.

_read is just a straightforward slurp.

I have EUMM 7.02, so author_makefile_re("Foo Bar") just returns qr/#\s*AUTHOR => \[q\[Foo Bar\]\]/;.

Guess what the generated Makefile contains:

#     AUTHOR => [q[Foo Bar

If you missed the carriage return, Vim will happily show you:

I believe this is related to commit cfabc28, and it may also explain the subsequent test failures. From the Changes file:

6.99_08 Mon Aug 18 14:17:04 BST 2014
Bug fixes:
- Generated META.files will now always have linefeed EOLs, even on

Mind you, that does not mean I think this is a bug in EUMM.

It is just that Module::Install includes a support module in t/lib/Test.pm which opens files, and prints them without taking any precautions (as opposed to, say Parse::CPAN::Meta). That’s where the CR comes from when the rest of the tools use LF only.

Fixing that makes all tests in t\18_all_from.t pass. I will look at the rest later, and probably put together a patch, unless someone beats me to it ;-)

PS: See my pull request.