]> git.refcnt.org Git - colorize.git/blob - t/conf/parse/fail.t
Print line number when exceeding chars
[colorize.git] / t / conf / parse / fail.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 = 8;
16
17 my $run_program_fail = sub
18 {
19 my ($program, $message, $infile) = @_;
20
21 my $err = gensym;
22
23 my $pid = open3(gensym, gensym, $err, $program, qw(default), $infile);
24 waitpid($pid, 0);
25
26 my $output = do { local $/; <$err> };
27
28 return ($? >> 8 == 1 && $output =~ /$message/) ? true : false;
29 };
30
31 plan tests => $tests;
32
33 SKIP: {
34 my $program = tmpnam();
35 my $conf_file = tmpnam();
36
37 skip 'compiling failed (config parse failure)', $tests unless system(qq($compiler -DTEST -DCONF_FILE_TEST=\"$conf_file\" -o $program $source)) == 0;
38
39 my $infile = $write_to_tmpfile->('');
40
41 my $chars_exceed = 'x' x 256;
42
43 my @set = (
44 [ '[attr=bold', 'option \'\[attr\' cannot be made of non-option characters' ],
45 [ 'attr1=bold', 'option \'attr1\' not recognized' ],
46 [ 'color1=magenta', 'option \'color1\' not recognized' ],
47 [ 'exclude-random1=black', 'option \'exclude-random1\' not recognized' ],
48 [ 'omit-color-empty1=yes', 'option \'omit-color-empty1\' not recognized' ],
49 [ 'attr', 'option \'attr\' not followed by =' ],
50 [ 'attr bold', 'option \'attr\' not followed by =' ],
51 [ "color=$chars_exceed", 'line 1 exceeds maximum of' ],
52 );
53
54 foreach my $set (@set) {
55 open(my $fh, '>', $conf_file) or die "Cannot open `$conf_file' for writing: $!\n";
56 print {$fh} $set->[0], "\n";
57 close($fh);
58 ok($run_program_fail->($program, $set->[1], $infile), $set->[1]);
59 }
60
61 unlink $program;
62 unlink $conf_file;
63 }