1N/A#!/usr/bin/perl
1N/A# $Id: test.pl,v 1.3 2004/02/20 06:21:26 eagle Exp $
1N/A#
1N/A# test.pl -- Test suite for the Term::ANSIColor Perl module.
1N/A#
1N/A# Before "make install" is performed this script should be runnable with "make
1N/A# test". After "make install" it should work as "perl test.pl".
1N/A
1N/A############################################################################
1N/A# Ensure module can be loaded
1N/A############################################################################
1N/A
1N/ABEGIN { $| = 1; print "1..13\n" }
1N/AEND { print "not ok 1\n" unless $loaded }
1N/Adelete $ENV{ANSI_COLORS_DISABLED};
1N/Ause Term::ANSIColor qw(:constants color colored uncolor);
1N/A$loaded = 1;
1N/Aprint "ok 1\n";
1N/A
1N/A
1N/A############################################################################
1N/A# Test suite
1N/A############################################################################
1N/A
1N/A# Test simple color attributes.
1N/Aif (color ('blue on_green', 'bold') eq "\e[34;42;1m") {
1N/A print "ok 2\n";
1N/A} else {
1N/A print "not ok 2\n";
1N/A}
1N/A
1N/A# Test colored.
1N/Aif (colored ("testing", 'blue', 'bold') eq "\e[34;1mtesting\e[0m") {
1N/A print "ok 3\n";
1N/A} else {
1N/A print "not ok 3\n";
1N/A}
1N/A
1N/A# Test the constants.
1N/Aif (BLUE BOLD "testing" eq "\e[34m\e[1mtesting") {
1N/A print "ok 4\n";
1N/A} else {
1N/A print "not ok 4\n";
1N/A}
1N/A
1N/A# Test AUTORESET.
1N/A$Term::ANSIColor::AUTORESET = 1;
1N/Aif (BLUE BOLD "testing" eq "\e[34m\e[1mtesting\e[0m\e[0m") {
1N/A print "ok 5\n";
1N/A} else {
1N/A print "not ok 5\n";
1N/A}
1N/A
1N/A# Test EACHLINE.
1N/A$Term::ANSIColor::EACHLINE = "\n";
1N/Aif (colored ("test\n\ntest", 'bold')
1N/A eq "\e[1mtest\e[0m\n\n\e[1mtest\e[0m") {
1N/A print "ok 6\n";
1N/A} else {
1N/A print colored ("test\n\ntest", 'bold'), "\n";
1N/A print "not ok 6\n";
1N/A}
1N/A
1N/A# Test EACHLINE with multiple trailing delimiters.
1N/A$Term::ANSIColor::EACHLINE = "\r\n";
1N/Aif (colored ("test\ntest\r\r\n\r\n", 'bold')
1N/A eq "\e[1mtest\ntest\r\e[0m\r\n\r\n") {
1N/A print "ok 7\n";
1N/A} else {
1N/A print "not ok 7\n";
1N/A}
1N/A
1N/A# Test the array ref form.
1N/A$Term::ANSIColor::EACHLINE = "\n";
1N/Aif (colored (['bold', 'on_green'], "test\n", "\n", "test")
1N/A eq "\e[1;42mtest\e[0m\n\n\e[1;42mtest\e[0m") {
1N/A print "ok 8\n";
1N/A} else {
1N/A print colored (['bold', 'on_green'], "test\n", "\n", "test");
1N/A print "not ok 8\n";
1N/A}
1N/A
1N/A# Test uncolor.
1N/Amy @names = uncolor ('1;42', "\e[m", '', "\e[0m");
1N/Aif (join ('|', @names) eq 'bold|on_green|clear') {
1N/A print "ok 9\n";
1N/A} else {
1N/A print join ('|', @names), "\n";
1N/A print "not ok 9\n";
1N/A}
1N/A
1N/A# Test ANSI_COLORS_DISABLED.
1N/A$ENV{ANSI_COLORS_DISABLED} = 1;
1N/Aif (color ('blue') == '') {
1N/A print "ok 10\n";
1N/A} else {
1N/A print "not ok 10\n";
1N/A}
1N/Aif (colored ('testing', 'blue', 'on_red') == 'testing') {
1N/A print "ok 11\n";
1N/A} else {
1N/A print "not ok 11\n";
1N/A}
1N/Aif (GREEN 'testing' eq 'testing') {
1N/A print "ok 12\n";
1N/A} else {
1N/A print "not ok 12\n";
1N/A}
1N/Adelete $ENV{ANSI_COLORS_DISABLED};
1N/A
1N/A# Make sure DARK is exported. This was omitted in versions prior to 1.07.
1N/Aif (DARK "testing" eq "\e[2mtesting\e[0m") {
1N/A print "ok 13\n";
1N/A} else {
1N/A print "not ok 13\n";
1N/A}