]>
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 [ '--attr=:', 'must be provided a string' ],
44 [ '--attr=bold:underscore', 'must have strings separated by ,' ],
45 [ '--attr=b0ld', 'attribute \'b0ld\' is not valid' ],
46 [ '--attr=b0ld,underscore', 'attribute \'b0ld\' is not valid' ], # handle comma
47 [ '--attr=bold,bold', 'has attribute \'bold\' twice or more' ],
48 [ '--exclude-random=random', 'must be provided a plain color' ],
49 [ '--clean --clean-all', 'mutually exclusive' ],
50 [ '--clean file1 file2', 'more than one file' ],
51 [ '--clean-all file1 file2', 'more than one file' ],
52 [ '- file', 'hyphen cannot be used as color string' ],
53 [ '-', 'hyphen must be preceded by color string' ],
54 [ "$file file", 'cannot be used as color string' ],
55 [ "$file", 'must be preceded by color string' ],
56 [ "$dir", 'is not a valid file type' ],
57 [ '/black', 'foreground color missing' ],
58 [ 'white/', 'background color missing' ],
59 [ 'white/black/yellow', 'one color pair allowed only' ],
60 [ 'y3llow', 'cannot be made of non-alphabetic characters' ],
61 [ 'yEllow', 'cannot be in mixed lower/upper case' ],
62 [ 'None', 'cannot be bold' ],
63 [ 'white/Black', 'cannot be bold' ],
64 [ 'random/none', 'cannot be combined with' ],
65 [ 'random/default', 'cannot be combined with' ],
66 [ 'none/random', 'cannot be combined with' ],
67 [ 'default/random', 'cannot be combined with' ],
69 foreach my $set (@set) {
70 ok
($run_program_fail->($program, $set->[0], $set->[1]), $set->[1]);