|
Packit |
e6c7a3 |
#!/usr/bin/perl
|
|
Packit |
e6c7a3 |
#
|
|
Packit |
e6c7a3 |
# Test setting color aliases via the environment.
|
|
Packit |
e6c7a3 |
#
|
|
Packit |
e6c7a3 |
# Copyright 2012 Stephen Thirlwall
|
|
Packit |
e6c7a3 |
# Copyright 2012, 2014 Russ Allbery <rra@cpan.org>
|
|
Packit |
e6c7a3 |
#
|
|
Packit |
e6c7a3 |
# This program is free software; you may redistribute it and/or modify it
|
|
Packit |
e6c7a3 |
# under the same terms as Perl itself.
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
use 5.006;
|
|
Packit |
e6c7a3 |
use strict;
|
|
Packit |
e6c7a3 |
use warnings;
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
use lib 't/lib';
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
use Test::More;
|
|
Packit |
e6c7a3 |
use Test::RRA qw(use_prereq);
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Load prerequisite modules.
|
|
Packit |
e6c7a3 |
use_prereq('Test::Warn');
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Print out our plan.
|
|
Packit |
e6c7a3 |
plan tests => 19;
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Ensure we don't pick up a setting from the user's environment.
|
|
Packit |
e6c7a3 |
delete $ENV{ANSI_COLORS_DISABLED};
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Set up some custom color configuration. The last four will produce warnings
|
|
Packit |
e6c7a3 |
# on module load.
|
|
Packit |
e6c7a3 |
my @COLOR_ALIASES = (
|
|
Packit |
e6c7a3 |
' custom_black = black', 'custom_red= red',
|
|
Packit |
e6c7a3 |
'custom_green =green ', 'custom_blue=blue',
|
|
Packit |
e6c7a3 |
'custom_unknown=unknown', '=no_new',
|
|
Packit |
e6c7a3 |
'no_old=', 'no_equals',
|
|
Packit |
e6c7a3 |
'red=green', 'custom_test=red=blue',
|
|
Packit |
e6c7a3 |
'custom!test=red',
|
|
Packit |
e6c7a3 |
);
|
|
Packit |
e6c7a3 |
local $ENV{ANSI_COLORS_ALIASES} = join(q{,}, @COLOR_ALIASES);
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Load the module, which should produce those warnings.
|
|
Packit |
e6c7a3 |
my $require_sub = sub { require_ok('Term::ANSIColor') };
|
|
Packit |
e6c7a3 |
warnings_like(
|
|
Packit |
e6c7a3 |
$require_sub,
|
|
Packit |
e6c7a3 |
[
|
|
Packit |
e6c7a3 |
qr{ \A Invalid [ ] attribute [ ] name [ ] "unknown" [ ] in [ ]
|
|
Packit |
e6c7a3 |
"custom_unknown=unknown" [ ] at [ ] }xms,
|
|
Packit |
e6c7a3 |
qr{ \A Bad [ ] color [ ] mapping [ ] "=no_new" [ ] at [ ] }xms,
|
|
Packit |
e6c7a3 |
qr{ \A Bad [ ] color [ ] mapping [ ] "no_old=" [ ] at [ ] }xms,
|
|
Packit |
e6c7a3 |
qr{ \A Bad [ ] color [ ] mapping [ ] "no_equals" [ ] at [ ] }xms,
|
|
Packit |
e6c7a3 |
qr{ \A Cannot [ ] alias [ ] standard [ ] color [ ] "red" [ ] in
|
|
Packit |
e6c7a3 |
[ ] "red=green" [ ] at [ ] }xms,
|
|
Packit |
e6c7a3 |
qr{ \A Invalid [ ] attribute [ ] name [ ] "red=blue" [ ] in [ ]
|
|
Packit |
e6c7a3 |
"custom_test=red=blue" [ ] at [ ] }xms,
|
|
Packit |
e6c7a3 |
qr{ \A Invalid [ ] alias [ ] name [ ] "custom!test" [ ] in [ ]
|
|
Packit |
e6c7a3 |
"custom!test=red" [ ] at [ ] }xms,
|
|
Packit |
e6c7a3 |
],
|
|
Packit |
e6c7a3 |
'Correct warnings when loading module'
|
|
Packit |
e6c7a3 |
);
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Import the functions for convenience.
|
|
Packit |
e6c7a3 |
Term::ANSIColor->import(qw(color colored colorvalid uncolor));
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Check the custom colors all get assigned. They use various spacing formats
|
|
Packit |
e6c7a3 |
# and should all parse correctly.
|
|
Packit |
e6c7a3 |
for my $original (qw(black red green blue)) {
|
|
Packit |
e6c7a3 |
my $custom = 'custom_' . $original;
|
|
Packit |
e6c7a3 |
ok(colorvalid($custom), "$custom is valid");
|
|
Packit |
e6c7a3 |
is(color($custom), color($original),
|
|
Packit |
e6c7a3 |
"...and matches $original with color");
|
|
Packit |
e6c7a3 |
is(
|
|
Packit |
e6c7a3 |
colored('test', $custom),
|
|
Packit |
e6c7a3 |
colored('test', $original),
|
|
Packit |
e6c7a3 |
"...and matches $original with colored"
|
|
Packit |
e6c7a3 |
);
|
|
Packit |
e6c7a3 |
is_deeply([uncolor(color($custom))],
|
|
Packit |
e6c7a3 |
[$original], "...and uncolor returns $original");
|
|
Packit |
e6c7a3 |
}
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# custom_unknown is mapped to an unknown color and should not appear.
|
|
Packit |
e6c7a3 |
is(colorvalid('custom_unknown'), undef, 'Unknown color mapping fails');
|