sbotools2

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

16-clean.t (3753B)


      1 #!/usr/bin/env perl
      2 
      3 use 5.16.0;
      4 use strict;
      5 use warnings FATAL => 'all';
      6 use Test::More;
      7 use Capture::Tiny qw/ capture_merged /;
      8 use FindBin '$RealBin';
      9 use lib $RealBin;
     10 use Test::Sbotools qw/ make_slackbuilds_txt set_pkg_dir set_distclean set_noclean set_lo sboinstall sboclean sboremove restore_perf_dummy set_sbo_home sboupgrade /;
     11 use SBO::Lib;
     12 use File::Temp 'tempdir';
     13 
     14 if ($ENV{TEST_INSTALL}) {
     15 	plan tests => 17;
     16 } else {
     17 	plan skip_all => 'Only run these tests if TEST_INSTALL=1';
     18 }
     19 
     20 my $sboname = "nonexistentslackbuild";
     21 my $perf    = "/usr/sbo/distfiles/perf.dummy";
     22 sub cleanup {
     23 	capture_merged {
     24 		system('removepkg', $sboname);
     25 		system(qw! rm -rf !, "/tmp/SBo/$sboname-1.0", "/tmp/SBo/$sboname-1.1");
     26 	}
     27 }
     28 
     29 make_slackbuilds_txt();
     30 set_lo("$RealBin/LO");
     31 set_pkg_dir("FALSE");
     32 delete $ENV{TMP};
     33 delete $ENV{OUTPUT};
     34 cleanup();
     35 restore_perf_dummy();
     36 
     37 # 1: check that build dir doesn't get cleaned
     38 set_noclean("TRUE");
     39 sboinstall '-r', $sboname, { test => 0 };
     40 ok (-e "/tmp/SBo/$sboname-1.0", "$sboname-1.0 exists when NOCLEAN set to true.");
     41 cleanup();
     42 
     43 # 2: check that build dir gets cleaned
     44 set_noclean("FALSE");
     45 sboinstall '-r', $sboname, { test => 0 };
     46 ok (!-e "/tmp/SBo/$sboname-1.0", "$sboname-1.0 is cleaned when NOCLEAN set to false.");
     47 cleanup();
     48 
     49 # 3-4: check that sboclean cleans working dir
     50 set_noclean("TRUE");
     51 sboinstall '-r', $sboname, { test => 0 };
     52 ok (-e "/tmp/SBo/$sboname-1.0", "$sboname-1.0 exists before cleaning.");
     53 sboclean '-w', { test => 0 };
     54 ok (!-e "/tmp/SBo/$sboname-1.0", "$sboname-1.0 was properly cleaned.");
     55 cleanup();
     56 
     57 # 5-6: check that sboclean cleans distfiles dir
     58 ok (-e $perf, "perf.dummy exists before cleaning distfiles.");
     59 sboclean '-d', { test => 0 };
     60 ok (!-e $perf, "perf.dummy deleted after cleaning distfiles.");
     61 restore_perf_dummy();
     62 
     63 # 7-8: check that distclean setting cleans too
     64 set_distclean("TRUE");
     65 ok (-e $perf, "perf.dummy exists before sboinstall with distclean true.");
     66 sboinstall '-r', $sboname, { test => 0 };
     67 ok (!-e $perf, "perf.dummy cleaned after install with distclean.");
     68 restore_perf_dummy();
     69 cleanup();
     70 
     71 # 9-10: check that distclean parameter cleans too
     72 set_distclean("FALSE");
     73 ok (-e $perf, "perf.dummy exists before sboinstall with -d.");
     74 sboinstall '-r', '-d', 'TRUE', $sboname, { test => 0 };
     75 ok (!-e $perf, "perf.dummy cleaned after install with -d.");
     76 restore_perf_dummy();
     77 cleanup();
     78 
     79 # 11: check that sboclean errors properly without arguments
     80 sboclean { exit => 1, expected => "You must specify at least one of -d or -w.\n" };
     81 
     82 # 12: sboclean -d with SBOHOME set
     83 set_sbo_home(tempdir(CLEANUP => 1));
     84 sboclean '-d', { exit => 0, expected => "Nothing to do.\n" };
     85 
     86 # 13-15: sboclean -w [-i] with TMP set
     87 {
     88 	local $ENV{TMP} = tempdir(CLEANUP => 1);
     89         set_sbo_home("/usr/sbo");
     90         sboinstall qw/ -r nonexistentslackbuild /, { test => 0 };
     91 	sboclean qw/ -w -i /, { input => "n", expected => qr!\QRemove $ENV{TMP}/\E.*\Q? [n]\E! };
     92 	sboclean qw/ -w -i /, { input => "y\ny", expected => qr!\QRemove $ENV{TMP}/\E.*\Q? [n]\E! };
     93 	sboclean '-w', { input => "y", expected => qr/This will remove the entire contents of \Q$ENV{TMP}\E/ };
     94 }
     95 
     96 # 16: sboupgrade -c TRUE
     97 set_sbo_home("/usr/sbo");
     98 sboinstall qw/ -r nonexistentslackbuild /, { test => 0 };
     99 set_lo "$RealBin/LO2";
    100 sboupgrade qw/ -c TRUE nonexistentslackbuild /, { input => "y\ny", test => 0 };
    101 ok (-e "/tmp/SBo/$sboname-1.1", "$sboname-1.1 exists when NOCLEAN set to true in sboupgrade.");
    102 cleanup();
    103 
    104 # 17: sboupgrade -d TRUE
    105 set_lo "$RealBin/LO";
    106 sboinstall qw/ -r nonexistentslackbuild /, { test => 0 };
    107 set_lo "$RealBin/LO2";
    108 sboupgrade qw/ -d TRUE nonexistentslackbuild /, { input => "y\ny", test => 0 };
    109 ok (!-e $perf, "perf.dummy cleaned after upgrade with -d.");
    110 restore_perf_dummy();
    111 cleanup();