sbotools2

Maintenance fork of the original sbotools version 2
Log | Files | Refs | README

commit 6dca3f44bb6889d3cef9387f0cfd0364b875237c
parent 72f21da8bc788ab5435c0101e43386c01dfff427
Author: Andreas Guldstrand <andreas.guldstrand@gmail.com>
Date:   Fri, 10 Jun 2016 01:17:25 +0200

26-race-sbocheck.t: add test for not being able to write logfile

Diffstat:
At/26-race-sbocheck.t | 47+++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+), 0 deletions(-)

diff --git a/t/26-race-sbocheck.t b/t/26-race-sbocheck.t @@ -0,0 +1,47 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use Test::Exit; +use FindBin '$RealBin'; +use lib "$RealBin/../SBO-Lib/lib"; +use Capture::Tiny qw/ capture_merged /; +use File::Temp 'tempdir'; +use Cwd; + +plan tests => 2; + +sub load { + my ($script, %opts) = @_; + + local @ARGV = exists $opts{argv} ? @{ $opts{argv} } : '-h'; + my ($ret, $exit, $out, $do_err); + my $eval = eval { + $out = capture_merged { $exit = exit_code { + $ret = do "$RealBin/../$script"; + $do_err = $@; + }; }; + 1; + }; + my $err = $@; + + note explain { ret => $ret, exit => $exit, out => $out, eval => $eval, err => $err, do_err => $do_err } if $opts{explain}; +} + +# 1-2: sboconfig unit tests... +{ + load('sbocheck'); + + my $logfile = '/var/log/sbocheck.log'; + unlink $logfile; + mkdir $logfile; + + my $exit; + my $out = capture_merged { $exit = exit_code { main::print_output('foo'); }; }; + + like ($out, qr/\QUnable to open $logfile./, "sbocheck's print_output() gave correct output"); + is ($exit, undef, "sbocheck's print_output() didn't exit"); + + unlink $logfile; +}