]>
git.refcnt.org Git - colorize.git/blob - t/fail.t
6 use constant true
=> 1;
7 use constant false
=> 0;
9 use Colorize
::Common
qw(:defaults $write_to_tmpfile);
10 use File::Temp qw(tempdir tmpnam);
11 use IPC
::Open3
qw(open3);
12 use Symbol
qw(gensym);
17 my $run_program_fail = sub
19 my ($program, $args, $message) = @_;
21 my @args = split /\s+/, $args;
25 my $pid = open3
(gensym
, gensym
, $err, $program, @args);
28 my $output = do { local $/; <$err> };
30 return ($?
>> 8 == 1 && $output =~ /$message/) ? true
: false
;
36 my $program = tmpnam
();
37 skip
'compiling failed (failure exit)', $tests unless system("$compiler -DTEST -o $program $source") == 0;
39 my $file = $write_to_tmpfile->('abc');
40 my $dir = tempdir
(CLEANUP
=> true
);
43 [ '--exclude-random=random', 'must be provided a plain color' ],
44 [ '--clean --clean-all', 'mutually exclusive' ],
45 [ '--clean file1 file2', 'more than one file' ],
46 [ '--clean-all file1 file2', 'more than one file' ],
47 [ '- file', 'hyphen cannot be used as color string' ],
48 [ '-', 'hyphen must be preceded by color string' ],
49 [ "$file file", 'cannot be used as color string' ],
50 [ "$file", 'must be preceded by color string' ],
51 [ "$dir", 'is not a valid file type' ],
52 [ '/black', 'foreground color missing' ],
53 [ 'white/', 'background color missing' ],
54 [ 'white/black/yellow', 'one color pair allowed only' ],
55 [ 'y3llow', 'cannot be made of non-alphabetic characters' ],
56 [ 'yEllow', 'cannot be in mixed lower/upper case' ],
57 [ 'None', 'cannot be bold' ],
58 [ 'white/Black', 'cannot be bold' ],
59 [ 'random/none', 'cannot be combined with' ],
60 [ 'random/default', 'cannot be combined with' ],
61 [ 'none/random', 'cannot be combined with' ],
62 [ 'default/random', 'cannot be combined with' ],
64 foreach my $set (@set) {
65 ok
($run_program_fail->($program, $set->[0], $set->[1]), $set->[1]);