diff options
| author | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2016-06-05 03:21:06 +0200 | 
|---|---|---|
| committer | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2016-06-05 03:21:06 +0200 | 
| commit | bd417b768e84cf733d0b5813545107c95953ba05 (patch) | |
| tree | e4fe611bf9215e0840399aa82031c6d469ae42dc | |
| parent | fda0360e34556d205ea05f2bbe5671679b3e7129 (diff) | |
| download | sbotools2-bd417b768e84cf733d0b5813545107c95953ba05.tar.xz | |
01-unit.t: separate out the sboclean and sboconfig unit tests into their own files
| -rwxr-xr-x | t/01-unit.t | 51 | ||||
| -rwxr-xr-x | t/23-unit-sboclean.t | 49 | ||||
| -rwxr-xr-x | t/24-unit-sboconfig.t | 42 | 
3 files changed, 92 insertions, 50 deletions
diff --git a/t/01-unit.t b/t/01-unit.t index 1c29de2..4c735dd 100755 --- a/t/01-unit.t +++ b/t/01-unit.t @@ -11,25 +11,7 @@ use Capture::Tiny qw/ capture_merged /;  use File::Temp 'tempdir';  use Cwd; -plan tests => 61; - -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}; -} - +plan tests => 55;  # 1-2: test script_error();  { @@ -321,34 +303,3 @@ SKIP: {  	is ($res[1], undef, 'perform_sbo returned correct src');  	is ($res[2], 6, 'perform_sbo returned correct exit');  } - -# 56-59: sboclean unit tests... -{ -	local (*main::show_usage, *main::rm_full, *main::remove_stuff, *main::clean_c32); -	load('sboclean'); - -	my $exit; -	my $out = capture_merged { $exit = exit_code { main::rm_full(); }; }; - -	is ($out, "A fatal script error has occurred:\nrm_full requires an argument.\nExiting.\n", "sboclean's rm_full() gave correct output"); -	is ($exit, 2, "sboclean's rm_full() gave correct exit status"); - -	undef $exit; -	undef $out; -	$out = capture_merged { $exit = exit_code { main::remove_stuff(); }; }; - -	is ($out, "A fatal script error has occurred:\nremove_stuff requires an argument.\nExiting.\n", "sboclean's remove_stuff() gave correct output"); -	is ($exit, 2, "sboclean's remove_stuff() gave correct exit status"); -} - -# 60-61: sboconfig unit tests... -{ -	local (*main::show_usage, *main::config_write); -	load('sboconfig'); - -	my $exit; -	my $out = capture_merged { $exit = exit_code { main::config_write(); }; }; - -	is ($out, "A fatal script error has occurred:\nconfig_write requires two arguments.\nExiting.\n", "sboconfig's config_write() gave correct output"); -	is ($exit, 2, "sboconfig's config_write() gave correct exit status"); -} diff --git a/t/23-unit-sboclean.t b/t/23-unit-sboclean.t new file mode 100755 index 0000000..399eedc --- /dev/null +++ b/t/23-unit-sboclean.t @@ -0,0 +1,49 @@ +#!/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 => 4; + +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-4: sboclean unit tests... +{ +	local (*main::show_usage, *main::rm_full, *main::remove_stuff, *main::clean_c32); +	load('sboclean'); + +	my $exit; +	my $out = capture_merged { $exit = exit_code { main::rm_full(); }; }; + +	is ($out, "A fatal script error has occurred:\nrm_full requires an argument.\nExiting.\n", "sboclean's rm_full() gave correct output"); +	is ($exit, 2, "sboclean's rm_full() gave correct exit status"); + +	undef $exit; +	undef $out; +	$out = capture_merged { $exit = exit_code { main::remove_stuff(); }; }; + +	is ($out, "A fatal script error has occurred:\nremove_stuff requires an argument.\nExiting.\n", "sboclean's remove_stuff() gave correct output"); +	is ($exit, 2, "sboclean's remove_stuff() gave correct exit status"); +} diff --git a/t/24-unit-sboconfig.t b/t/24-unit-sboconfig.t new file mode 100755 index 0000000..90008da --- /dev/null +++ b/t/24-unit-sboconfig.t @@ -0,0 +1,42 @@ +#!/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... +{ +	local (*main::show_usage, *main::config_write); +	load('sboconfig'); + +	my $exit; +	my $out = capture_merged { $exit = exit_code { main::config_write(); }; }; + +	is ($out, "A fatal script error has occurred:\nconfig_write requires two arguments.\nExiting.\n", "sboconfig's config_write() gave correct output"); +	is ($exit, 2, "sboconfig's config_write() gave correct exit status"); +}  | 
