Test::File::Cmp - Test routine for file comparison independent of CRLF or LF line endings.
use Test::File::Cmp qw(file_is);
For testing files and their contents, Test::File::Contents is a good choice. But I missed one feature: what if you need to run tests on both systems, Windows and Linux, and the "expected" files might be created on one or the other system and you don't know that in advance? Then there are ugly problems with line endings when comparing the contents of two files, and the encoding argument does not really resolve this.
For this situation I have created a file comparison function provided by this module, description see below.
This module exports a single function on demand.
file_is(GOT, EXPECTED, TEST_NAME)
This function compares the contents of GOT and EXPECTED line by line, but replaces each CRLF line ending with LF before the comparison. If the number of lines differ, then the diagnostic "Different number of lines" is printed and the test fails without any further comparison. Otherwise, the files are compared line by line. If a difference is found, then the dignostic "Files differ at line n" is printed and the test fails.
The test is only successful if there is no difference.
The optional argument TEST_NAME specifies the test name. Default is "compare file GOT with EXPECTED".
Abdul al Hazred, <451 at gmx.eu>
<451 at gmx.eu>
Currently there are no known bugs.
You can find documentation for this module with the perldoc command.
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
This software is copyright (c) 2022 by Abdul al Hazred.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Test::Builder, Test::File::Contents, Test::More
To install Test::File::Cmp, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.