]> git.refcnt.org Git - colorize.git/blob - t/conf/parse/success.t
Add new test files
[colorize.git] / t / conf / parse / success.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use lib qw(lib);
6 use constant true => 1;
7 use constant false => 0;
8
9 use Colorize::Common qw(:defaults $write_to_tmpfile);
10 use File::Temp qw(tmpnam);
11 use IPC::Open3 qw(open3);
12 use Symbol qw(gensym);
13 use Test::More;
14
15 my $tests = 21;
16
17 my $conf = <<'EOT';
18 # comment
19 # comment
20 # comment
21 attr=bold
22 attr =bold
23 attr= bold
24 attr =bold
25 attr= bold
26 attr = bold
27 color=green
28 color=green
29 color=green
30 color=green
31 exclude-random=black
32 omit-color-empty=yes
33 attr=bold # comment
34 attr=bold # comment
35 attr=
36 color=
37 exclude-random=
38 omit-color-empty=
39 EOT
40
41 my $run_program_succeed = sub
42 {
43 my ($program, $infile) = @_;
44
45 my $err = gensym;
46
47 my $pid = open3(gensym, gensym, $err, $program, qw(default), $infile);
48 waitpid($pid, 0);
49
50 my $output = do { local $/; <$err> };
51
52 return ($? >> 8 == 0 && $output eq '') ? true : false;
53 };
54
55 plan tests => $tests;
56
57 SKIP: {
58 my $program = tmpnam();
59 my $conf_file = tmpnam();
60
61 skip 'compiling failed (config parse success)', $tests unless system(qq($compiler -DTEST -DCONF_FILE_TEST=\"$conf_file\" -o $program $source)) == 0;
62
63 my $infile = $write_to_tmpfile->('');
64
65 foreach my $line (split /\n/, $conf) {
66 open(my $fh, '>', $conf_file) or die "Cannot open `$conf_file' for writing: $!\n";
67 print {$fh} $line, "\n";
68 close($fh);
69 ok($run_program_succeed->($program, $infile), $line);
70 }
71
72 unlink $program;
73 unlink $conf_file;
74 }