Test::File::Cmp - Test routine for file comparison independent of CRLF or LF line endings.
Version 0.05
use Test::File::Cmp qw(file_is); # ... file_is(got_file, $expected_file); # ...
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.
encoding
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)
file_is(GOT, EXPECTED)
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.
GOT
EXPECTED
n
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".
TEST_NAME
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.
perldoc Test::File::Cmp
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
https://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-File-Cmp
Search CPAN
https://metacpan.org/release/Test-File-Cmp
GitHub Repository
https://github.com/AAHAZRED/perl-Test-File-Cmp.git
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.
cpanm
cpanm Test::File::Cmp
CPAN shell
perl -MCPAN -e shell install Test::File::Cmp
For more information on module installation, please visit the detailed CPAN module installation guide.