File Coverage

t/lib/MyTestTools.pm
Criterion Covered Total %
statement 15 44 34.0
branch 0 10 0.0
condition 0 7 0.0
subroutine 5 10 50.0
pod 3 5 60.0
total 23 76 30.2


line stmt bran cond sub pod time code
1             package MyTestTools;
2 1     1   6 use base qw(Exporter);
  1         2  
  1         152  
3 1     1   6 use strict;
  1         2  
  1         27  
4 1     1   5 use warnings;
  1         2  
  1         31  
5              
6 1     1   4 use Test::More;
  1         2  
  1         13  
7 1     1   1033 use IO::File;
  1         10437  
  1         646  
8              
9             our @EXPORT = ();
10             our @CSS_FUNCTIONS = qw( build_css_regex count_css check_results );
11             our @EXPORT_OK = ( @CSS_FUNCTIONS, qw(Engines ResultsFile) );
12             our %EXPORT_TAGS = (
13             'all' => [ @EXPORT_OK ],
14             'css' => [ @CSS_FUNCTIONS ],
15             );
16              
17             our $VERSION = '0.1';
18             my %default_counters = (
19             q(synLineNumber) => 0,
20             q(synTitle) => 0,
21             q(synBar) => 0,
22             q(synComment) => 0,
23             q(synConstant) => 0,
24             q(synIdentifier) => 0,
25             q(synStatement) => 0,
26             q(synPreProc) => 0,
27             q(synType) => 0,
28             q(synSpecial) => 0,
29             q(synUnderlined) => 0,
30             q(synError) => 0,
31             q(synTodo) => 0,
32             );
33              
34             sub build_css_regex {
35 0     0 1   my $tag = shift;
36 0   0       my $value = shift || q(.+);
37              
38 0           my $expr = sprintf('\s*%s\s*',
39             $tag, $value );
40              
41 0           return qr{$expr};
42             }
43              
44             sub count_css {
45 0     0 1   my $text = shift;
46 0           my %css_tags = ();
47              
48 0           while ($text =~ m{}xmsg) {
49 0           my $name = $1;
50 0 0         if (not exists $css_tags{$name}) {
51 0           $css_tags{$name} = 0;
52             }
53              
54 0           $css_tags{$name}++;
55             }
56              
57 0 0         return wantarray ? %css_tags : scalar keys %css_tags;
58             }
59              
60             sub check_results {
61 0     0 1   my ($text, %expect) = @_;
62            
63 0           my %found = ( %default_counters,
64             count_css( $text ) );
65              
66 0           foreach my $name (keys %expect) {
67 0           is($found{$name},$expect{$name}, sprintf ("Found %u %s tag(s)", $found{$name}, $name) );
68             }
69              
70 0           return;
71             }
72              
73             sub Engines {
74 0   0 0 0   my $full_path = shift || 0;
75 0           my @names = qw(Simple Kate Vim);
76              
77 0 0         if ($full_path) {
78 0           return map { "IkiWiki::Plugin::syntax::${_}" } @names;
  0            
79             }
80             else {
81 0           return @names;
82             }
83             }
84              
85             my $results_fh = undef;
86              
87             sub ResultsFile {
88 0     0 0   my $path = shift;
89              
90 0 0         if (not $path) {
91 0           return $results_fh;
92             }
93             else {
94             # if the file exits and isn't writable
95 0 0 0       if (-e $path and not -w $path) {
96 0           return;
97             }
98             else {
99             # open the file for writing
100 0           return $results_fh = IO::File->new( $path, ">" );
101             }
102             }
103             }
104              
105             1;
106             __END__