NAME
Test::File::Cmp - Test routine for file comparison independent of CRLF or LF line endings.
VERSION
Version 0.05
SYNOPSIS
use Test::File::Cmp qw(file_is);
# ...
file_is(got_file, $expected_file);
# ...
DESCRIPTION
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.
Subroutines
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
andEXPECTED
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 linen
" 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 fileGOT
withEXPECTED
".
AUTHOR
Abdul al Hazred, <451 at gmx.eu>
BUGS
Currently there are no known bugs.
SUPPORT
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)
Search CPAN
GitHub Repository
LICENSE AND COPYRIGHT
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.