]>
git.refcnt.org Git - colorize.git/blob - t/fail.t
b7f0dcbcd5882982245fdf520ce817f66daee62d
5 use constant true
=> 1;
6 use constant false
=> 0;
8 use File
::Temp
qw(tempfile tempdir tmpnam);
9 use IPC
::Open3
qw(open3);
10 use Symbol
qw(gensym);
15 my $source = 'colorize.c';
18 my $write_to_tmpfile = sub
22 my ($fh, $tmpfile) = tempfile
(UNLINK
=> true
);
29 my $run_program_fail = sub
31 my ($program, $args, $message) = @_;
33 my @args = split /\s+/, $args;
37 my $pid = open3
(gensym
, gensym
, $err, $program, @args);
40 my $output = do { local $/; <$err> };
42 return ($?
>> 8 == 1 && $output =~ /$message/) ? true
: false
;
48 my $program = tmpnam
();
49 skip
'compiling failed (failure exit)', $tests unless system("$compiler -DTEST -o $program $source") == 0;
51 my $file = $write_to_tmpfile->('abc');
52 my $dir = tempdir
(CLEANUP
=> true
);
55 [ '--exclude-random=random', 'must be provided a plain color' ],
56 [ '--clean --clean-all', 'mutually exclusive' ],
57 [ '--clean file1 file2', 'more than one file' ],
58 [ '--clean-all file1 file2', 'more than one file' ],
59 [ '- file', 'hyphen cannot be used as color string' ],
60 [ '-', 'hyphen must be preceeded by color string' ],
61 [ "$file file", 'cannot be used as color string' ],
62 [ "$file", 'must be preceeded by color string' ],
63 [ "$dir", 'is not a valid file type' ],
64 [ '/black', 'foreground color missing' ],
65 [ 'white/', 'background color missing' ],
66 [ 'white/black/yellow', 'one color pair allowed only' ],
67 [ 'y3llow', 'cannot be made of non-alphabetic characters' ],
68 [ 'yEllow', 'cannot be in mixed lower/upper case' ],
69 [ 'None', 'cannot be bold' ],
70 [ 'white/Black', 'cannot be bold' ],
71 [ 'random/none', 'cannot be combined with' ],
72 [ 'random/default', 'cannot be combined with' ],
73 [ 'none/random', 'cannot be combined with' ],
74 [ 'default/random', 'cannot be combined with' ],
76 foreach my $set (@set) {
77 ok
($run_program_fail->($program, $set->[0], $set->[1]), $set->[1]);