]> git.refcnt.org Git - colorize.git/blob - t/conf/use.t
Add new test files
[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 # tested also in color.t
16 omit-color-empty=yes
17 EOT
18
19 plan tests => $tests;
20
21 SKIP: {
22 my $program = tmpnam();
23 my $conf_file = tmpnam();
24
25 skip 'compiling failed (use config)', $tests unless system(qq($compiler -DTEST -DCONF_FILE_TEST=\"$conf_file\" -o $program $source)) == 0;
26
27 my $infile1 = $write_to_tmpfile->(<<'EOT');
28 foo
29
30 bar
31
32 baz
33 EOT
34 open(my $fh, '>', $conf_file) or die "Cannot open `$conf_file' for writing: $!\n";
35 print {$fh} $conf;
36 close($fh);
37
38 is(qx($program $infile1), <<"EOT", 'use config');
39 \e[4;33mfoo\e[0m
40
41 \e[4;33mbar\e[0m
42
43 \e[4;33mbaz\e[0m
44 EOT
45 my $infile2 = $write_to_tmpfile->('foo');
46
47 open($fh, '>', $conf_file) or die "Cannot open `$conf_file' for writing: $!\n";
48 print {$fh} "exclude-random=black\n";
49 close($fh);
50
51 for (my $i = 1; $i <= 20; $i++) {
52 like(qx($program random $infile2), qr/^\e\[3[1-7]mfoo\e\[0m$/, 'use exclude-random');
53 }
54
55 unlink $program;
56 unlink $conf_file;
57 }