14-jobs.t (3286B)
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/ set_lo set_jobs sboinstall sboremove sboconfig restore_perf_dummy make_slackbuilds_txt sboupgrade /; 11 12 if ($ENV{TEST_INSTALL}) { 13 plan tests => 9; 14 } else { 15 plan skip_all => "Only run these tests if TEST_INSTALL=1"; 16 } 17 18 sub cleanup { 19 capture_merged { 20 system(qw!/sbin/removepkg nonexistentslackbuild!); 21 unlink "$RealBin/LO-jobs/nonexistentslackbuild/perf.dummy"; 22 system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.0!); 23 system(qw!rm -rf /tmp/package-nonexistentslackbuild!); 24 }; 25 } 26 27 cleanup(); 28 make_slackbuilds_txt(); 29 set_lo("$RealBin/LO-jobs"); 30 set_jobs("FALSE"); 31 restore_perf_dummy(); 32 33 # 1: sboinstall with jobs set to FALSE 34 { 35 my ($time) = sboinstall(qw/ -r nonexistentslackbuild /, { expected => qr/\nreal\s+\d+m([0-9.]+)s\n/, test => 0, }); 36 ok ($time > 5, "jobs set to FALSE took the expected amount of time"); 37 } 38 sboremove('nonexistentslackbuild', { input => "y\ny", test => 0 }); 39 40 # 2: sboinstall with jobs set to 2 41 sboconfig(qw/ -j 2 /, { test => 0 }); 42 { 43 my ($time) = sboinstall(qw/ -r nonexistentslackbuild /, { expected => qr/^real\s+\d+m([\d.]+)s$/m, test => 0 }); 44 ok ($time < 5, "jobs set to 2 took less time than otherwise"); 45 } 46 sboremove('nonexistentslackbuild', { input => "y\ny", test => 0 }); 47 48 # 3: sboinstall -j FALSE with jobs set to 2 49 { 50 my ($time) = sboinstall(qw/ -j FALSE -r nonexistentslackbuild /, { expected => qr/^real\s+\d+m([\d.]+)s$/m, test => 0 }); 51 ok ($time > 5, "-j FALSE took the expected amount of time"); 52 } 53 sboremove('nonexistentslackbuild', { input => "y\ny", test => 0 }); 54 55 # 4: sboinstall -j 2 with jobs set to FALSE 56 sboconfig(qw/ -j FALSE /, { test => 0 }); 57 { 58 my ($time) = sboinstall(qw/ -j 2 -r nonexistentslackbuild /, { expected => qr/^real\s+\d+m([\d.]+)s$/m, test => 0 }); 59 ok ($time < 5, "-j 2 took less time than otherwise"); 60 } 61 sboremove('nonexistentslackbuild', { input => "y\ny", test => 0 }); 62 63 # 5: sboinstall -j 0 with jobs set to 2 64 sboconfig(qw/ -j 2 /, { test => 0 }); 65 { 66 my ($time) = sboinstall(qw/ -j 0 -r nonexistentslackbuild /, { expected => qr/^real\s+\d+m([\d.]+)s$/m, test => 0 }); 67 ok ($time > 5, "-j 0 took the expected amount of time"); 68 } 69 sboremove('nonexistentslackbuild', { input => "y\ny", test => 0 }); 70 71 #6: sboinstall -j invalid 72 sboinstall(qw/ -j invalid nonexistentslackbuild /, { exit => 1, expected => "You have provided an invalid value for -j|--jobs\n" }); 73 74 #7: sboupgrade -j invalid 75 sboinstall qw/ -r nonexistentslackbuild /, { test => 0 }; 76 set_lo "$RealBin/LO-jobs2"; 77 sboupgrade qw/ -j invalid nonexistentslackbuild /, { exit => 1, expected => "You have provided an invalid value for -j|--jobs\n" }; 78 79 #8: sboupgrade -j 2 80 { 81 my ($time) = sboupgrade qw/ -j 2 nonexistentslackbuild /, { input => "y\ny", expected => qr/^real\s+\d+m([\d.]+)s$/m, test => 0 }; 82 ok ($time < 5, "sboupgrade -j 2 took less time than otherwise"); 83 } 84 85 #9: sboupgrade -j 0 86 { 87 set_lo "$RealBin/LO-jobs"; 88 my ($time) = sboupgrade qw/ -j 0 nonexistentslackbuild /, { input => "y\ny", expected => qr/^real\s+\d+m([\d.]+)s$/m, test => 0 }; 89 ok ($time > 5, "sboupgrade -j 0 took the expected amount of time"); 90 } 91 92 93 # Cleanup 94 END { 95 cleanup(); 96 }