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