diff options
| author | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2016-05-26 00:26:48 +0200 | 
|---|---|---|
| committer | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2016-05-26 00:26:48 +0200 | 
| commit | da2f4da2ffe22ba9d4704f46b31b50c2d368fe3f (patch) | |
| tree | 5a5ae18abdce29a2becbcfdc6b520dd2b1d7ac2f | |
| parent | 3204f1b97fb828a7db0b133ca54cd74ea699cb62 (diff) | |
| download | sbotools2-da2f4da2ffe22ba9d4704f46b31b50c2d368fe3f.tar.xz | |
22-race.t: add tests for exit branch in get_slack_version()
| -rwxr-xr-x | t/22-race.t | 22 | 
1 files changed, 20 insertions, 2 deletions
diff --git a/t/22-race.t b/t/22-race.t index 7fbe081..920635e 100755 --- a/t/22-race.t +++ b/t/22-race.t @@ -6,11 +6,11 @@ use Test::More;  use Test::Exit;  use FindBin '$RealBin';  use lib "$RealBin/../SBO-Lib/lib"; -use SBO::Lib qw/ open_fh /; +use SBO::Lib qw/ open_fh %config /;  use Capture::Tiny qw/ capture_merged /;  use File::Temp 'tempdir'; -plan tests => 2; +plan tests => 4;  sub emulate_race {  	my ($file, $caller) = @_; @@ -46,3 +46,21 @@ sub emulate_race {  	system('mv', "$conf_file.bak", $conf_file) if -e "$conf_file.bak";  } + +# 3-4: emulate race in open_fh by get_slack_version +{ +	my $sv_file = '/etc/slackware-version'; +	system('mkdir', '-p', '/etc'); +	system('mv', $sv_file, "$sv_file.bak"); +	system('touch', $sv_file); + +	my $exit; +	emulate_race($sv_file, 'open_fh'); +	local $config{SLACKWARE_VERSION} = 'FALSE'; +	my $out = capture_merged { $exit = exit_code { SBO::Lib::get_slack_version(); }; }; + +	is ($exit, 6, 'get_slackware_version() exited with correct exitcode'); +	is ($out, "Unable to open $sv_file.\n", 'get_slackware_version output correct'); + +	system('mv', "$sv_file.bak", $sv_file) if -e "$sv_file.bak"; +}  | 
