]> git.refcnt.org Git - colorize.git/blob - t/conf/use.t
Don't increment rainbow color with partial line
[colorize.git] / t / conf / use.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use lib qw(lib);
6
7 use Colorize::Common qw(:defaults $write_to_tmpfile);
8 use File::Temp qw(tmpnam);
9 use Test::More;
10
11 my $tests = 21;
12
13 my $conf = <<'EOT';
14 attr=underscore
15 color=yellow/black # tested also in color.t
16 omit-color-empty=yes
17 rainbow-bg=yes
18 EOT
19
20 plan tests => $tests;
21
22 SKIP: {
23 my $program = tmpnam();
24 my $conf_file = tmpnam();
25
26 skip 'compiling failed (use config)', $tests unless system(qq($compiler -DTEST -DCONF_FILE_TEST=\"$conf_file\" -o $program $source)) == 0;
27
28 my $infile1 = $write_to_tmpfile->(<<'EOT');
29 foo
30
31 bar
32
33 baz
34 EOT
35 open(my $fh, '>', $conf_file) or die "Cannot open `$conf_file' for writing: $!\n";
36 print {$fh} $conf;
37 close($fh);
38
39 is(qx($program $infile1), <<"EOT", 'use config');
40 \e[40m\e[4;33mfoo\e[0m
41
42 \e[41m\e[4;33mbar\e[0m
43
44 \e[42m\e[4;33mbaz\e[0m
45 EOT
46 my $infile2 = $write_to_tmpfile->('foo');
47
48 open($fh, '>', $conf_file) or die "Cannot open `$conf_file' for writing: $!\n";
49 print {$fh} "exclude-random=black\n";
50 close($fh);
51
52 for (my $i = 1; $i <= 20; $i++) {
53 like(qx($program random $infile2), qr/^\e\[3[1-7]mfoo\e\[0m$/, 'use exclude-random');
54 }
55
56 unlink $program;
57 unlink $conf_file;
58 }