]>
git.refcnt.org Git - colorize.git/blob - fail.t
d2988e496f4be49161780292cd1295c525ec6c5a
6 use constant true
=> 1;
7 use constant false
=> 0;
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);
17 my $run_program_fail = sub
19 my ($program, $message, $infile) = @_;
23 my $pid = open3
(gensym
, gensym
, $err, $program, qw(default), $infile);
26 my $output = do { local $/; <$err> };
28 return ($?
>> 8 == 1 && $output =~ /$message/) ? true
: false
;
34 my $program = tmpnam
();
35 my $conf_file = tmpnam
();
37 skip
'compiling failed (config parse failure)', $tests unless system(qq($compiler -DTEST
-DCONF_FILE_TEST
=\"$conf_file\" -o
$program $source)) == 0;
39 my $infile = $write_to_tmpfile->('');
41 my $chars_exceed = 'x' x
256;
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#', 'option \'attr\' not followed by =' ],
51 [ 'attr bold', 'option \'attr\' not followed by =' ],
52 [ "color=$chars_exceed", 'line 1 exceeds maximum of' ],
55 foreach my $set (@set) {
56 open(my $fh, '>', $conf_file) or die "Cannot open `$conf_file' for writing: $!\n";
57 print {$fh} $set->[0], "\n";
59 ok
($run_program_fail->($program, $set->[1], $infile), $set->[1]);