08-env.t (5792B)
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_lo sboinstall restore_perf_dummy /; 11 12 if ($ENV{TEST_INSTALL}) { 13 plan tests => 5; 14 } else { 15 plan skip_all => 'Only run these tests if TEST_INSTALL=1'; 16 } 17 $ENV{TEST_ONLINE} //= 0; 18 19 sub cleanup { 20 my $tmp = shift; 21 my $output = shift; 22 capture_merged { 23 system(qw!/sbin/removepkg nonexistentslackbuild!); 24 system(qw!/sbin/removepkg nonexistentslackbuild4!); 25 system(qw!/sbin/removepkg nonexistentslackbuild5!); 26 unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; 27 unlink "$RealBin/LO/nonexistentslackbuild4/perf.dummy"; 28 unlink "$RealBin/LO/nonexistentslackbuild5/perf.dummy"; 29 system(qw!rm -rf!, "$tmp/nonexistentslackbuild-1.0"); 30 system(qw!rm -rf!, "$tmp/nonexistentslackbuild4-1.0"); 31 system(qw!rm -rf!, "$tmp/nonexistentslackbuild5-1.0"); 32 system(qw!rm -rf!, "$output/package-nonexistentslackbuild"); 33 system(qw!rm -rf!, "$output/package-nonexistentslackbuild4"); 34 system(qw!rm -rf!, "$output/package-nonexistentslackbuild5"); 35 }; 36 } 37 38 cleanup('/tmp/SBo', '/tmp'); 39 make_slackbuilds_txt(); 40 set_lo("$RealBin/LO"); 41 restore_perf_dummy(); 42 43 SKIP: { 44 skip "Not testing unset OUTPUT", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne ''; 45 subtest 'OUTPUT unset', 46 sub { 47 delete local $ENV{OUTPUT}; 48 tmp_tests(); 49 }; 50 } 51 52 SKIP: { 53 skip "Not testing OUTPUT=/tmp", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne '/tmp'; 54 subtest 'OUTPUT=/tmp', 55 sub { 56 local $ENV{OUTPUT}='/tmp'; 57 tmp_tests(); 58 }; 59 } 60 61 SKIP: { 62 skip "Not testing OUTPUT=/tmp", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne '/tmp/SBo'; 63 subtest 'OUTPUT=/tmp/SBo', 64 sub { 65 local $ENV{OUTPUT}='/tmp/SBo'; 66 tmp_tests(); 67 }; 68 } 69 70 SKIP: { 71 skip "Not testing OUTPUT=/tmp/foo", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne '/tmp/foo'; 72 subtest 'OUTPUT=/tmp/foo', 73 sub { 74 local $ENV{OUTPUT}='/tmp/foo'; 75 tmp_tests(); 76 }; 77 } 78 79 SKIP: { 80 skip "Not testing OUTPUT=/tmp/bar", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne '/tmp/bar'; 81 subtest 'OUTPUT=/tmp/bar', 82 sub { 83 local $ENV{OUTPUT}='/tmp/bar'; 84 tmp_tests(); 85 }; 86 } 87 88 sub tmp_tests { 89 plan tests => 4; 90 91 SKIP: { 92 skip "Not testing unset TMP", 1 if exists $ENV{TEST_TMP} and $ENV{TEST_TMP} ne ''; 93 subtest 'TMP unset', 94 sub { 95 delete local $ENV{TMP}; 96 env_tests(); 97 }; 98 } 99 100 SKIP: { 101 skip "Not testing TMP=/tmp", 1 if exists $ENV{TEST_TMP} and $ENV{TEST_TMP} ne '/tmp'; 102 subtest 'TMP=/tmp', 103 sub { 104 local $ENV{TMP}='/tmp'; 105 env_tests(); 106 }; 107 } 108 109 SKIP: { 110 skip "Not testing TMP=/tmp/SBo", 1 if exists $ENV{TEST_TMP} and $ENV{TEST_TMP} ne '/tmp/SBo'; 111 subtest 'TMP=/tmp/SBo', 112 sub { 113 local $ENV{TMP}='/tmp/SBo'; 114 env_tests(); 115 }; 116 } 117 118 SKIP: { 119 skip "Not testing TMP=/tmp/foo", 1 if exists $ENV{TEST_TMP} and $ENV{TEST_TMP} ne '/tmp/foo'; 120 subtest 'TMP=/tmp/foo', 121 sub { 122 local $ENV{TMP}='/tmp/foo'; 123 env_tests(); 124 }; 125 } 126 } 127 128 sub env_tests { 129 my $tmp = $ENV{TMP} // '/tmp/SBo'; 130 my $output = $ENV{OUTPUT} // '/tmp'; 131 cleanup($tmp, $output); 132 my $tmpmsg = "TMP=" . ( defined $ENV{TMP} ? $tmp : '' ); 133 my $outmsg = "OUTPUT=" . ( defined $ENV{OUTPUT} ? $output : '' ); 134 135 plan tests => 20; 136 137 ok (! -e "$tmp/nonexistentslackbuild-1.0/README", "README file 1 doesn't exist ($tmpmsg)"); 138 ok (! -e "$tmp/nonexistentslackbuild4-1.0/README", "README file 4 doesn't exist ($tmpmsg)"); 139 ok (! -e "$tmp/nonexistentslackbuild5-1.0/README", "README file 5 doesn't exist ($tmpmsg)"); 140 ok (! -e "$output/package-nonexistentslackbuild", "package dir 1 doesn't exist ($outmsg)"); 141 ok (! -e "$output/package-nonexistentslackbuild4", "package4 dir 1 doesn't exist ($outmsg)"); 142 ok (! -e "$output/package-nonexistentslackbuild5", "package5 dir 1 doesn't exist ($outmsg)"); 143 sboinstall qw/ -c FALSE nonexistentslackbuild /, { input => "y\ny", expected => qr!Cleaning for nonexistentslackbuild-1\.0!, note => 0 }; 144 ok (! -e "$tmp/nonexistentslackbuild-1.0/README", "README file 1 doesn't exist after sboinstall ($tmpmsg)"); 145 ok (! -e "$output/package-nonexistentslackbuild", "package dir 1 doesn't exist after sboinstall ($outmsg)"); 146 sboinstall qw/ -c FALSE nonexistentslackbuild4 /, 147 { input => "y\ny\ny", expected => qr!Cleaning for nonexistentslackbuild5-1\.0.*Cleaning for nonexistentslackbuild4-1\.0!s, note => 0 }; 148 ok (! -e "$tmp/nonexistentslackbuild4-1.0/README", "README file 4 doesn't exist after sboinstall ($tmpmsg)"); 149 ok (! -e "$tmp/nonexistentslackbuild5-1.0/README", "README file 5 doesn't exist after sboinstall ($tmpmsg)"); 150 ok (! -e "$output/package-nonexistentslackbuild4", "package dir 4 doesn't exist after sboinstall ($outmsg)"); 151 ok (! -e "$output/package-nonexistentslackbuild5", "package dir 5 doesn't exist after sboinstall ($outmsg)"); 152 153 cleanup($tmp, $output); 154 155 sboinstall qw/ -c TRUE nonexistentslackbuild /, { input => "y\ny", test => 0, note => 0 }; 156 ok (-e "$tmp/nonexistentslackbuild-1.0/README", "README file 1 exists after sboinstall -c TRUE ($tmpmsg)"); 157 ok (-e "$output/package-nonexistentslackbuild", "package dir 1 exists after sboinstall -c TRUE ($outmsg)"); 158 sboinstall qw/ -c TRUE nonexistentslackbuild4 /, { input => "y\ny\ny", test => 0, note => 0 }; 159 ok (-e "$tmp/nonexistentslackbuild4-1.0/README", "README file 4 exists after sboinstall -c TRUE ($tmpmsg)"); 160 ok (-e "$tmp/nonexistentslackbuild5-1.0/README", "README file 5 exists after sboinstall -c TRUE ($tmpmsg)"); 161 ok (-e "$output/package-nonexistentslackbuild4", "package dir 4 exists after sboinstall -c TRUE ($outmsg)"); 162 ok (-e "$output/package-nonexistentslackbuild5", "package dir 5 exists after sboinstall -c TRUE ($outmsg)"); 163 164 cleanup($tmp, $output); 165 } 166 167 # Cleanup 168 END { 169 cleanup('/tmp/SBo', '/tmp'); 170 }