1 # Test suite for the Term::ANSIColor Perl module. Before `make install' is
2 # performed this script should be runnable with `make test'. After `make
3 # install' it should work as `perl test.pl'.
5 ############################################################################
6 # Ensure module can be loaded
7 ############################################################################
9 BEGIN { $| = 1; print "1..12\n" }
10 END { print "not ok 1\n" unless $loaded }
11 delete $ENV{ANSI_COLORS_DISABLED};
12 use Term::ANSIColor qw(:constants color colored uncolor);
17 ############################################################################
19 ############################################################################
21 # Test simple color attributes.
22 if (color ('blue on_green', 'bold') eq "\e[34;42;1m") {
29 if (colored ("testing", 'blue', 'bold') eq "\e[34;1mtesting\e[0m") {
36 if (BLUE BOLD "testing" eq "\e[34m\e[1mtesting") {
43 $Term::ANSIColor::AUTORESET = 1;
44 if (BLUE BOLD "testing" eq "\e[34m\e[1mtesting\e[0m\e[0m") {
51 $Term::ANSIColor::EACHLINE = "\n";
52 if (colored ("test\n\ntest", 'bold')
53 eq "\e[1mtest\e[0m\n\n\e[1mtest\e[0m") {
56 print colored ("test\n\ntest", 'bold'), "\n";
60 # Test EACHLINE with multiple trailing delimiters.
61 $Term::ANSIColor::EACHLINE = "\r\n";
62 if (colored ("test\ntest\r\r\n\r\n", 'bold')
63 eq "\e[1mtest\ntest\r\e[0m\r\n\r\n") {
69 # Test the array ref form.
70 $Term::ANSIColor::EACHLINE = "\n";
71 if (colored (['bold', 'on_green'], "test\n", "\n", "test")
72 eq "\e[1;42mtest\e[0m\n\n\e[1;42mtest\e[0m") {
75 print colored (['bold', 'on_green'], "test\n", "\n", "test");
80 my @names = uncolor ('1;42', "\e[m", '', "\e[0m");
81 if (join ('|', @names) eq 'bold|on_green|clear') {
84 print join ('|', @names), "\n";
88 # Test ANSI_COLORS_DISABLED.
89 $ENV{ANSI_COLORS_DISABLED} = 1;
90 if (color ('blue') == '') {
95 if (colored ('testing', 'blue', 'on_red') == 'testing') {
100 if (GREEN 'testing' eq 'testing') {