|
Packit |
e6c7a3 |
#!/usr/bin/perl
|
|
Packit |
e6c7a3 |
#
|
|
Packit |
e6c7a3 |
# Test suite for $@ preservation with constants.
|
|
Packit |
e6c7a3 |
#
|
|
Packit |
e6c7a3 |
# Earlier versions of Term::ANSIColor would clobber $@ during AUTOLOAD
|
|
Packit |
e6c7a3 |
# processing and lose its value or leak $@ values to the calling program.
|
|
Packit |
e6c7a3 |
# This is a regression test to ensure that this problem doesn't return.
|
|
Packit |
e6c7a3 |
#
|
|
Packit |
e6c7a3 |
# Copyright 2012, 2013, 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 strict;
|
|
Packit |
e6c7a3 |
use warnings;
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
use Test::More tests => 15;
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# We refer to $@ in the test descriptions.
|
|
Packit |
e6c7a3 |
## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Load the module.
|
|
Packit |
e6c7a3 |
BEGIN {
|
|
Packit |
e6c7a3 |
delete $ENV{ANSI_COLORS_ALIASES};
|
|
Packit |
e6c7a3 |
delete $ENV{ANSI_COLORS_DISABLED};
|
|
Packit |
e6c7a3 |
use_ok('Term::ANSIColor', qw(:constants));
|
|
Packit |
e6c7a3 |
}
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Ensure that using a constant doesn't leak anything in $@.
|
|
Packit |
e6c7a3 |
is((BOLD 'test'), "\e[1mtest", 'BOLD works');
|
|
Packit |
e6c7a3 |
is($@, q{}, '... and $@ is empty');
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Store something in $@ and ensure it doesn't get clobbered.
|
|
Packit |
e6c7a3 |
## no critic (BuiltinFunctions::ProhibitStringyEval)
|
|
Packit |
e6c7a3 |
eval 'sub { syntax';
|
|
Packit |
e6c7a3 |
is((BLINK 'test'), "\e[5mtest", 'BLINK works after eval failure');
|
|
Packit |
e6c7a3 |
isnt($@, q{}, '... and $@ still contains something useful');
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Do some additional unnecessary testing so that coverage analysis works
|
|
Packit |
e6c7a3 |
# properly. First, check disabled colors.
|
|
Packit |
e6c7a3 |
local $ENV{ANSI_COLORS_DISABLED} = 1;
|
|
Packit |
e6c7a3 |
is(BOLD, q{}, 'ANSI_COLORS_DISABLED works for BOLD');
|
|
Packit |
e6c7a3 |
is(BLINK, q{}, '...and for BLINK');
|
|
Packit |
e6c7a3 |
delete $ENV{ANSI_COLORS_DISABLED};
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Now, AUTORESET.
|
|
Packit |
e6c7a3 |
$Term::ANSIColor::AUTORESET = 1;
|
|
Packit |
e6c7a3 |
is((BOLD 't'), "\e[1mt\e[0m", 'AUTORESET works for BOLD');
|
|
Packit |
e6c7a3 |
is((BLINK 't'), "\e[5mt\e[0m", '...and for BLINK');
|
|
Packit |
e6c7a3 |
is((BOLD), "\e[1m", 'AUTORESET without text for BOLD');
|
|
Packit |
e6c7a3 |
is((BLINK), "\e[5m", '...and for BLINK');
|
|
Packit |
e6c7a3 |
$Term::ANSIColor::AUTORESET = 0;
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# And, finally, AUTOLOCAL.
|
|
Packit |
e6c7a3 |
$Term::ANSIColor::AUTOLOCAL = 1;
|
|
Packit |
e6c7a3 |
is((BOLD 't'), "\e[1mt\e[0m", 'AUTOLOCAL works for BOLD');
|
|
Packit |
e6c7a3 |
is((BLINK 't'), "\e[5mt\e[0m", '...and for BLINK');
|
|
Packit |
e6c7a3 |
is((BOLD), "\e[1m", 'AUTOLOCAL without text for BOLD');
|
|
Packit |
e6c7a3 |
is((BLINK), "\e[5m", '...and for BLINK');
|
|
Packit |
e6c7a3 |
$Term::ANSIColor::AUTOLOCAL = 0;
|