sbotools2

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

28-race-sboremove.t (1372B)


      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 Capture::Tiny qw/ capture_merged /;
     10 use File::Temp 'tempdir';
     11 use Cwd;
     12 use feature 'state';
     13 use Test::Sbotools qw/ set_repo set_lo sboconfig sboinstall sbosnap load /;
     14 
     15 if ($ENV{TEST_INSTALL}) {
     16 	plan tests => 2;
     17 } else {
     18 	plan skip_all => 'Only run these tests if TEST_INSTALL=1';
     19 }
     20 
     21 set_lo("$RealBin/LO2");
     22 
     23 # set up git repo with readme slackbuild
     24 my $tempdir = tempdir(CLEANUP => 0);
     25 capture_merged { system <<"GIT"; };
     26 cd $tempdir
     27 git init
     28 mkdir test
     29 cp -a "$RealBin/LO/nonexistentslackbuild8/" test
     30 git add test
     31 git commit -m 'first commit'
     32 GIT
     33 set_repo("file://$tempdir");
     34 
     35 sboconfig qw/ --gpg-key FALSE /, { test => 0 };
     36 sbosnap 'fetch', { test => 0 };
     37 
     38 # install the readme slackbuild
     39 sboinstall 'nonexistentslackbuild8', { input => "y\ny", test => 0 };
     40 
     41 { package STDINTIE;
     42 	sub TIEHANDLE { bless {}, shift; }
     43 	sub READLINE {
     44 		no warnings 'once', 'redefine';
     45 		*_race::cond = sub {
     46 			unlink "/usr/sbo/repo/test/nonexistentslackbuild8/README";
     47 		};
     48 		"y\n";
     49 	}
     50 }
     51 
     52 tie *STDIN, 'STDINTIE';
     53 
     54 my $res = load('sboremove', argv => ['nonexistentslackbuild8']);
     55 
     56 like ($res->{out}, qr/Unable to open README for nonexistentslackbuild8\./, 'sboremove output with race condition correct');
     57 is ($res->{exit}, 0, 'sboremove did not exit in error');