My first contribution to CPAN
was Test::Excel. It was initiated as we had requirement for such at work at that time.
It has gone through many changes, thanks to all for reporting issues and providing patches..
It even got space as topic for Day 18 in Perl Advent Calendar 2018
.
It was a proud moment when a collegue of mine at work requested help with Test::Excel
as it was not behaving as per her requirements. I was glad I could help her and got it patched so that it works for her.
Recently another collegue of mine at work asked me if it has support for regex
.
Unfortunately it didn't
have the support but I liked the idea.
I decided to get the patch ready. I had the first draft ready in no time but there was still some edge cases failing.
I needed some interrupted time to get it fixed. I then got distracted and moved away to do something else.
This morning, Sunday 3rd July 2022
, I was feeling low and wanted to do something to boost my confidence.
I looked at my TODO
list and found this long pending task.
Having spent non-distracted 3 hours
, I finally have cleared all pending edge cases.
It is now available on CPAN
as v1.51.
So how to use regex
?
The regex
is now added to be part of specification file.
The regex comparison can be applied to every cells in every sheets by having the following in the specification file.
sheet ALL
regex 2022\-\d\d\-\d\d
Or if you want to apply the rule to just a particular sheet e.g. Demo
.
sheet Demo
regex 2022\-\d\d\-\d\d
How about just selected ranges in every sheets.
sheet ALL
range B2:B4
regex 2022\-\d\d\-\d\d
Similary restrict to a named sheet.
sheet Demo
range B2:B4
regex 2022\-\d\d\-\d\d
Time for some action.
#!/usr/bin/perl
use v5.36;
use Test::Excel;
compare_excel('demo-1.xls', 'demo-2.xls', { spec => 'spec.txt' })
?
(say "matched.")
:
(say "unmatched.");
You can use as unit testing as below:
#!/usr/bin/perl
use v5.36;
use Test::More;
use Test::Excel;
ok compare_excel('demo-1.xls', 'demo-2.xls', { spec => 'spec.txt' });
ok !compare_excel('demo-1.xls', 'demo-3.xls', { spec => 'spec.txt' });
done_testing;
Or something like this:
#!/usr/bin/perl
use v5.36;
use Test::More;
use_ok('Test::Excel');
cmp_excel_ok('demo-1.xls', 'demo-2.xls', { spec => 'spec.txt' });
cmp_excel_not_ok('demo-1.xls', 'demo-3.xls', { spec => 'spec.txt' });
done_testing;
If you have any suggestions then please report it on GitHub repository.
That’s it for now.