+
+my %exit = (
+ pass => 0,
+ fail => 1,
+ skip => 2,
+ unknown => 3, # or greater
+);
+
+my %colors = (
+ $exit{pass} => colored('pass:', 'green' ),
+ $exit{fail} => colored('FAIL:', 'red' ),
+ $exit{skip} => colored('Skip:', 'yellow' ),
+ $exit{unknown} => colored('Unknown:', 'magenta'),
+);
+
+print "\n";
+foreach my $test (@tested) {
+ my $colored = exists $colors{$test->{result}}
+ ? $colors{$test->{result}}
+ : $colors{$exit{unknown}};
+ print "$colored $test->{name}\n";
+}
+
+my $count = sub
+{
+ return {
+ pass => sub { scalar grep $_->{result} == $exit{pass}, @tested },
+ fail => sub { scalar grep $_->{result} == $exit{fail}, @tested },
+ skip => sub { scalar grep $_->{result} == $exit{skip}, @tested },
+ unknown => sub { scalar grep $_->{result} >= $exit{unknown}, @tested },
+ }->{$_[0]}->();
+};
+
+my $summary = sub
+{
+ my @lines = (
+ "${\scalar @tested} tests were run",
+ "${\$count->('pass')} PASS, ${\$count->('fail')} FAIL",
+ "${\$count->('skip')} SKIP, ${\$count->('unknown')} UNKNOWN",
+ );
+ my $len_longest = sub
+ {
+ local $_ = 0;
+ foreach my $line (@lines) {
+ if (length $line > $_) {
+ $_ = length $line;
+ }
+ }
+ return $_;
+ }->();
+ return join "\n",
+ '=' x $len_longest,
+ @lines,
+ '=' x $len_longest;
+}->();
+
+print "\n";
+print $count->('fail') || $count->('unknown')
+ ? colored($summary, 'red')
+ : colored($summary, 'green');
+print "\n";
+
+exit $count->('fail') + $count->('unknown');