]> git.refcnt.org Git - colorize.git/blobdiff - test.pl
Omit declaration of optind/optarg
[colorize.git] / test.pl
diff --git a/test.pl b/test.pl
index a44395fecdce2b900557053cf3ee2e25ef85a105..928c6987054f644dd06e48baac2b384118a05c85 100755 (executable)
--- a/test.pl
+++ b/test.pl
@@ -7,12 +7,13 @@ use constant true  => 1;
 use constant false => 0;
 
 use Colorize::Common qw(:defaults $compiler_flags %BUF_SIZE $valgrind_command $write_to_tmpfile);
+use File::Find;
 use File::Temp qw(tmpnam);
 use Getopt::Long qw(:config no_auto_abbrev no_ignore_case);
 use Test::Harness qw(runtests);
 use Test::More;
 
-my $tests = 24;
+my $tests = 32;
 
 my $valgrind_cmd = '';
 {
@@ -28,8 +29,9 @@ my $valgrind_cmd = '';
 }
 
 {
-    my @test_files = glob('t/*.t');
-    eval { runtests(@test_files) } or warn $@;
+    my @test_files;
+    find ({ wanted => sub { push @test_files, $File::Find::name if /\.t$/ } }, 't');
+    eval { runtests(sort @test_files) } or warn $@;
 }
 
 plan tests => $tests;
@@ -82,7 +84,28 @@ SKIP: {
         is(qx(printf %s "hello world" | $program Magenta | $valgrind_cmd$program $switch),        'hello world', "$type colored line");
         is_deeply([split /\n/, qx($program cyan $infile1 | $valgrind_cmd$program $switch)], [split /\n/, $text], "$type colored text");
 
+        {
+            my @attrs = qw(bold underscore blink reverse concealed);
+
+            my $ok = true;
+            foreach my $attr (@attrs) {
+                $ok &= qx(printf %s "$attr" | $program green --attr=$attr | $valgrind_cmd$program $switch) eq $attr;
+            }
+            ok($ok, "$type attribute");
+
+            my $attrs = join ',', @attrs;
+            is(qx(printf %s "$attrs" | $program green --attr=$attrs | $valgrind_cmd$program $switch), $attrs, "$type attributes");
+        }
+
         ok(qx(printf %s "\e[\e[33m" | $valgrind_cmd$program $switch) eq "\e[", "$type with invalid sequence");
+
+        {
+            my $ok = true;
+            foreach my $option (qw(--attr=bold --exclude-random=black --omit-color-empty)) {
+                $ok &= qx($valgrind_cmd$program $option $switch $infile1 2>&1 >/dev/null) =~ /switch has no meaning with/;
+            }
+            ok($ok, "$type strict options");
+        }
     };
 
     $check_clean->($_) foreach qw(clean clean-all);
@@ -119,10 +142,24 @@ SKIP: {
         is($sequences, 2, 'count of sequences printed');
     }
 
+    {
+        # Check that a 'none' foreground color (with a background color present)
+        # will be substituted by 'default'.
+        my $colored_text = qx(printf %s "foo bar baz" | $valgrind_cmd$program none/black);
+        is($colored_text, "\e[40m\e[39mfoo bar baz\e[0m", 'no color sequences printed');
+    }
+
     is(qx(printf %s "hello\nworld\r\n" | $valgrind_cmd$program none/none), "hello\nworld\r\n", 'stream mode');
 
     is(system(qq(printf '%s\n' "hello world" | $valgrind_cmd$program random --exclude-random=black >/dev/null)), 0, 'switch exclude-random');
 
+    {
+        my $infile = $write_to_tmpfile->("foo\n\nbar");
+        is_deeply([split /\n/, qx($valgrind_cmd$program yellow --omit-color-empty $infile)],
+                  [split /\n/, "\e[33mfoo\e[0m\n\n\e[33mbar\e[0m"],
+                  'switch omit-color-empty');
+    }
+
     SKIP: {
         skip 'valgrind not found', 1 unless system('which valgrind >/dev/null 2>&1') == 0;
         like(qx(valgrind $program none/none $infile1 2>&1 >/dev/null), qr/no leaks are possible/, 'valgrind memleaks');
@@ -145,6 +182,14 @@ EOT
         system(qq(printf '%s\n' "$bold_color" | $program $bold_color));
     }
 
+    print <<'EOT';
+Attributes
+==========
+EOT
+    foreach my $attr (qw(bold underscore blink reverse concealed)) {
+        system(qq(printf '%s\n' "$attr" | $program green --attr=$attr));
+    }
+
     unlink $program;
 };