]> git.refcnt.org Git - colorize.git/blob - t/conf/param.t
Add config short option -c
[colorize.git] / t / conf / param.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 = 2;
12
13 my $conf = <<'EOT';
14 attr=bold
15 color=blue
16 omit-color-empty=yes
17 EOT
18
19 my $expected = <<"EOT";
20 \e[1;34mfoo\e[0m
21
22 \e[1;34mbar\e[0m
23
24 \e[1;34mbaz\e[0m
25 EOT
26
27 plan tests => $tests;
28
29 SKIP: {
30 my $program = tmpnam();
31 my $conf_file = tmpnam();
32 # -DTEST omitted on purpose
33 skip 'compiling failed (config param)', $tests unless system(qq($compiler -o $program $source)) == 0;
34
35 my $infile = $write_to_tmpfile->(<<'EOT');
36 foo
37
38 bar
39
40 baz
41 EOT
42 open(my $fh, '>', $conf_file) or die "Cannot open `$conf_file' for writing: $!\n";
43 print {$fh} $conf;
44 close($fh);
45
46 is(qx($program -c $conf_file $infile), $expected, 'short option');
47 is(qx($program --config=$conf_file $infile), $expected, 'long option');
48
49 unlink $program;
50 unlink $conf_file;
51 }