Stop harness from printing summary table header for each row in table
[p5sagit/p5-mst-13.2.git] / lib / Term / ANSIColor / test.pl
CommitLineData
2e589669 1#!/usr/bin/perl
51da1d85 2# $Id: test.pl,v 1.5 2005/08/21 18:31:58 eagle Exp $
2e589669 3#
4# test.pl -- Test suite for the Term::ANSIColor Perl module.
5#
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".
e3e5e1ea 8
51da1d85 9##############################################################################
e3e5e1ea 10# Ensure module can be loaded
51da1d85 11##############################################################################
e3e5e1ea 12
51da1d85 13BEGIN { $| = 1; print "1..16\n" }
e3e5e1ea 14END { print "not ok 1\n" unless $loaded }
110e9fb0 15delete $ENV{ANSI_COLORS_DISABLED};
16use Term::ANSIColor qw(:constants color colored uncolor);
e3e5e1ea 17$loaded = 1;
18print "ok 1\n";
19
51da1d85 20##############################################################################
e3e5e1ea 21# Test suite
51da1d85 22##############################################################################
e3e5e1ea 23
24# Test simple color attributes.
25if (color ('blue on_green', 'bold') eq "\e[34;42;1m") {
26 print "ok 2\n";
27} else {
28 print "not ok 2\n";
29}
30
31# Test colored.
32if (colored ("testing", 'blue', 'bold') eq "\e[34;1mtesting\e[0m") {
33 print "ok 3\n";
34} else {
35 print "not ok 3\n";
36}
37
38# Test the constants.
39if (BLUE BOLD "testing" eq "\e[34m\e[1mtesting") {
40 print "ok 4\n";
41} else {
42 print "not ok 4\n";
43}
44
45# Test AUTORESET.
46$Term::ANSIColor::AUTORESET = 1;
47if (BLUE BOLD "testing" eq "\e[34m\e[1mtesting\e[0m\e[0m") {
48 print "ok 5\n";
49} else {
50 print "not ok 5\n";
51}
52
53# Test EACHLINE.
54$Term::ANSIColor::EACHLINE = "\n";
55if (colored ("test\n\ntest", 'bold')
56 eq "\e[1mtest\e[0m\n\n\e[1mtest\e[0m") {
57 print "ok 6\n";
58} else {
59 print colored ("test\n\ntest", 'bold'), "\n";
60 print "not ok 6\n";
61}
62
63# Test EACHLINE with multiple trailing delimiters.
64$Term::ANSIColor::EACHLINE = "\r\n";
65if (colored ("test\ntest\r\r\n\r\n", 'bold')
66 eq "\e[1mtest\ntest\r\e[0m\r\n\r\n") {
67 print "ok 7\n";
68} else {
69 print "not ok 7\n";
70}
f63addff 71
72# Test the array ref form.
73$Term::ANSIColor::EACHLINE = "\n";
74if (colored (['bold', 'on_green'], "test\n", "\n", "test")
75 eq "\e[1;42mtest\e[0m\n\n\e[1;42mtest\e[0m") {
76 print "ok 8\n";
77} else {
78 print colored (['bold', 'on_green'], "test\n", "\n", "test");
79 print "not ok 8\n";
80}
110e9fb0 81
82# Test uncolor.
83my @names = uncolor ('1;42', "\e[m", '', "\e[0m");
84if (join ('|', @names) eq 'bold|on_green|clear') {
85 print "ok 9\n";
86} else {
87 print join ('|', @names), "\n";
88 print "not ok 9\n";
89}
90
91# Test ANSI_COLORS_DISABLED.
92$ENV{ANSI_COLORS_DISABLED} = 1;
92c7d2a2 93if (color ('blue') eq '') {
110e9fb0 94 print "ok 10\n";
95} else {
96 print "not ok 10\n";
97}
92c7d2a2 98if (colored ('testing', 'blue', 'on_red') eq 'testing') {
110e9fb0 99 print "ok 11\n";
100} else {
101 print "not ok 11\n";
102}
103if (GREEN 'testing' eq 'testing') {
104 print "ok 12\n";
105} else {
106 print "not ok 12\n";
107}
2e589669 108delete $ENV{ANSI_COLORS_DISABLED};
109
110# Make sure DARK is exported. This was omitted in versions prior to 1.07.
111if (DARK "testing" eq "\e[2mtesting\e[0m") {
112 print "ok 13\n";
113} else {
114 print "not ok 13\n";
115}
51da1d85 116
117# Test colored with 0 and EACHLINE.
118$Term::ANSIColor::EACHLINE = "\n";
119if (colored ('0', 'blue', 'bold') eq "\e[34;1m0\e[0m") {
120 print "ok 14\n";
121} else {
122 print "not ok 14\n";
123}
124if (colored ("0\n0\n\n", 'blue', 'bold')
125 eq "\e[34;1m0\e[0m\n\e[34;1m0\e[0m\n\n") {
126 print "ok 15\n";
127} else {
128 print "not ok 15\n";
129}
130
131# Test colored with the empty string and EACHLINE.
132if (colored ('', 'blue', 'bold') eq '') {
133 print "ok 16\n";
134} else {
135 print "not ok 16\n";
136}