sbotools2

Maintenance fork of the original sbotools version 2
git clone git://git.server.ky/slackcoder/sbotools2
Log | Files | Refs | README

27-race-sbofind.t (2374B)


      1 #!/usr/bin/env perl
      2 
      3 use strict;
      4 use warnings;
      5 use Test::More;
      6 use Test::Exit;
      7 use FindBin '$RealBin';
      8 use lib $RealBin;
      9 use Test::Sbotools qw/set_gpg_verify load sbosnap/;
     10 use Capture::Tiny qw/ capture_merged /;
     11 use File::Temp 'tempdir';
     12 use Cwd;
     13 use feature 'state';
     14 
     15 plan tests => 9;
     16 
     17 set_gpg_verify('FALSE');
     18 load('sbofind');
     19 my $tags_file = '/usr/sbo/repo/TAGS.txt';
     20 
     21 # Test may be run by itself
     22 sbosnap 'fetch', { test => 0 } if not -d '/usr/sbo/repo';
     23 
     24 # 1: tags file
     25 {
     26 	rename $tags_file, "$tags_file.bak";
     27 	system 'touch', $tags_file;
     28 
     29 	no warnings 'redefine';
     30 	local *_race::cond = sub {
     31 		if ($_[0] eq '$tags_file may be deleted after -f check') {
     32 			local *_race::cond = sub {
     33 				if ($_[0] eq '$file could be deleted between -f test and open') {
     34 					unlink $tags_file;
     35 				}
     36 			};
     37 		}
     38 	};
     39 
     40 	my $exit;
     41 	capture_merged { $exit = exit_code { perform_search('foo'); }; };
     42 
     43 	is ($exit, undef, "perform_search didn't exit");
     44 
     45 	rename "$tags_file.bak", $tags_file;
     46 }
     47 
     48 # 2-3: slackbuilds.txt file
     49 {
     50 	my $sbt = '/usr/sbo/repo/SLACKBUILDS.TXT';
     51 	system('touch', $tags_file) unless -f $tags_file;
     52 
     53 	no warnings 'redefine';
     54 	local *_race::cond = sub {
     55 		if ($_[0] eq '$file could be deleted between -f test and open') {
     56 			state $num++;
     57 			rename $sbt, "$sbt.bak" if $num == 2;
     58 		}
     59 	};
     60 
     61 	my $exit;
     62 	my $out = capture_merged { $exit = exit_code { perform_search('foo'); }; };
     63 
     64 	is ($out, "Unable to open $sbt.\n", "perform_search gave correct output");
     65 	is ($exit, 6, "perform_search exited with 6");
     66 
     67 	rename "$sbt.bak", $sbt;
     68 }
     69 
     70 # 4-9: get_file_contents
     71 {
     72 	my $file = tempdir(CLEANUP => 1) . "/foo";
     73 
     74 	my ($exit, $ret);
     75 	my $out = capture_merged { $exit = exit_code { $ret = get_file_contents($file); }; };
     76 
     77 	is ($out, '', 'get_file_contents gave no output');
     78 	is ($ret, "Unable to open $file.\n", 'get_file_contents returned correctly');
     79 	is ($exit, undef, 'get_file_contents didn\'t exit');
     80 
     81 	system 'touch', $file;
     82 
     83 	no warnings 'redefine';
     84 	local *_race::cond = sub {
     85 		if ($_[0] eq '$file could be deleted between -f test and open') {
     86 			unlink $file;
     87 		}
     88 	};
     89 
     90 	undef $exit;
     91 	undef $ret;
     92 	$out = capture_merged { $exit = exit_code { $ret = get_file_contents($file); }; };
     93 
     94 	is ($out, '', 'get_file_contents gave no output');
     95 	is ($ret, "Unable to open $file.\n", 'get_file_contents returned correctly');
     96 	is ($exit, undef, 'get_file_contents still didn\'t exit');
     97 }