File Coverage

blib/lib/Test/Sort/Sub.pm
Criterion Covered Total %
statement 45 45 100.0
branch 13 14 92.8
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 68 69 98.5


line stmt bran cond sub pod time code
1             ## no critic: Modules::ProhibitAutomaticExportation
2              
3             package Test::Sort::Sub;
4              
5             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
6             our $DATE = '2020-05-25'; # DATE
7             our $DIST = 'Sort-Sub'; # DIST
8             our $VERSION = '0.120'; # VERSION
9              
10 15     15   1359706 use 5.010001;
  15         185  
11 15     15   77 use strict 'subs', 'vars';
  15         24  
  15         382  
12 15     15   63 use warnings;
  15         25  
  15         435  
13              
14 15     15   79 use Exporter 'import';
  15         20  
  15         458  
15 15     15   6391 use Sort::Sub ();
  15         35  
  15         350  
16 15     15   94 use Test::More 0.98;
  15         219  
  15         73  
17              
18             our @EXPORT = qw(sort_sub_ok);
19              
20             sub _sort {
21 39     39   91 my ($args, $extras, $output_name) = @_;
22              
23 39         70 my $subname = $args->{subname};
24 39 100       269 Sort::Sub->import("$subname$extras", ($args->{args} ? $args->{args} : ()));
25 39         61 my $res;
26 39 100       95 if ($args->{compares_record}) {
27 24         44 $res = [map {$_->[0]} sort {&{$subname}($a,$b)}
  24         38  
  24         49  
28 6         12 (map { [$args->{input}[$_], $_] } 0..$#{ $args->{input} })];
  24         65  
  6         16  
29             } else {
30 33         48 $res = [sort {&{$subname}($a,$b)} @{ $args->{input} }];
  189         467  
  189         359  
  33         117  
31             }
32 39 50       279 is_deeply($args->{$output_name}, $res) or diag explain $res;
33             }
34              
35             sub sort_sub_ok {
36 16     16 1 4127 my %args = @_;
37              
38 16         43 my $subname = $args{subname};
39             subtest "sort_sub_ok $subname" => sub {
40 16     16   19999 my $res;
41              
42 16 100       61 if ($args{output}) {
43 15         55 _sort(\%args, '', 'output');
44             }
45              
46 16 100       11158 if ($args{output_i}) {
47 10         31 _sort(\%args, '<i>', 'output_i');
48             }
49              
50 16 100       6290 if ($args{output_r}) {
51 2         9 _sort(\%args, '<r>', 'output_r');
52             };
53              
54 16 100       1523 if ($args{output_ir}) {
55 12         41 _sort(\%args, '<ir>', 'output_ir');
56             };
57 16         130 };
58             }
59              
60             1;
61             # ABSTRACT: Test Sort::Sub::* subroutine
62              
63             __END__
64              
65             =pod
66              
67             =encoding UTF-8
68              
69             =head1 NAME
70              
71             Test::Sort::Sub - Test Sort::Sub::* subroutine
72              
73             =head1 VERSION
74              
75             This document describes version 0.120 of Test::Sort::Sub (from Perl distribution Sort-Sub), released on 2020-05-25.
76              
77             =head1 FUNCTIONS
78              
79             =head2 sort_sub_ok(%args) => bool
80              
81             =head1 HOMEPAGE
82              
83             Please visit the project's homepage at L<https://metacpan.org/release/Sort-Sub>.
84              
85             =head1 SOURCE
86              
87             Source repository is at L<https://github.com/perlancar/perl-Sort-Sub>.
88              
89             =head1 BUGS
90              
91             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Sort-Sub>
92              
93             When submitting a bug or request, please include a test-file or a
94             patch to an existing test-file that illustrates the bug or desired
95             feature.
96              
97             =head1 AUTHOR
98              
99             perlancar <perlancar@cpan.org>
100              
101             =head1 COPYRIGHT AND LICENSE
102              
103             This software is copyright (c) 2020, 2019, 2018, 2016, 2015 by perlancar@cpan.org.
104              
105             This is free software; you can redistribute it and/or modify it under
106             the same terms as the Perl 5 programming language system itself.
107              
108             =cut