aboutsummaryrefslogtreecommitdiffstats
path: root/t/conf/fail.t
diff options
context:
space:
mode:
authorGravatar Steven Schubiger <stsc@refcnt.org> 2019-09-13 21:15:22 +0200
committerGravatar Steven Schubiger <stsc@refcnt.org> 2019-09-13 21:15:22 +0200
commitb5ff1ba35b959261c855262b6e820732e72b0bfe (patch)
treeb5b0cdc7ec3438b441e736d56bccf44785ae96ae /t/conf/fail.t
parent763a5a99b3af4161cd1dd4c7ee2c450c4b6137a5 (diff)
parent660177bb22c5b8b54c0ec3aabd1930fd49584e23 (diff)
downloadcolorize-b5ff1ba35b959261c855262b6e820732e72b0bfe.tar.gz
colorize-b5ff1ba35b959261c855262b6e820732e72b0bfe.tar.bz2
Merge branch 'config_file'
Diffstat (limited to 't/conf/fail.t')
-rwxr-xr-xt/conf/fail.t59
1 files changed, 59 insertions, 0 deletions
diff --git a/t/conf/fail.t b/t/conf/fail.t
new file mode 100755
index 0000000..d3b8852
--- /dev/null
+++ b/t/conf/fail.t
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use lib qw(lib);
+use constant true => 1;
+use constant false => 0;
+
+use Colorize::Common qw(:defaults $write_to_tmpfile);
+use File::Temp qw(tmpnam);
+use IPC::Open3 qw(open3);
+use Symbol qw(gensym);
+use Test::More;
+
+my $tests = 7;
+
+my $run_program_fail = sub
+{
+ my ($program, $message, $infile) = @_;
+
+ my $err = gensym;
+
+ my $pid = open3(gensym, gensym, $err, $program, qw(default), $infile);
+ waitpid($pid, 0);
+
+ my $output = do { local $/; <$err> };
+
+ return ($? >> 8 == 1 && $output =~ /$message/) ? true : false;
+};
+
+plan tests => $tests;
+
+SKIP: {
+ my $program = tmpnam();
+ my $conf_file = tmpnam();
+
+ skip 'compiling failed (config failure exit)', $tests unless system(qq($compiler -DTEST -DCONF_FILE_TEST=\"$conf_file\" -o $program $source)) == 0;
+
+ my $infile = $write_to_tmpfile->('');
+
+ my @set = (
+ [ 'attr=:', 'attr conf option must be provided a string' ],
+ [ 'attr=bold:underscore', 'attr conf option must have strings separated by ,' ],
+ [ 'attr=b0ld', 'attr conf option attribute \'b0ld\' is not valid' ],
+ [ 'attr=b0ld,underscore', 'attr conf option attribute \'b0ld\' is not valid' ], # handle comma
+ [ 'attr=bold,bold', 'attr conf option has attribute \'bold\' twice or more' ],
+ [ 'exclude-random=random', 'exclude-random conf option must be provided a plain color' ],
+ [ 'omit-color-empty=unsure', 'omit-color-empty conf option is not valid' ],
+ );
+ foreach my $set (@set) {
+ open(my $fh, '>', $conf_file) or die "Cannot open `$conf_file' for writing: $!\n";
+ print {$fh} $set->[0], "\n";
+ close($fh);
+ ok($run_program_fail->($program, $set->[1], $infile), $set->[1]);
+ }
+
+ unlink $program;
+ unlink $conf_file;
+}