| Test-Differences-Color documentation | Contained in the Test-Differences-Color distribution. |
Test::Differences::Color - colorize the result of Test::Differences
Version 0.05
use Test::More tests => 1;
use Test::Differences::Color;
eq_or_diff(\%hash1, \@hash2);
Alec Chen, <alec at cpan.org>
Please report any bugs or feature requests to bug-test-differences-color at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Differences-Color. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc Test::Differences::Color
You can also look for information at:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Differences-Color
Copyright 2008 Alec Chen, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Test-Differences-Color documentation | Contained in the Test-Differences-Color distribution. |
package Test::Differences::Color; use Sub::Override; use Term::ANSIColor qw(:constants); #$Term::ANSIColor::AUTORESET = 1; use Exporter 'import'; our @EXPORT = qw(eq_or_diff);
our $VERSION = '0.05';
sub eq_or_diff { my ($data1, $data2) = @_; my(undef, $file, $line_num) = caller; my $override = Sub::Override->new(); $override->replace('Test::Builder::_print_to_fh', sub { my( $self, $fh, @msgs ) = @_; # Prevent printing headers when only compiling. Mostly for when # tests are deparsed with B::Deparse return if $^C; my $msg = join '', @msgs; local( $\, $", $, ) = ( undef, ' ', '' ); # Escape each line after the first with a # so we don't # confuse Test::Harness. $msg =~ s{\n(?!\z)}{\n# }sg; # Stick a newline on the end if it needs it. $msg .= "\n" unless $msg =~ /\n\z/; my @lines = split /\n/, $msg; foreach my $line (@lines) { my $match_start = $line =~ /^# \*/; my $match_end = $line =~ /\*$/; if ($match_start && $match_end) { print $fh ON_RED, $line, RESET, "\n"; } elsif ($match_start) { print $fh ON_BLUE, $line, RESET, "\n"; } elsif ($match_end) { print $fh ON_GREEN, $line, RESET, "\n"; } else { print $fh $line, "\n"; } } return; }, ); require Test::Differences; my $return = Test::Differences::eq_or_diff($data1, $data2); $override->restore(); return $return; }
1; # End of Test::Differences::Color