Mohammad S Anwar > Test-Excel > Test::Excel

Download:
Test-Excel-1.37.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 1.37   Source  

NAME ^

Test::Excel - Interface to test and compare Excel files.

VERSION ^

Version 1.37

DESCRIPTION ^

This module is meant to be used for testing custom generated Excel files, it provides interfaces to compare_excel two Excel files if they are visually same.

SYNOPSIS ^

Using as unit test as below:

    use strict; use warnings;
    use Test::More tests => 2;
    use Test::Excel;

    cmp_excel_ok("1.xls", "1.xls");

    cmp_excel_not_ok("1.xls", "2.xls");

    done_testing();

Using as standalone as below:

    use strict; use warnings;
    use Test::Excel;

    if (compare_excel("1.xls", "1.xls")) {
        print "Excels are similar.\n";
    }
    else {
        print "Excels aren't similar.\n";
    }

METHODS ^

cmp_excel($got, $exp, \%rule, $message)

This function will tell you whether the two Excel files are "visually" different, ignoring differences in embedded fonts/images and metadata. Both $got and $exp can be either instances of Spreadsheet::ParseExcel / file path (which is in turn passed to the Spreadsheet::ParseExcel constructor). This one is for use in TEST MODE.

    use strict; use warnings;
    use Test::More tests => 1;
    use Test::Excel;

    cmp_excel('foo.xls', 'bar.xls', {}, 'EXCELs are identical.');

    done_testing();

cmp_excel_ok($got, $exp, \%rule, $message)

Test OK if excel files are identical. Same as cmp_excel().

cmp_excel_not_ok($got, $exp, \%rule, $message)

Test OK if excel files are NOT identical.

compare_excel($got, $exp, \%rule)

This function will tell you whether the two Excel files are "visually" different, ignoring differences in embedded fonts/images and metadata. Both $got and $exp can be either instances of Spreadsheet::ParseExcel / file path (which in turn passed to the Spreadsheet::ParseExcel constructor).

    use strict; use warnings;
    use Test::Excel;

    print "EXCELs are identical.\n" if compare_excel("foo.xls", "bar.xls");

RULE ^

The paramter rule can be used optionally to apply exception when comparing the contents. This should be passed in as has ref and may contain keys from the table below.

    +-----------------+---------------------------------------------------------+
    | Key             | Description                                             |
    +-----------------+---------------------------------------------------------+
    | sheet           | "|" seperated sheet names.                              |
    | tolerance       | Number. Apply to all NUMBERS except on 'sheet'/'spec'.  |
    |                 | e.g. 10**-12                                            |
    | sheet_tolerance | Number. Apply to sheets/ranges in the spec. e.g. 0.20   |
    | spec            | Path to the specification file.                         |
    | swap_check      | Number (optional) (1 or 0). Row swapping check.         |
    |                 | Default is 0.                                           |
    | error_limit     | Number (optional). Limit error per sheet. Default is 0. |
    +-----------------+---------------------------------------------------------+

SPECIFICATION FILE ^

Spec file containing rules used should be in the format mentioned below. Key and values are space seperated.

    sheet       Sheet1
    range       A3:B14
    range       B5:C5
    sheet       Sheet2
    range       A1:B2
    ignorerange B3:B8

What is "Visually" Similar? ^

This module uses the Spreadsheet::ParseExcel module to parse Excel files, then compares the parsed data structure for differences.We ignore certain components of the Excel file, such as embedded fonts, images, forms and annotations, and focus entirely on the layout of each Excel page instead. Future versions will likely support font and image comparisons.

How to find out what failed the comparison? ^

By turning the environment variable DEBUG ON would spit out PASS/FAIL comparison.

e.g. $/> $DEBUG=1 perl your_script.pl

NOTES ^

It should be clearly noted that this module does not claim to provide fool-proof comparison of generated Excels. In fact there are still a number of ways in which I want to expand the existing comparison functionality. This module is no longer actively being developed as I moved to another company.This work was part of one of my project. Having said, I would be more than happy to add new features if its requested. Any suggestions / ideas most welcome.

CAVEATS ^

Testing of large Excels can take a long time, this is because, well, we are doing a lot of computation. In fact, this module test suite includes tests against several large Excels, however I am not including those in this distibution for obvious reasons.

BUGS ^

None that I am aware of.Of course, if you find a bug, let me know, and I would do my best to fix it. This is still a very early version, so it is always possible that I have just "gotten it wrong" in some places.

SEE ALSO ^

Spreadsheet::ParseExcel - I could not have written this without this module.

ACKNOWLEDGEMENTS ^

John McNamara (author of Spreadsheet::ParseExcel).
Kawai Takanori (author of Spreadsheet::ParseExcel::Utility).
Stevan Little (author of Test::PDF).

AUTHOR ^

Mohammad S Anwar, <mohammad.anwar at yahoo.com>

REPOSITORY ^

https://github.com/Manwar/Test-Excel

BUGS ^

Please report any bugs or feature requests to bug-test-excel at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Excel. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Test::Excel

You can also look for information at:

LICENSE AND COPYRIGHT ^

Copyright (C) 2010 - 2015 Mohammad S Anwar.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License.By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you,you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement,then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

syntax highlighting: