File Coverage

blib/lib/Perlito5/Test.pm
Criterion Covered Total %
statement 24 90 26.6
branch 1 10 10.0
condition n/a
subroutine 4 21 19.0
pod 0 20 0.0
total 29 141 20.5


line stmt bran cond sub pod time code
1             package Perlito5::Test;
2              
3 1     1   309 use feature 'say';
  1         1  
  1         696  
4              
5             ### GLOBALS
6              
7             # globals to keep track of our tests
8             my $num_of_tests_run;
9             my $num_of_tests_failed;
10             my $num_of_tests_badpass;
11             my $num_of_tests_planned;
12              
13             # for running the test suite multiple times in the same process
14             my $testing_started;
15              
16             ### FUNCTIONS
17              
18             sub plan {
19 1     1 0 8 my $number_of_tests = shift;
20 1         3 $testing_started = 1;
21 1         2 $num_of_tests_planned = $number_of_tests;
22              
23 1         15 say "1..$number_of_tests";
24             }
25              
26             sub ok {
27 1     1 0 6 my $cond = shift;
28 1         2 my $desc = shift;
29 1         2 my $todo = shift;
30 1         2 my $depends = shift;
31 1         13 Perlito5::Test::proclaim( $cond, 'ok! ' . $desc, $todo, $depends );
32             }
33              
34             sub is {
35 0     0 0 0 my $got = shift;
36 0         0 my $expected = shift;
37 0         0 my $desc = shift;
38 0         0 my $todo = shift;
39 0         0 my $depends = shift;
40              
41 0         0 my $test = $got eq $expected;
42 0         0 Perlito5::Test::proclaim( $test, 'is! ' . $desc, $todo, $got, $expected, $depends );
43             }
44              
45             sub is_deeply {
46 0     0 0 0 my $got = shift;
47 0         0 my $expected = shift;
48 0         0 my $desc = shift;
49 0         0 my $todo = shift;
50 0         0 my $depends = shift;
51              
52             # hack for now - TODO - use Data::Dumper
53 0         0 my $got_perl = $got;
54 0         0 my $expected_perl = $expected;
55 0         0 my $test = ( $got_perl eq $expected_perl );
56              
57 0         0 Perlito5::Test::proclaim( $test, "is deeply! $desc", $todo, $got_perl, $expected_perl, $depends );
58             }
59              
60             sub isnt {
61 0     0 0 0 my $got = shift;
62 0         0 my $expected = shift;
63 0         0 my $desc = shift;
64 0         0 my $todo = shift;
65 0         0 my $depends = shift;
66              
67 0         0 my $test = !( $got eq $expected );
68 0         0 Perlito5::Test::proclaim( $test, "isnt! $desc", $todo, $got, $expected, $depends, { negate => 1 } );
69             }
70              
71             sub cmp_ok {
72 0     0 0 0 my $got = shift;
73 0         0 my $compare_func = shift;
74 0         0 my $expected = shift;
75 0         0 my $desc = shift;
76 0         0 my $todo = shift;
77 0         0 my $depends = shift;
78              
79 0         0 say "### Perlito5::Test::cmp_ok not implemented";
80             }
81              
82             sub like {
83 0     0 0 0 say "### Perlito5::Test::like not implemented";
84             }
85              
86             sub unlike {
87 0     0 0 0 say "### Perlito5::Test::unlike not implemented";
88             }
89              
90             sub eval_dies_ok {
91 0     0 0 0 say "### Perlito5::Test::eval_dies_ok not implemented";
92             }
93              
94             sub isa_ok {
95 0     0 0 0 say "### Perlito5::Test::isa_ok not implemented";
96             }
97              
98             sub use_ok {
99 0     0 0 0 say "### Perlito5::Test::use_ok not implemented";
100             }
101              
102             sub throws_ok {
103 0     0 0 0 say "### Perlito5::Test::throws_ok not implemented";
104             }
105              
106             sub dies_ok {
107 0     0 0 0 say "### Perlito5::Test::dies_ok not implemented";
108             }
109              
110             sub lives_ok {
111 0     0 0 0 say "### Perlito5::Test::lives_ok not implemented";
112             }
113              
114             ## misc. test utilities
115              
116             sub skip {
117 0     0 0 0 my $reason = shift;
118 0         0 my $depends = shift;
119 0         0 Perlito5::Test::proclaim( 1, '', "skip " . $reason, $depends );
120             }
121              
122             sub pass {
123 0     0 0 0 my $desc = shift;
124 0         0 Perlito5::Test::proclaim( 1, 'pass! ' . $desc );
125             }
126              
127             sub flunk {
128 0     0 0 0 my $desc = shift;
129 0         0 my $todo = shift;
130 0         0 my $depends = shift;
131              
132 0         0 Perlito5::Test::proclaim( 0, 'flunk! ' . $desc, $todo, $depends );
133             }
134              
135             ## 'private' subs
136              
137             sub proclaim {
138 1     1 0 2 my $cond = shift;
139 1         2 my $desc = shift;
140 1         2 my $todo = shift;
141 1         2 my $got = shift;
142 1         2 my $expected = shift;
143 1         2 my $depends = shift;
144 1         1 my $negate = shift;
145              
146 1         2 $testing_started = 1;
147 1         3 $num_of_tests_run = $num_of_tests_run + 1;
148              
149 1 50       3 if ($cond) {
150 1         8 say "ok ", $num_of_tests_run;
151             }
152             else {
153 0           say "not ok ", $num_of_tests_run;
154 0           Perlito5::Test::report_failure( $todo, $got, $expected, $negate );
155             }
156              
157 1           return $cond;
158             }
159              
160             sub report_failure {
161 0     0 0   my $todo = shift;
162 0           my $got = shift;
163 0           my $expected = shift;
164 0           my $negate = shift;
165              
166 0           say "### Perlito5::Test::report_failure not implemented";
167             }
168              
169             sub test_ends {
170 0 0   0 0   if ( !$testing_started ) {
171 0           return;
172             }
173              
174 0 0         if ( !$num_of_tests_planned ) {
175 0           say "1.." . $num_of_tests_run;
176             }
177              
178 0 0         if ( $num_of_tests_planned != $num_of_tests_run ) {
179 0           say "# Looks like you planned " . $num_of_tests_planned . " tests, but ran " . $num_of_tests_run;
180             }
181              
182 0 0         if ($num_of_tests_failed) {
183 0           say "# Looks like you failed " . $num_of_tests_failed . " tests of " . $num_of_tests_run;
184             }
185              
186 0           $num_of_tests_run = 0;
187 0           $num_of_tests_failed = 0;
188 0           $num_of_tests_planned = 0;
189 0           $testing_started = 0;
190             }
191              
192             1;
193