2 # $Id: test.pl,v 1.5 2005/08/21 18:31:58 eagle Exp $
4 # test.pl -- Test suite for the Term::ANSIColor Perl module.
6 # Before "make install" is performed this script should be runnable with "make
7 # test". After "make install" it should work as "perl test.pl".
9 ##############################################################################
10 # Ensure module can be loaded
11 ##############################################################################
13 BEGIN { $| = 1; print "1..16\n" }
14 END { print "not ok 1\n" unless $loaded }
15 delete $ENV{ANSI_COLORS_DISABLED};
16 use Term::ANSIColor qw(:constants color colored uncolor);
20 ##############################################################################
22 ##############################################################################
24 # Test simple color attributes.
25 if (color ('blue on_green', 'bold') eq "\e[34;42;1m") {
32 if (colored ("testing", 'blue', 'bold') eq "\e[34;1mtesting\e[0m") {
39 if (BLUE BOLD "testing" eq "\e[34m\e[1mtesting") {
46 $Term::ANSIColor::AUTORESET = 1;
47 if (BLUE BOLD "testing" eq "\e[34m\e[1mtesting\e[0m\e[0m") {
54 $Term::ANSIColor::EACHLINE = "\n";
55 if (colored ("test\n\ntest", 'bold')
56 eq "\e[1mtest\e[0m\n\n\e[1mtest\e[0m") {
59 print colored ("test\n\ntest", 'bold'), "\n";
63 # Test EACHLINE with multiple trailing delimiters.
64 $Term::ANSIColor::EACHLINE = "\r\n";
65 if (colored ("test\ntest\r\r\n\r\n", 'bold')
66 eq "\e[1mtest\ntest\r\e[0m\r\n\r\n") {
72 # Test the array ref form.
73 $Term::ANSIColor::EACHLINE = "\n";
74 if (colored (['bold', 'on_green'], "test\n", "\n", "test")
75 eq "\e[1;42mtest\e[0m\n\n\e[1;42mtest\e[0m") {
78 print colored (['bold', 'on_green'], "test\n", "\n", "test");
83 my @names = uncolor ('1;42', "\e[m", '', "\e[0m");
84 if (join ('|', @names) eq 'bold|on_green|clear') {
87 print join ('|', @names), "\n";
91 # Test ANSI_COLORS_DISABLED.
92 $ENV{ANSI_COLORS_DISABLED} = 1;
93 if (color ('blue') eq '') {
98 if (colored ('testing', 'blue', 'on_red') eq 'testing') {
103 if (GREEN 'testing' eq 'testing') {
108 delete $ENV{ANSI_COLORS_DISABLED};
110 # Make sure DARK is exported. This was omitted in versions prior to 1.07.
111 if (DARK "testing" eq "\e[2mtesting\e[0m") {
117 # Test colored with 0 and EACHLINE.
118 $Term::ANSIColor::EACHLINE = "\n";
119 if (colored ('0', 'blue', 'bold') eq "\e[34;1m0\e[0m") {
124 if (colored ("0\n0\n\n", 'blue', 'bold')
125 eq "\e[34;1m0\e[0m\n\e[34;1m0\e[0m\n\n") {
131 # Test colored with the empty string and EACHLINE.
132 if (colored ('', 'blue', 'bold') eq '') {