05-upgrade.t (8405B)
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_gpg_verify set_lo sboconfig sboinstall sboupgrade restore_perf_dummy set_repo sbosnap /; 11 use File::Temp 'tempdir'; 12 13 if ($ENV{TEST_INSTALL}) { 14 plan tests => 22; 15 } else { 16 plan skip_all => 'Only run these tests if TEST_INSTALL=1'; 17 } 18 $ENV{TEST_ONLINE} //= 0; 19 20 sub cleanup { 21 capture_merged { 22 system(qw!/sbin/removepkg nonexistentslackbuild!); 23 system(qw!/sbin/removepkg nonexistentslackbuild2!); 24 system(qw!/sbin/removepkg nonexistentslackbuild4!); 25 system(qw!/sbin/removepkg nonexistentslackbuild5!); 26 system(qw!/sbin/removepkg nonexistentslackbuild6!); 27 system(qw!/sbin/removepkg weird-versionsbo!); 28 system(qw!/sbin/removepkg locale-versionsbo!); 29 unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; 30 unlink "$RealBin/LO/nonexistentslackbuild2/perf.dummy"; 31 unlink "$RealBin/LO/nonexistentslackbuild4/perf.dummy"; 32 unlink "$RealBin/LO/nonexistentslackbuild5/perf.dummy"; 33 unlink "$RealBin/LO/nonexistentslackbuild6/perf.dummy"; 34 unlink "$RealBin/LO/weird-versionsbo/perf.dummy"; 35 unlink "$RealBin/LO/locale-versionsbo/perf.dummy"; 36 unlink "$RealBin/LO2/nonexistentslackbuild/perf.dummy"; 37 unlink "$RealBin/LO2/nonexistentslackbuild2/perf.dummy"; 38 unlink "$RealBin/LO2/nonexistentslackbuild4/perf.dummy"; 39 unlink "$RealBin/LO2/nonexistentslackbuild5/perf.dummy"; 40 unlink "$RealBin/LO2/nonexistentslackbuild6/perf.dummy"; 41 unlink "$RealBin/LO3/nonexistentslackbuild/perf.dummy"; 42 unlink "$RealBin/LO3/nonexistentslackbuild4/perf.dummy"; 43 unlink "$RealBin/LO3/nonexistentslackbuild5/perf.dummy"; 44 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-0.9!); 45 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild2-0.9!); 46 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-0.9!); 47 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-0.9!); 48 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild6-0.9!); 49 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.0!); 50 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild2-1.0!); 51 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.0!); 52 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-1.0!); 53 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild6-1.0!); 54 system(qw!rm -rf /tmp/SBo/weird-versionsbo-1.0!); 55 system(qw!rm -rf /tmp/SBo/locale-versionsbo-1.0!); 56 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.1!); 57 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild2-1.1!); 58 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.1!); 59 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-1.1!); 60 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild6-1.1!); 61 system(qw!rm -rf /tmp/package-nonexistentslackbuild!); 62 system(qw!rm -rf /tmp/package-nonexistentslackbuild2!); 63 system(qw!rm -rf /tmp/package-nonexistentslackbuild4!); 64 system(qw!rm -rf /tmp/package-nonexistentslackbuild5!); 65 system(qw!rm -rf /tmp/package-nonexistentslackbuild6!); 66 system(qw!rm -rf /tmp/package-weird-versionsbo!); 67 system(qw!rm -rf /tmp/package-locale-versionsbo!); 68 }; 69 } 70 71 cleanup(); 72 make_slackbuilds_txt(); 73 set_gpg_verify('FALSE'); 74 set_lo("$RealBin/LO"); 75 restore_perf_dummy(); 76 77 sub install { 78 cleanup(); 79 my $lo = shift; 80 my @pkgs = @_; 81 82 sboconfig '-o', "$RealBin/LO", { test => 0 }; 83 for my $pkg (@pkgs) { 84 sboinstall '-r', $pkg, { test => 0 }; 85 } 86 sboconfig '-o', "$RealBin/$lo", { test => 0 }; 87 } 88 89 # 1-2: sboupgrade nonexistentslackbuild when it doesn't need to be upgraded 90 install( 'LO', 'nonexistentslackbuild' ); 91 sboupgrade 'nonexistentslackbuild', { expected => '' }; 92 sboupgrade qw/ -f nonexistentslackbuild /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild\b.*Upgrade queue: nonexistentslackbuild\n/s }; 93 94 # 3-7: sboupgrade nonexistentslackbuild4 and 5 when they don't need to be upgraded 95 install( 'LO', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); 96 sboupgrade 'nonexistentslackbuild4', { expected => '' }; 97 sboupgrade qw/ nonexistentslackbuild5 /, { expected => '' }; 98 sboupgrade qw/ -f nonexistentslackbuild4 /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild4\b.*Upgrade queue: nonexistentslackbuild4\n/s }; 99 sboupgrade qw/ -f nonexistentslackbuild5 /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Upgrade queue: nonexistentslackbuild5\n/s }; 100 sboupgrade qw/ -f -z nonexistentslackbuild4 /, { input => "y\ny\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Proceed with nonexistentslackbuild4\b.*Upgrade queue: nonexistentslackbuild5 nonexistentslackbuild4\n/s }; 101 102 # 8: sboupgrade works with nonexistentslackbuild6 103 install( 'LO2', 'nonexistentslackbuild6' ); 104 sboupgrade 'nonexistentslackbuild6', { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild6\b.*Upgrade queue: nonexistentslackbuild6\n/s }; 105 106 # 9: sboupgrade nonexistentslackbuild when it needs to be upgraded 107 install( 'LO2', 'nonexistentslackbuild' ); 108 sboupgrade 'nonexistentslackbuild', { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild\b.*Upgrade queue: nonexistentslackbuild\n/s }; 109 110 # 10: sboupgrade nonexistentslackbuild4 and 5 when they need to be upgraded 111 install( 'LO2', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); 112 sboupgrade 'nonexistentslackbuild4', { input => "y\ny\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Proceed with nonexistentslackbuild4\b.*Upgrade queue: nonexistentslackbuild5 nonexistentslackbuild4\n/s }; 113 114 # 11-12: sboupgrade nonexistentslackbuild4 and 5 when only 5 needs an update 115 install( 'LO3', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); 116 sboupgrade 'nonexistentslackbuild4', { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Upgrade queue: nonexistentslackbuild5\n/s }; 117 install( 'LO3', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); 118 sboupgrade qw/ -f nonexistentslackbuild4 /, { input => "y\ny\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Proceed with nonexistentslackbuild4\b.*Upgrade queue: nonexistentslackbuild5 nonexistentslackbuild4\n/s }; 119 120 # 13-16: sbosnap + sboupgrade --all 121 my $temp = tempdir(CLEANUP => 1); 122 set_repo("file://$temp"); 123 capture_merged { system(<<"END"); }; 124 cd "$temp"; 125 git init; 126 echo hello > README.txt; 127 git add README.txt; 128 git commit -am init; 129 END 130 sbosnap 'fetch', { expected => qr/Pulling SlackBuilds tree[.][.][.]/ }; 131 install( 'LO2', 'nonexistentslackbuild' ); 132 my @sbos = glob("/var/log/packages/*_SBo"); 133 sboupgrade '--all', { input => ("n\n" x (@sbos+1)), expected => qr/Proceed with nonexistentslackbuild\b/ }; 134 install( 'LO2', 'nonexistentslackbuild', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); 135 sboupgrade '--all', { input => ("n\n" x (@sbos+3)), expected => qr/Proceed with nonexistentslackbuild\b.*Proceed with nonexistentslackbuild5\b.*Proceed with nonexistentslackbuild4\b/s }; 136 set_lo("$RealBin/LO"); 137 sboupgrade '--all', { expected => "Checking for updated SlackBuilds...\nNothing to update.\n" }; 138 139 cleanup(); 140 141 # 17: sboupgrade --all shouldn't pick up weird-versionsbo or locale-versionsbo 142 install('LO', 'weird-versionsbo', 'locale-versionsbo'); 143 sboupgrade '--all', { input => ("n\n" x (@sbos+1)), expected => sub { not /weird-versionsbo/ and not /locale-versionsbo/ } }; 144 145 # 18-19: sboupgrade -r -f both something installed and something not installed 146 install('LO', 'nonexistentslackbuild'); 147 sboupgrade qw/ -r -f nonexistentslackbuild /, { expected => qr/^Upgrade queue: nonexistentslackbuild$/m }; 148 sboupgrade qw/ -r -f nonexistentslackbuild2 /, { expected => "" }; 149 150 # 20: sboupgrade -r on something already up to date 151 sboupgrade qw/ -r nonexistentslackbuild /, { expected => "" }; 152 153 # 21: sboupgrade and answer weirdly and use a default and then answer no twice 154 install('LO2', 'nonexistentslackbuild', 'nonexistentslackbuild5'); 155 sboupgrade qw/nonexistentslackbuild nonexistentslackbuild5/, { input => "foo\n\nn\nn\n", expected => qr/Proceed with nonexistentslackbuild\?.*Proceed with nonexistentslackbuild\?.*Proceed with nonexistentslackbuild5\?.*Upgrade queue: nonexistentslackbuild$/sm }; 156 157 # 22: sboupgrade on something installed with no-longer-existing dep 158 install('LO', 'nonexistentslackbuild2'); 159 sboupgrade qw/ -f -z nonexistentslackbuild2 /, { input => "n", expected => "Unable to locate nonexistentslackbuild3 in the SlackBuilds.org tree.\nDo you want to ignore it and continue? [n] " }; 160 161 # Cleanup 162 END { 163 cleanup(); 164 }