sbotools2

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

02.2-unit-repo.t (4043B)


      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/../SBO-Lib/lib";
      9 use SBO::Lib qw/ do_slackbuild rsync_sbo_tree get_sbo_downloads /;
     10 use Capture::Tiny qw/ capture_merged /;
     11 use File::Path qw/ remove_tree /;
     12 
     13 if (defined $ENV{TRAVIS} and $ENV{TRAVIS} eq 'true') {
     14 	plan tests => 13;
     15 } else {
     16 	plan skip_all => 'Only run these tests under Travis CI (TRAVIS=true)';
     17 }
     18 
     19 # first set up the repo
     20 my $repo = "/usr/sbo/repo";
     21 my $moved = rename $repo, "$repo.orig";
     22 my $url = "$RealBin/02.2-unit-repo/";
     23 my $rsync_res;
     24 
     25 note "Unit repo: $url";
     26 note "rsync $url:\n" . capture_merged {
     27 	no warnings 'redefine';
     28 	local *SBO::Lib::Repo::get_slack_version = sub { '14.1' };
     29 
     30 	$rsync_res = exit_code { rsync_sbo_tree($url, 'FALSE'); };
     31 };
     32 
     33 if (defined $rsync_res) {
     34 	note "rsync exit status: $rsync_res";
     35 	rename "$repo.orig", $repo if $moved;
     36 
     37 	BAIL_OUT("rsync_sbo_tree exited");
     38 }
     39 
     40 # 1-3: test do_slackbuild() without /etc/profile.d/32dev.sh
     41 {
     42 	my $file = "/etc/profile.d/32dev.sh";
     43 	my $moved = rename $file, "$file.orig";
     44 
     45 	my ($exit, @ret);
     46 	my $out = capture_merged { $exit = exit_code { @ret = do_slackbuild(LOCATION => "/usr/sbo/repo/test/test", COMPAT32 => 1); }; };
     47 
     48 	is ($exit, undef, "do_slackbuild() didn't exit without $file.");
     49 	is ($out, "", "do_slackbuild() didn't output anything without $file.");
     50   is_deeply (\@ret, ["compat32 requires multilib.\n", undef, undef, 9], "do_slackbuild() returned the correct things without $file.");
     51 
     52 	rename "$file.orig", $file if $moved;
     53 }
     54 
     55 # 4-6: test do_slackbuild() without /usr/sbin/convertpkg-compat32
     56 SKIP: {
     57 	skip "These tests require /etc/profile.d/32dev.sh to be an existing file.", 3 unless -f "/etc/profile.d/32dev.sh";
     58 
     59 	my $file = "/usr/sbin/convertpkg-compat32";
     60 	my $moved = rename $file, "$file.orig";
     61 
     62 	my ($exit, @ret);
     63 	my $out = capture_merged { $exit = exit_code { @ret = do_slackbuild(LOCATION => "/usr/sbo/repo/test/test", COMPAT32 => 1); }; };
     64 
     65 	is ($exit, undef, "do_slackbuild() didn't exit without $file.");
     66 	is ($out, "", "do_slackbuild() didn't output anything without $file.");
     67   is_deeply (\@ret, ["compat32 requires $file.\n", undef, undef, 11], "do_slackbuild() returned the correct things without $file.");
     68 
     69 	rename "$file.orig", $file if $moved;
     70 }
     71 
     72 # 7-9: test do_slackbuild() without needed multilib
     73 {
     74 	no warnings 'redefine';
     75 
     76 	local *SBO::Lib::Build::get_arch = sub { return 'x86_64' };
     77 	local *SBO::Lib::Build::check_multilib = sub { return (); };
     78 
     79 	my ($exit, @ret);
     80 	my $out = capture_merged { $exit = exit_code { @ret = do_slackbuild(LOCATION => "/usr/sbo/repo/test/test" ); }; };
     81 
     82 	is ($exit, undef, "do_slackbuild() didn't exit without needed multilib.");
     83 	is ($out, "", "do_slackbuild() didn't output anything without needed multilib.");
     84 	is_deeply (\@ret, ["test is 32-bit which requires multilib on x86_64.\n", undef, undef, 9], "do_slackbuild() returned the correct things without needed multilib.");
     85 }
     86 
     87 # 10-12: test do_slackbuild() which thinks it's on 32bit
     88 {
     89 	no warnings 'redefine';
     90 
     91 	local *SBO::Lib::Build::get_arch = sub { return 'i586' };
     92 	local *SBO::Lib::Build::perform_sbo = sub { return 'sentinel', undef, -1 };
     93 
     94 	my ($exit, @ret);
     95 	my $out = capture_merged { $exit = exit_code { @ret = do_slackbuild(LOCATION => "/usr/sbo/repo/test/test" ); }; };
     96 
     97 	is ($exit, undef, "do_slackbuild() didn't exit when it's on 32bit.");
     98 	is ($out, "", "do_slackbuild() didn't output anything when it's on 32bit.");
     99 	is_deeply (\@ret, ["sentinel", undef, undef, -1], "do_slackbuild() returned the correct things when it's on 32bit.");
    100 }
    101 
    102 # 13: test get_sbo_downloads() which thinks it's on 32bit
    103 {
    104   no warnings 'redefine';
    105   local *SBO::Lib::Download::get_arch = sub { return 'i586' };
    106 
    107   my $ret = get_sbo_downloads(LOCATION => "/usr/sbo/repo/test/test2");
    108 
    109   ok (exists $ret->{'http://pink-mist.github.io/sbotools/testing/32/perf.dummy'}, "get_sbo_downloads() returned the correct link for 32bit.")
    110     or diag explain $ret;
    111 }
    112 
    113 remove_tree($repo);
    114 rename "$repo.orig", $repo if $moved;