From a605927dc5ae1e3a697cef2829be4e63af526645 Mon Sep 17 00:00:00 2001 From: Andreas Guldstrand Date: Sat, 2 Jan 2016 20:48:32 +0100 Subject: Rename test files so they get run in a nicer order --- t/01-test.t | 642 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ t/02-travis.t | 119 +++++++++++ t/03-online.t | 107 ++++++++++ t/04-install.t | 103 +++++++++ t/05-upgrade.t | 130 ++++++++++++ t/06-remove.t | 90 ++++++++ t/07-fail.t | 181 ++++++++++++++++ t/08-env.t | 199 ++++++++++++++++++ t/env.t | 199 ------------------ t/fail.t | 181 ---------------- t/install.t | 103 --------- t/online.t | 107 ---------- t/remove.t | 90 -------- t/test.t | 642 --------------------------------------------------------- t/travis.t | 119 ----------- t/upgrade.t | 130 ------------ 16 files changed, 1571 insertions(+), 1571 deletions(-) create mode 100755 t/01-test.t create mode 100755 t/02-travis.t create mode 100755 t/03-online.t create mode 100755 t/04-install.t create mode 100755 t/05-upgrade.t create mode 100755 t/06-remove.t create mode 100755 t/07-fail.t create mode 100755 t/08-env.t delete mode 100755 t/env.t delete mode 100755 t/fail.t delete mode 100755 t/install.t delete mode 100755 t/online.t delete mode 100755 t/remove.t delete mode 100755 t/test.t delete mode 100755 t/travis.t delete mode 100755 t/upgrade.t diff --git a/t/01-test.t b/t/01-test.t new file mode 100755 index 0000000..ee7e1fb --- /dev/null +++ b/t/01-test.t @@ -0,0 +1,642 @@ +#!/usr/bin/env perl + +use 5.16.0; +use strict; +use warnings FATAL => 'all'; +use File::Temp qw(tempdir tempfile); +use Test::More; +use Test::Output; +use File::Copy; +use Text::Diff; +use FindBin '$RealBin'; + +BEGIN { + chdir($RealBin); + system($^X, 'prep.pl') unless -d 'SBO'; +} + +use lib "."; +use SBO::Lib qw/ :all /; + +plan tests => 60; + +chomp(my $pwd = `pwd`); +my $sbo_home = "$pwd/sbo"; + +$conf_file = "$pwd/sbotools.conf"; +$SBO::Lib::conf_file = $conf_file; +@SBO::Lib::config{'LOCAL_OVERRIDES', 'REPO'} = ('FALSE', 'FALSE'); +read_config; +$config{SBO_HOME} = $sbo_home; +my $repo_path = "$sbo_home/repo"; +$SBO::Lib::repo_path = $repo_path; +$SBO::Lib::distfiles = "$sbo_home/distfiles"; +$SBO::Lib::slackbuilds_txt = "$repo_path/SLACKBUILDS.TXT"; +$SBO::Lib::pkg_db = "$pwd/packages"; + +# 1-6: config settings tests +is($config{DISTCLEAN}, 'FALSE', 'config{DISTCLEAN} is good'); +is($config{JOBS}, 2, 'config{JOBS} is good'); +is($config{NOCLEAN}, 'FALSE', 'config{NOCLEAN} is good'); +is($config{PKG_DIR}, 'FALSE', 'config{PKG_DIR} is good'); +is($config{SBO_HOME}, "$pwd/sbo", 'config{SBO_HOME} is good'); +is($config{LOCAL_OVERRIDES}, 'FALSE', 'config{LOCAL_OVERRIDES} is good'); + +# 7: open_read, open_fh tests +{ + my $fh = open_read('./test.t'); + is(ref $fh, 'GLOB', 'open_read works'); + close $fh; +} + +# 8: test to ensure tempdir is defined by default +ok(defined $tempdir, '$tempdir is defined'); + +# 9-10: show_version test +my $version_output = <<"VERSION"; +sbotools version 2.0 +licensed under the WTFPL + +VERSION +my $ret; +stdout_is (sub { $ret = show_version(); }, $version_output, 'show_version output is good'); +is( $ret, 1, 'show_version return value is good'); + +# 11-16: get_slack_version test +SKIP: { + skip 'no /etc/slackware-version', 1 unless -f '/etc/slackware-version'; + + local $config{SLACKWARE_VERSION} = 'FALSE'; + chomp(my $version = qx(awk '{print \$2}' /etc/slackware-version)); + is (get_slack_version(), $version, 'get_slack_version is good'); +} +for my $ver (qw/ 14.0 14.1 14.2 15.0 26.80 /) { + local $config{SLACKWARE_VERSION} = $ver; + is (get_slack_version(), $ver, 'get_slack_version gets custom SLACK_VERSION'); +} + +# 17: make sure we migrate when we should +ok(-f "$sbo_home/SLACKBUILDS.TXT", 'SLACKBUILDS.TXT exists pre-migration'); + +# 18-19: chk_slackbuilds_txt tests +is(chk_slackbuilds_txt(), 1, 'chk_slackbuilds_txt is good'); +move("$repo_path/SLACKBUILDS.TXT", "$sbo_home/SLACKBUILDS.TXT.moved"); +is(chk_slackbuilds_txt(), undef, + 'chk_slackbuilds_txt returns false with no SLACKBUILDS.TXT'); +move("$sbo_home/SLACKBUILDS.TXT.moved", "$repo_path/SLACKBUILDS.TXT"); + +# 20: slackbuilds_or_fetch test +is(slackbuilds_or_fetch(), 1, 'slackbuilds_or_fetch is good'); + +# 21: get_installed_packages 'SBO' test +subtest "pseudo-random sampling of get_installed_packages 'SBO' output...", +sub { + plan tests => 8; + + my %expected = ( + OpenAL => '1.13', + 'adobe-reader' => '9.5.1_enu', + libdvdnav => '4.1.3', + libmodplug => '0.8.8.4', + unetbootin => '575', + zdoom => '2.6.0', + 'p7zip-compat32' => '9.20.1', + 'lame-compat32' => '3.99.5', + ); + my $installed = get_installed_packages('SBO'); + + for my $inst (@$installed) { + my $ver = $expected{ $inst->{name} }; + next if not defined $ver; + + is( $inst->{version}, $ver, $inst->{name} ); + } +}; + +# 22: get_installed_packages 'ALL' test +subtest "pseudo-random sampling of get_installed_packages 'ALL' output...", +sub { + plan tests => 8; + + my %expected = ( + OpenAL => '1.13', + gimp => '2.8.2', + libdvdnav => '4.1.3', + perl => '5.16.1', + unetbootin => '575', + zlib => '1.2.6', + 'p7zip-compat32' => '9.20.1', + 'lame-compat32' => '3.99.5', + ); + my $installed = get_installed_packages('ALL'); + + for my $inst (@$installed) { + my $ver = $expected{ $inst->{name} }; + next if not defined $ver; + + is( $inst->{version}, $ver, $inst->{name} ); + } +}; + +# 23: get_sbo_location/get_sbo_locations tests +subtest 'get_sbo_location tests', +sub { + plan tests => 7; + + is(get_sbo_location ('nginx'), "$repo_path/network/nginx", + 'get_sbo_location is good'); + is(get_sbo_locations('omgwtfbbq'), 0, + 'get_sbo_locations returns false with not-an-sbo input'); + is(get_sbo_location ('omgwtfbbq'), undef, + 'get_sbo_location returns false with not-an-sbo input'); + my @finds = qw(nginx gmpc); + my %locs = get_sbo_locations(@finds); + is($locs{nginx}, "$repo_path/network/nginx", + 'get_sbo_locations passed array #1 good'); + is($locs{gmpc}, "$repo_path/audio/gmpc", 'get_sbo_locations passed array #2 good'); + %locs = get_sbo_locations(\@finds); + is($locs{nginx}, "$repo_path/network/nginx", + 'get_sbo_locations passed array ref #1 good'); + is($locs{gmpc}, "$repo_path/audio/gmpc", + 'get_sbo_locations passed array ref #2 good'); +}; + +# 24: get_available_updates tests +subtest 'get_available_updates tests', +sub { + plan tests => 2; + + my $updates = get_available_updates(); + my %expected = ( + mutagen => { installed => '1.15', update => '1.20', }, + ); + for my $upd (@$updates) { + my $vers = $expected{ $upd->{name} }; + next if not defined $vers; + + is ($upd->{installed}, $vers->{installed}, 'installed version is good for mutagen'); + is ($upd->{update}, $vers->{update}, 'update version is good for mutagen'); + } +}; + +# 25: get_arch test +# TODO: uh, this will fail on 32bit, right? +is(get_arch(), 'x86_64', 'get_arch is good'); + +# 26: get_download_info tests +subtest 'get_download_info tests', +sub { + plan tests => 2; + + my $dl_info = get_download_info(LOCATION => "$repo_path/system/wine", X64 => 0); + my $link = 'http://downloads.sf.net/wine/source/1.4/wine-1.4.1.tar.bz2'; + is($$dl_info{$link}, '0c28702ed478df7a1c097f3a9c4cabd6', + 'get_download_info test 01 good.'); + $link = 'http://www.unrealize.co.uk/source/dibeng-max-2010-11-12.zip'; + is($$dl_info{$link}, '97159d77631da13952fe87e846cf1f3b', + 'get_download_info test 02 good.'); +}; + +# 27: get_sbo_downloads tests +subtest 'get_sbo_downloads tests', +sub { + plan tests => 5; + + my $dl_info = get_sbo_downloads(LOCATION => "$repo_path/system/wine"); + my $link = 'http://downloads.sf.net/wine/source/1.4/wine-1.4.1.tar.bz2'; + is($$dl_info{$link}, '0c28702ed478df7a1c097f3a9c4cabd6', + 'get_sbo_downloads test 01 good.'); + $link = 'http://www.unrealize.co.uk/source/dibeng-max-2010-11-12.zip'; + is($$dl_info{$link}, '97159d77631da13952fe87e846cf1f3b', + 'get_sbo_downloads test 02 good.'); + my $downloads = get_sbo_downloads(LOCATION => "$repo_path/system/ifuse"); + $link = 'http://www.libimobiledevice.org/downloads/ifuse-1.1.1.tar.bz2'; + is($$downloads{$link}, '8d528a79de024b91f12f8ac67965c37c', + 'get_sbo_downloads test 03 good.'); + $downloads = get_sbo_downloads(LOCATION => "$repo_path/multimedia/mpv"); + my @links = qw' + https://github.com/mpv-player/mpv/archive/v0.10.0.tar.gz + http://www.freehackers.org/~tnagy/release/waf-1.8.12 + '; + is ($$downloads{$links[0]}, 'e81a975e4fa17f500dc2e7ea3d3ecf25', + 'get_sbo_downloads test 04 good.'); + is ($$downloads{$links[1]}, 'cef4ee82206b1843db082d0b0506bf71', + 'get_sbo_downloads test 05 good.'); +}; + +# 28-29: get_filename_from_link tests +is(get_filename_from_link( + 'http://www.libimobiledevice.org/downloads/ifuse-1.1.1.tar.bz2'), + "$sbo_home/distfiles/ifuse-1.1.1.tar.bz2", 'get_file_from_link good'); +is(get_filename_from_link('adf;lkajsdfaksjdfalsdjfalsdkfjdsfj'), undef, + 'get_filename_from_link good with invalid input'); + +# 30: compute_md5sum test +is(compute_md5sum("$sbo_home/distfiles/test.file"), + '593d3125d3170f0b5326a40a253aa6fd', 'compute_md5sum good'); + +# 31: verify_distfile test +is(verify_distfile("http://dawnrazor.net/test.file", + '593d3125d3170f0b5326a40a253aa6fd'), 1, 'verify_distfile good'); + +# 32: get_sbo_version test +is(get_sbo_version("$repo_path/system/wine"), '1.4.1', 'get_sbo_version good'); + +# 33: get_symlink_from_filename test +is(get_symlink_from_filename("$sbo_home/distfiles/test.file", + "$repo_path/system/laptop-mode-tools"), + "$repo_path/system/laptop-mode-tools/test.file", + 'get_symlink_from_filename good'); + +# 34-35: check_x32 tests +ok(check_x32("$repo_path/system/wine"), 'check_x32 true for 32-bit only wine'); +ok(!(check_x32("$repo_path/system/ifuse")), + 'check_x32 false for not-32-bit-only ifuse'); + +# 36: check_multilib tests +SKIP: { + skip "This is useless to test if TEST_MULTILIB=1", 1 if ($ENV{TEST_MULTILIB} // 0) == 1; + if (-x '/usr/sbin/convertpkg-compat32') { + ok(check_multilib(), 'check_multilib good'); + } else { + ok(!check_multilib(), 'check_multilib good'); + } +} + +# 37: create_symlinks tests +subtest 'create_sumlinks tests', +sub { + plan tests => 2; + + my $downloads = get_sbo_downloads(LOCATION => "$repo_path/system/wine", 32 => 1); + my $symlinks = create_symlinks("$repo_path/system/wine", $downloads); + my ($have1, $have2); + for my $sl (@$symlinks) { + $have1++ if $sl eq "$repo_path/system/wine/wine-1.4.1.tar.bz2"; + $have2++ if $sl eq "$repo_path/system/wine/dibeng-max-2010-11-12.zip"; + } + ok($have1, '$create_symlinks test 1 passed.'); + ok($have2, '$create_symlinks test 2 passed.'); +}; + +# 38: grok_temp_file, get_src_dir/get_pkg_name tests +{ + my $tempdir = tempdir(CLEANUP => 1); + my $tempfh = tempfile(DIR => $tempdir); + my $lmt = 'laptop-mode-tools_1.60'; + print {$tempfh} "$lmt/COPYING\n"; + print {$tempfh} "$lmt/Documentation/\n"; + print {$tempfh} "$lmt/README\n"; + print {$tempfh} "Slackware package skype-2.2.0.35-i486-1_SBo.tgz created.\n"; + is(get_pkg_name($tempfh), 'skype-2.2.0.35-i486-1_SBo.tgz', 'get_pkg_name good'); +} + +# 39-40: get_src_dir tests +SKIP: { + skip 'Need to look into how to do the get_src_dir tests', 2; + # TODO: get this working as it should + # we can not test get_src_dir() at present - we will need to support $TMP in + # order to be able to test this. because user can't write to /tmp/SBo + #close $tempfh; + #$tempfh = tempfile(DIR => $tempdir); + #opendir (my $tsbo_dh, '/tmp/SBo'); + #FIRST: while (readdir $tsbo_dh) { + # next FIRST if /^\.[\.]{0,1}$/; + # say {$tempfh} $_; + #} + #close $tsbo_dh; + #mkdir '/tmp/SBo/test.d.1'; + #mkdir '/tmp/SBo/test.2.d'; + #my $src = get_src_dir $tempfh; + #say ref $src; + #say $_ for @$src; + #is($$src[0], 'test.d.1', 'get_src_dir test 01'); + #is($$src[1], 'test.2.d', 'get_src_dir test 02'); + #rmdir '/tmp/SBo/test.d.1'; + #rmdir '/tmp/SBo/test.2.d'; +} + +# 41: check_repo tests +subtest 'check_repo tests', +sub { + plan tests => 3; + + local $config{SBO_HOME} = "$pwd/test_sbo"; + local $SBO::Lib::repo_path = "$config{SBO_HOME}/repo"; + ok(check_repo(), 'check_repo returns true with new non-existent directory'); + ok(-d "$pwd/test_sbo", 'check_repo creates $config{SBO_HOME}'); + ok(check_repo(), 'check_repo returns true with new existent empty directory'); + rmdir "$pwd/test_sbo"; +}; + +# 42-43: get_sbo_from_loc tests +is(get_sbo_from_loc('/home/d4wnr4z0r/sbo.git/system/ifuse'), 'ifuse', + 'get_sbo_from_loc returns correctly with valid input'); +ok(! get_sbo_from_loc('omg_wtf_bbq'), + 'get_sbo_from_loc returns false with invalid input'); + +# 44: rewrite_slackbuild/revert_slackbuild tests +subtest 'rewrite_slackbuild/revert_slackbuild tests', +sub { + plan tests => 7; + + my $rewrite_dir = tempdir(CLEANUP => 1); + copy("$repo_path/system/ifuse/ifuse.SlackBuild", $rewrite_dir); + my $slackbuild = "$rewrite_dir/ifuse.SlackBuild"; + my $tempfh = tempfile(DIR => $rewrite_dir); + my $tempfn = get_tmp_extfn($tempfh); + my %changes = (); + is(rewrite_slackbuild (SLACKBUILD => $slackbuild, TEMPFN => $tempfn, + CHANGES => \%changes), 1, 'rewrite_slackbuild with no %changes good'); + ok(-f "$slackbuild.orig", 'rewrite_slackbuild backing up original is good.'); + is(revert_slackbuild($slackbuild), 1, 'revert_slackbuild is good'); + $changes{libdirsuffix} = ''; + $changes{make} = '-j 5'; + $changes{arch_out} = 'i486'; + is(rewrite_slackbuild (SLACKBUILD => $slackbuild, CHANGES => \%changes, + C32 => 1, SBO => 'ifuse'), 1, 'rewrite_slackbuild test w/ all %changes'); + ok(-f "$slackbuild.orig", 'rewrite_slackbuild backing up original is good.'); + my $expected_out = <<'END'; +55c55 +< LIBDIRSUFFIX="64" +--- +> LIBDIRSUFFIX="" +67c67 +< tar xvf $CWD/$PRGNAM-$VERSION.tar.bz2 +--- +> tar xvf $CWD/ifuse-1.1.1.tar.bz2 +103c103 +< /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz} +--- +> /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-i486-$BUILD$TAG.${PKGTYPE:-tgz} +END + is(diff("$slackbuild.orig", $slackbuild, {STYLE => 'OldStyle'}), + $expected_out, 'all changed lines rewritten correctly'); + is(revert_slackbuild($slackbuild), 1, 'revert_slackbuild is good again'); +}; + +# 45: get_from_info tests +subtest 'get_from_info tests', +sub { + plan tests => 3; + + my $test_loc = "$repo_path/system/ifuse"; + my %params = (LOCATION => $test_loc); + my $info = get_from_info(%params, GET => 'VERSION'); + is($$info[0], '1.1.1', 'get_from_info GET => VERSION is good'); + $info = get_from_info(%params, GET => 'HOMEPAGE'); + is($$info[0], 'http://www.libimobiledevice.org', + 'get_from_info GET => HOMEPAGE is good'); + $info = get_from_info(%params, GET => 'DOWNLOAD_x86_64'); + is($$info[0], "", 'get_from_info GET => DOWNLOAD_x86_64 is good'); +}; + +# 46: get_update_list tests +subtest 'get_update_list tests', +sub { + plan tests => 5; + + my $listing; + stdout_is(sub { $listing = get_update_list(); }, "Checking for updated SlackBuilds...\n", 'output of get_update_list() good'); + s/\s//g for @$listing; + is (shift(@$listing), 'adobe-reader9.5.1_enu 'Path /omg/wtf/bbq needs to not exist for this test.'; + } else { + plan tests => 2; + } + + my $ret; + stdout_is (sub { $ret = remove_stuff('/omg/wtf/bbq') }, "Nothing to do.\n", 'output for remove_stuff good'); + is($ret, 1, 'remove_stuff good for invalid input'); +}; + +# 48: perform_search tests +subtest 'perform_search tests', +sub { + plan tests => 7; + + my $findings = perform_search('desktop'); + for my $found (@$findings) { + my $name = $found->{name}; + my $location = $found->{location}; + my $section = 'desktop';; + if ($name eq 'libdesktop-agnostic') { + $section = 'libraries'; + } elsif ($name eq 'mendeleydesktop') { + $section = 'academic'; + } elsif ($name eq 'gtk-recordmydesktop' || $name eq 'huludesktop') { + $section = 'multimedia'; + } elsif ($name eq 'gnome-python-desktop') { + $section = 'python'; + } elsif ($name eq 'gsettings-desktop-schemas') { + $section = 'system'; + } + is($location, "$repo_path/$section/$name", + 'perform_search good for $search eq desktop'); + } +}; + +# 49: get_inst_names test +my $inst_names; +{ + my $installed = get_installed_packages('SBO'); + $inst_names = get_inst_names($installed); + my %inst_names; + $inst_names{$_} = 1 for @$inst_names; + ok($inst_names{zdoom}, 'get_inst_names is good'); +} + +# 50: get_reqs tests +subtest 'get_reqs tests', +sub { + plan tests => 5; + + my $reqs = get_requires('gmpc');#, "$sbo_home/audio/gmpc"; + my $name = 'get_requires good for normal req list'; + is($$reqs[0], 'gob2', $name); + is($$reqs[1], 'libmpd', $name); + is($$reqs[2], 'vala', $name); + $reqs = get_requires('doomseeker'); + is($$reqs[0], '%README%', 'get_requires good for REQUIRES="%README%"'); + is(get_requires('krb5')->[0], '', 'get_requires good for REQUIRES=""'); +}; + +# 51: get_user_group tests +subtest 'get_user_group tests', +sub { + plan tests => 4; + + my $fh = open_read("$repo_path/network/nagios/README"); + my $readme = do {local $/; <$fh>}; + close $fh; + my $cmds = get_user_group($readme); + is($$cmds[0], 'groupadd -g 213 nagios', 'get_user_group good for # groupadd'); + is($$cmds[1], 'useradd -u 213 -d /dev/null -s /bin/false -g nagios nagios', + 'get_user_group for # useradd'); + + $fh = open_read("$repo_path/network/havp/README"); + $readme = do {local $/; <$fh>}; + close $fh; + $cmds = get_user_group($readme); + is($$cmds[0], 'groupadd -g 210 clamav', 'get_user_group good for groupadd'); + is($$cmds[1], 'useradd -u 256 -d /dev/null -s /bin/false -g clamav havp', + 'get_user_group good for useradd'); +}; + +# 52: get_opts test +subtest 'get_opts test', +sub { + plan tests => 2; + + my $fh = open_read("$repo_path/games/vbam/README"); + my $readme = do {local $/; <$fh>}; + close $fh; + ok(get_opts($readme), 'get_opts good where README defines opts'); + + $fh = open_read("$repo_path/audio/gmpc/README"); + $readme = do {local $/; <$fh>}; + close $fh; + ok(! (get_opts($readme)), 'get_opts good where README does not define opts'); +}; + +# 53: queue tests +subtest 'queue tests', +sub { + plan tests => 30; + + # test multiple sbo's + # sbo's: zdoom', 'bsnes', 'spring', 'OpenAL' + # expected queue: eawpats TiMidity++ fmodapi p7zip zdoom OpenAL bsnes DevIL jdk spring + my $warnings = {}; + my @t_argv = ( 'zdoom', 'bsnes', 'spring', 'OpenAL' ); + my $queue; + for my $sbo (@t_argv) { + my $queue_sbo = get_build_queue([$sbo], $warnings); + $queue = merge_queues($queue, $queue_sbo); + } + my $count = @$queue; + is($count, 10, 'get_build_queue returns correct amount for multiple sbos'); + is($$queue[0], 'eawpats', 'get_build_queue first entry correct for multiple sbos'); + is($$queue[2], 'fmodapi', 'get_build_queue third entry correct for multiple sbos'); + is($$queue[4], 'zdoom', 'get_build_queue fifth entry correct for multiple sbos'); + is($$queue[6], 'bsnes', 'get_build_queue seventh entry correct for multiple sbos'); + is($$queue[8], 'jdk', 'get_build_queue ninth entry correct for multiple sbos'); + + # test single sbo + # sbo: zdoom + # expected queue: eawpats TiMidity++ fmodapi p7zip zdoom + $queue = get_build_queue(['zdoom'], $warnings); + $count = @$queue; + is($count, 5, 'get_build_queue returns correct amount for single sbo'); + is($$queue[0], 'eawpats', 'get_build_queue first entry correct for single sbo'); + is($$queue[2], 'fmodapi', 'get_build_queue third entry correct for single sbo'); + is($$queue[4], 'zdoom', 'get_build_queue fifth entry correct for single sbo'); + + # https://github.com/pink-mist/sbotools/issues/2 + my $bug_2 = get_build_queue(['dfvfs'], $warnings); + my $bug_2_test = "get_build_queue handles bug 2 properly (%s)"; + my @bug_2_req = qw( + six construct pytz pysetuptools python-dateutil python-gflags + protobuf libbde libewf libqcow + libsigscan libsmdev libsmraw libvhdi libvmdk + libvshadow sleuthkit pytsk dfvfs ); + for my $index (0 .. $#bug_2_req) { + is($$bug_2[$index], $bug_2_req[$index], sprintf($bug_2_test, $bug_2_req[$index])); + } + + # test that we get a warning in $warnings + $queue = get_build_queue(['ffmpeg'], $warnings); + is($warnings->{ffmpeg}, "%README%", 'got ffmpeg README warning'); +}; + +# 54: test get_required_by +subtest 'get_required_by tests', +sub { + plan tests => 3; + + get_reverse_reqs($inst_names); + my $required = get_required_by('p7zip'); + is($$required[0], 'unetbootin', 'get_required_by good for populated req_by list'); + is($$required[1], 'zdoom', 'get_required_by good for populated req_by list'); + is( get_required_by('zdoom'), undef, 'get_required_by good for empty req_by list'); +}; + +# 55-56: test confirm_remove +{ + local @SBO::Lib::confirmed=('p7zip', 'eawpats', 'bsnes'); + confirm_remove('zdoom'); + my $count = @SBO::Lib::confirmed; + is($count, 4, 'confirm_remove good for new sbo'); + confirm_remove('zdoom'); + $count = @SBO::Lib::confirmed; + is($count, 4, 'confirm_remove good for duplicate sbo'); +}; + +# 57: test get_readme_contents +ok(get_readme_contents("$repo_path/network/nagios"), 'get_readme_contents is good'); + +# 58: test get_dl_fns +subtest 'get_dl_fns tests', +sub { + plan tests => 3; + + my $downloads = [ + 'http://developer.download.nvidia.com/cg/Cg_3.1/Cg-3.1_April2012_x86.tgz' + ]; + my $fns = get_dl_fns($downloads); + is($$fns[0], 'Cg-3.1_April2012_x86.tgz', 'get_dl_fns test, one input'); + $downloads = [ + 'http://download.virtualbox.org/virtualbox/4.2.0/VirtualBox-4.2.0.tar.bz2', + 'http://download.virtualbox.org/virtualbox/4.2.0/VBoxGuestAdditions_4.2.0.iso', + 'http://download.virtualbox.org/virtualbox/4.2.0/UserManual.pdf', + 'http://download.virtualbox.org/virtualbox/4.2.0/SDKRef.pdf', + ]; + $fns = get_dl_fns($downloads); + is($$fns[0], 'VirtualBox-4.2.0.tar.bz2', 'get_dl_fns test, multiple inputs 01'); + is($$fns[2], 'UserManual.pdf', 'get_dl_fns test, multiple inputs 02'); +}; + +# 59: test get_dc_regex - multiple tests for various types of input +subtest 'get_dc_regex tests', +sub { + plan tests => 8; + + my $line = 'tar xvf $CWD/$PRGNAM-$VERSION.tar.?z*'; + my ($regex, $initial) = get_dc_regex($line); + is($regex, '(?^u:/[^-]+-[^-]+.tar.[a-z]z.*)', 'get_dc_regex test 01.1'); + is($initial, '/', 'get_dc_regex test 01.2'); + $line = 'tar xvf $CWD/Oracle_VM_VirtualBox_Extension_Pack-$VERSION.vbox-extpack'; + ($regex, $initial) = get_dc_regex($line); + is($regex, '(?^u:/Oracle_VM_VirtualBox_Extension_Pack-[^-]+.vbox-extpack)', + 'get_dc_regex test 02.1'); + is($initial, '/', 'get_dc_regex test 02.2'); + $line = 'tar xvf $CWD/${PRGNAM}-source-$(echo $VERSION).tar.gz'; + ($regex, $initial) = get_dc_regex($line); + is($regex, '(?^u:/[^-]+-source-[^-]+.tar.gz)', 'get_dc_regex test 03.1'); + is($initial, '/', 'get_dc_regex test 03.2'); + $line = '( tar xvf xapian-bindings-$VERSION.tar.gz'; + ($regex, $initial) = get_dc_regex($line); + is($regex, '(?^u: xapian-bindings-[^-]+.tar.gz)', 'get_dc_regex test 04.1'); + is($initial, ' ', 'get_dc_regex test 04.2'); +}; + +# 60: move things back to pre-migration state +subtest 'move things back to pre-migration state', +sub { + foreach my $fname (glob("$repo_path/*")) { + is(system('mv', $fname, $sbo_home), 0, "moving $fname to pre-migration place works"); + } + ok (rmdir($repo_path), "removing $repo_path works"); + ok (do { rmdir("$sbo_home/../test_sbo/repo") and rmdir("$sbo_home/../test_sbo") }, "removing test_sbo works"); +}; + +# end of tests. diff --git a/t/02-travis.t b/t/02-travis.t new file mode 100755 index 0000000..20b2665 --- /dev/null +++ b/t/02-travis.t @@ -0,0 +1,119 @@ +#!/usr/bin/env perl + +use 5.16.0; +use strict; +use warnings FATAL => 'all'; +use Test::More; +use Capture::Tiny qw/ capture_merged /; +use FindBin '$RealBin'; +use lib $RealBin; +use lib "$RealBin/../SBO-Lib/lib"; +use Test::Execute; + +if (defined $ENV{TRAVIS} and $ENV{TRAVIS} eq 'true') { + plan tests => 26; +} else { + plan skip_all => 'Only run these tests under Travis CI (TRAVIS=true)'; +} +$ENV{TEST_ONLINE} //= 0; + +$path = "$RealBin/../"; + +# 1-3: Test SLACKWARE_VERSION +script (qw/ sboconfig -V 14.1 /, { expected => "Setting SLACKWARE_VERSION to 14.1...\n" }); +SKIP: { + skip 'Not doing online tests without TEST_ONLINE=1', 2 if $ENV{TEST_ONLINE} ne '1'; + + script (qw/ sbosnap fetch /, { expected => qr/\APulling SlackBuilds tree\.\.\.\n/ }); + script (qw/ sbofind sbotools /, { expected => "SBo: sbotools\nPath: /usr/sbo/repo/system/sbotools\n\n" }); +} + +# 4-10: Test alternative REPO +is (system(qw!rm -rf /usr/sbo!), 0, 'Removing /usr/sbo works'); +ok (! -e "/usr/sbo/repo/SLACKBUILDS.TXT", "SLACKBUILDS.TXT doesn't exist"); +script (qw! sboconfig -r https://github.com/Ponce/slackbuilds.git !, { expected => "Setting REPO to https://github.com/Ponce/slackbuilds.git...\n", name => 'Alternative REPO' }); +SKIP: { + skip 'Not doing online tests without TEST_ONLINE=1', 4 if $ENV{TEST_ONLINE} ne '1'; + + script (qw/ sbosnap fetch /, { expected => qr!Pulling SlackBuilds tree.*Cloning into '/usr/sbo/repo'!s }); + ok (-e "/usr/sbo/repo/SLACKBUILDS.TXT", "SLACKBUILDS.TXT exists (REPO)"); + ok (! -e "/usr/sbo/repo/SLACKBUILDS.TXT.gz", "SLACKBUILDS.TXT.gz doesn't exist (REPO)"); + script (qw/ sbofind sbotools /, { expected => "SBo: sbotools\nPath: /usr/sbo/repo/system/sbotools\n\n" }); +} + +# 11-17: Test local overrides +script (qw/ sboconfig -o /, "$RealBin/LO", { expected => "Setting LOCAL_OVERRIDES to $RealBin/LO...\n", name => 'LOCAL_OVERRIDES' }); +my $skip = 0; +SKIP: { + if ($ENV{TEST_ONLINE} ne '1') { $skip = !(system(qw! mkdir -p /usr/sbo/repo !) == 0 and system(qw! touch /usr/sbo/repo/SLACKBUILDS.TXT !) == 0) } + skip "Online testing disabled (TEST_ONLINE!=1) and could not create dummy SLACKBUILDS.TXT", 9 if $skip; + + script (qw/ sbofind nonexistentslackbuild /, { expected => <<"LOCAL" }); +Local: nonexistentslackbuild5 +Path: /home/travis/build/pink-mist/sbotools/t/LO/nonexistentslackbuild5 + +Local: nonexistentslackbuild4 +Path: /home/travis/build/pink-mist/sbotools/t/LO/nonexistentslackbuild4 + +Local: nonexistentslackbuild2 +Path: $RealBin/LO/nonexistentslackbuild2 + +Local: nonexistentslackbuild +Path: $RealBin/LO/nonexistentslackbuild + +LOCAL + script (qw/ sboinstall -r nonexistentslackbuild /, + { expected => qr/nonexistentslackbuild added to install queue[.].*perf[.]dummy' saved.*Cleaning for nonexistentslackbuild-1[.]0/s }); + script (qw/ sboremove --nointeractive nonexistentslackbuild /, { expected => qr/Removing 1 package\(s\).*nonexistentslackbuild.*All operations have completed/s }); + is (system(qw!/sbin/installpkg nonexistentslackbuild-0.9-noarch-1_SBo.tgz!), 0, 'Old version fake installed'); + script (qw/ sbocheck /, { expected => qr/Updating SlackBuilds tree.*Checking for updated SlackBuilds.*nonexistentslackbuild 0[.]9.*needs updating/s }); + script (qw/ sboupgrade -r nonexistentslackbuild /, { expected => qr/nonexistentslackbuild added to upgrade queue.*Upgrade queue: nonexistentslackbuild/s }); + +# 18: Test missing dep + script (qw/ sboinstall nonexistentslackbuild2 /, { input => 'y', exit => 1, expected => "Unable to locate nonexistentslackbuild3 in the SlackBuilds.org tree.\n" }); +} + +# 19-23: Test sboupgrade --all +SKIP: { + my @files = glob("/var/log/packages/nonexistentslackbuild-*"); + skip 'nonexistentslackbuild not installed', 1 if @files == 0; + + is (system(qw!/sbin/removepkg nonexistentslackbuild!), 0, 'removepkging nonexistentslackbuild works'); +} +SKIP: { + skip "Online testing disabled (TEST_ONLINE!=1) and could not create dummy SLACKBUILDS.txt", 4 if $skip; + + my @files = glob("/var/log/packages/nonexistentslackbuild-*"); + skip 'Cannot test if nonexistentslackbuild is already installed', 4 if @files; + + is (system(qw!/sbin/installpkg nonexistentslackbuild-0.9-noarch-1_SBo.tgz!), 0, 'installpkg old version works'); + script (qw/ sboupgrade -r --all /, { expected => qr/Checking for updated SlackBuilds.*nonexistentslackbuild added to upgrade queue.*Cleaning for nonexistentslackbuild/s }); + ok (-e "/var/log/packages/nonexistentslackbuild-1.0-noarch-1_SBo", 'updated package is installed'); + ok (! -e "/var/log/packages/nonexistentslackbuild-0.9-noarch-1_SBo", 'old package is removed'); +} + +if (not glob("/var/log/packages/nonexistentslackbuild-*")) { + script (qw/ sboinstall -r nonexistentslackbuild /, { test => 0 }); +} +if (not glob("/var/log/packages/nonexistentslackbuild4-*")) { + script (qw/ sboinstall nonexistentslackbuild4 /, { input => "y\ny\ny", test => 0 }); +} +# 24-25: Test sboupgrade -f +script (qw/ sboupgrade -f nonexistentslackbuild /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild\?.*Upgrade queue: nonexistentslackbuild\n/s }); +script (qw/ sboupgrade -f nonexistentslackbuild4 /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild4\?.*Upgrade queue: nonexistentslackbuild4\n/s }); + +# 26: Test sboupgrade -f -z +script (qw/ sboupgrade -f -z nonexistentslackbuild4 /, { + input => "y\ny\ny", + expected => qr/nonexistentslackbuild5 added to upgrade queue.*nonexistentslackbuild4 added to upgrade queue.*Upgrade queue: nonexistentslackbuild5 nonexistentslackbuild4\n/s +}); + +# Cleanup +capture_merged { + system(qw!/sbin/removepkg nonexistentslackbuild!); + system(qw!/sbin/removepkg nonexistentslackbuild4!); + system(qw!/sbin/removepkg nonexistentslackbuild5!); + unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; + unlink "$RealBin/LO/nonexistentslackbuild4/perf.dummy"; + unlink "$RealBin/LO/nonexistentslackbuild5/perf.dummy"; +}; diff --git a/t/03-online.t b/t/03-online.t new file mode 100755 index 0000000..c04366f --- /dev/null +++ b/t/03-online.t @@ -0,0 +1,107 @@ +#!/usr/bin/env perl + +use 5.16.0; +use strict; +use warnings FATAL => 'all'; +use File::Temp qw(tempdir tempfile); +use Test::More; +use Test::Output; +use File::Copy; +use FindBin '$RealBin'; + +BEGIN { + chdir($RealBin); + system($^X, 'prep.pl') unless -d 'SBO'; +} + +use lib "."; +use SBO::Lib qw/ :all /; + +if (defined $ENV{TEST_ONLINE} and $ENV{TEST_ONLINE} eq '1') { + plan tests => 7; +} else { + plan skip_all => 'Not doing online tests unless TEST_ONLINE is set to 1'; +} + +chomp(my $pwd = `pwd`); +my $sbo_home = "$pwd/sbo"; + +$conf_file = "$pwd/sbotools.conf"; +$SBO::Lib::conf_file = $conf_file; +@SBO::Lib::config{'LOCAL_OVERRIDES', 'REPO'} = ('FALSE', 'FALSE'); +read_config; +$config{SBO_HOME} = $sbo_home; +my $repo_path = "$sbo_home/repo"; +$SBO::Lib::repo_path = $repo_path; +$SBO::Lib::distfiles = "$sbo_home/distfiles"; +$SBO::Lib::slackbuilds_txt = "$repo_path/SLACKBUILDS.TXT"; +$SBO::Lib::pkg_db = "$pwd/packages"; +chk_slackbuilds_txt(); + +# 1-2: check_distfiles test +{ + my $symlinks; + stderr_like(sub { $symlinks = check_distfiles(LOCATION => "$repo_path/perl/perl-Sort-Versions"); }, + qr/Resolving search[.]cpan[.]org/, 'check_distfiles output good'); + is($$symlinks[0], "$repo_path/perl/perl-Sort-Versions/Sort-Versions-1.5.tar.gz", + 'check_distfiles test 01'); +} + +# 3-4: get_distfile tests +{ + my $distfile = "$sbo_home/distfiles/Sort-Versions-1.5.tar.gz"; + unlink $distfile if -f $distfile; + my $ret; + stderr_like ( + sub { $ret = get_distfile('http://search.cpan.org/CPAN/authors/id/E/ED/EDAVIS/Sort-Versions-1.5.tar.gz', '5434f948fdea6406851c77bebbd0ed19') }, + qr/Resolving search[.]cpan[.]org/, 'get_distfile output good'); + is ($ret, 1, 'get_distfile test 01'); + unlink $distfile; +} + +# 5: test sbosrcarch +SKIP: { + skip "Not doing sbosrcarch test under Travis CI", 1 if $ENV{TRAVIS}; + + subtest 'sbosrcarch tests', + sub { + plan tests => 5; + + my $symlinks; + stderr_like ( sub { $symlinks = check_distfiles(LOCATION => "$repo_path/audio/test"); }, + qr/ERROR 404: Not Found[.].*Resolving slackware[.]uk/s, 'link not found, using sbosrcarch'); + my $sym = $symlinks->[0]; + my $fn = "eawpats12_full.tar.gz"; + is ($sym, "$repo_path/audio/test/$fn", 'symlink is in the right place'); + ok (-l $sym, 'symlink is actually a symlink'); + is (readlink($sym), "$sbo_home/distfiles/$fn", 'symlink leads to the right place'); + ok (unlink(readlink($sym), $sym), "deleting $fn works"); + }; +} + +# 6: test pull_sbo_tree +SKIP: { + skip "Travis doesn't have a new enough rsync", 1 if $ENV{TRAVIS}; + + local $SBO::Lib::repo_path = "$repo_path/tmp"; + local $SBO::Lib::config{SLACKWARE_VERSION} = '14.2'; + local $SBO::Lib::config{REPO} = 'rsync://slackbuilds.org/slackbuilds/14.1/'; + check_repo(); + + use Capture::Tiny 'capture_stdout'; + my $stdout = capture_stdout( sub { pull_sbo_tree() } ); + like ($stdout, qr/100%/, 'pull_sbo_tree output correct'); + + system('rm', '-rf', $SBO::Lib::repo_path); +} + +# 7: move things back to pre-migration state +subtest 'move things back to pre-migration state', +sub { + foreach my $fname (glob("$repo_path/*")) { + is(system('mv', $fname, $sbo_home), 0, "moving $fname to pre-migration place works"); + } + ok (rmdir($repo_path), "removing $repo_path works"); +}; + +# end of tests. diff --git a/t/04-install.t b/t/04-install.t new file mode 100755 index 0000000..db1c87a --- /dev/null +++ b/t/04-install.t @@ -0,0 +1,103 @@ +#!/usr/bin/env perl + +use 5.16.0; +use strict; +use warnings FATAL => 'all'; +use Test::More; +use Capture::Tiny qw/ capture_merged /; +use FindBin '$RealBin'; +use lib $RealBin; +use lib "$RealBin/../SBO-Lib/lib"; +use Test::Execute; + +if ($ENV{TEST_INSTALL}) { + plan tests => 8; +} else { + plan skip_all => 'Only run these tests if TEST_INSTALL=1'; +} +$ENV{TEST_ONLINE} //= 0; + +$path = "$RealBin/../"; + +sub cleanup { + capture_merged { + system(qw!/sbin/removepkg nonexistentslackbuild!); + system(qw!/sbin/removepkg nonexistentslackbuild4!); + system(qw!/sbin/removepkg nonexistentslackbuild5!); + unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; + unlink "$RealBin/LO/nonexistentslackbuild4/perf.dummy"; + unlink "$RealBin/LO/nonexistentslackbuild5/perf.dummy"; + unlink "$RealBin/LO/failingslackbuild/perf.dummy"; + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.0!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.0!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-1.0!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild4!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild5!); + }; +} + +sub make_slackbuilds_txt { + state $made = 0; + my $fname = "/usr/sbo/repo/SLACKBUILDS.TXT"; + if ($_[0]) { + if ($made) { return system(qw!rm -rf!, $fname); } + } else { + if (not -e $fname) { $made = 1; system('mkdir', '-p', '/usr/sbo/repo'); system('touch', $fname); } + } +} + +sub set_lo { + state $set = 0; + state $lo; + if ($_[0]) { + if ($set) { script (qw/ sboconfig -o /, $lo, { test => 0 }); } + } else { + ($lo) = script (qw/ sboconfig -l /, { expected => qr/LOCAL_OVERRIDES=(.*)/, test => 0 }); + $lo //= 'FALSE'; + note "Saving original value of LOCAL_OVERRIDES: $lo"; + $set = 1; + script (qw/ sboconfig -o /, "$RealBin/LO", { test => 0 }); + } +} + +cleanup(); +make_slackbuilds_txt(); +set_lo(); + + +# 1-2: sboinstall nonexistentslackbuild +script (qw/ sboinstall nonexistentslackbuild /, { input => "y\ny", expected => qr/nonexistentslackbuild added to install queue.*Install queue: nonexistentslackbuild/s }); +ok (! -e "$RealBin/LO/nonexistentslackbuild/perf.dummy", "Source symlink removed"); +script (qw/ sboremove nonexistentslackbuild /, { input => "y\ny", test => 0 }); + +# 3: sboinstall nonexistentslackbuild2 +script (qw/ sboinstall nonexistentslackbuild2 /, { exit => 1, expected => "Unable to locate nonexistentslackbuild3 in the SlackBuilds.org tree.\n" }); + +# 4: sboinstall nonexistentslackbuild3 +script (qw/ sboinstall nonexistentslackbuild3 /, { exit => 1, expected => "Unable to locate nonexistentslackbuild3 in the SlackBuilds.org tree.\n" }); + +# 5: sboinstall nonexistentslackbuild4 +script(qw/ sboinstall nonexistentslackbuild4 /, { input => "y\ny\ny", + expected => qr/nonexistentslackbuild5 added to install queue.*nonexistentslackbuild4 added to install queue.*Install queue: nonexistentslackbuild5 nonexistentslackbuild4/s }); +script (qw/ sboremove nonexistentslackbuild5 /, { input => "y\ny", test => 0 }); + +# 6: sboinstall nonexistentslackbuild5 +script (qw/ sboinstall nonexistentslackbuild5 /, { input => "y\ny", expected => qr/nonexistentslackbuild5 added to install queue.*Install queue: nonexistentslackbuild5/s }); +script (qw/ sboremove nonexistentslackbuild4 /, { input => "y\ny\ny", test => 0 }); + +# 7: sboinstall nonexistentslackbuild4 +script (qw/ sboinstall nonexistentslackbuild4 /, { input => "y\ny\ny", + expected => qr/nonexistentslackbuild5 added to install queue.*nonexistentslackbuild4 added to install queue.*Install queue: nonexistentslackbuild5 nonexistentslackbuild4/s }); +script (qw/ sboremove nonexistentslackbuild5 /, { input => "y\ny", test => 0 }); + +# 8: sboinstall nonexistentslackbuild4 +script (qw/ sboinstall nonexistentslackbuild4 /, { input => "y\ny", expected => qr/nonexistentslackbuild5 added to install queue.*Install queue: nonexistentslackbuild5/s }); +script (qw/ sboremove nonexistentslackbuild4 nonexistentslackbuild5 /, { input => "y\ny\ny", test => 0 }); + +# Cleanup +END { + set_lo('delete'); + make_slackbuilds_txt('delete'); + cleanup(); +} diff --git a/t/05-upgrade.t b/t/05-upgrade.t new file mode 100755 index 0000000..8417cf0 --- /dev/null +++ b/t/05-upgrade.t @@ -0,0 +1,130 @@ +#!/usr/bin/env perl + +use 5.16.0; +use strict; +use warnings FATAL => 'all'; +use Test::More; +use Capture::Tiny qw/ capture_merged /; +use FindBin '$RealBin'; +use lib $RealBin; +use lib "$RealBin/../SBO-Lib/lib"; +use Test::Execute; + +if ($ENV{TEST_INSTALL}) { + plan tests => 13; +} else { + plan skip_all => 'Only run these tests if TEST_INSTALL=1'; +} +$ENV{TEST_ONLINE} //= 0; + +$path = "$RealBin/../"; + +sub cleanup { + capture_merged { + system(qw!/sbin/removepkg nonexistentslackbuild!); + system(qw!/sbin/removepkg nonexistentslackbuild4!); + system(qw!/sbin/removepkg nonexistentslackbuild5!); + unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; + unlink "$RealBin/LO/nonexistentslackbuild4/perf.dummy"; + unlink "$RealBin/LO/nonexistentslackbuild5/perf.dummy"; + unlink "$RealBin/LO2/nonexistentslackbuild/perf.dummy"; + unlink "$RealBin/LO2/nonexistentslackbuild4/perf.dummy"; + unlink "$RealBin/LO2/nonexistentslackbuild5/perf.dummy"; + unlink "$RealBin/LO3/nonexistentslackbuild/perf.dummy"; + unlink "$RealBin/LO3/nonexistentslackbuild4/perf.dummy"; + unlink "$RealBin/LO3/nonexistentslackbuild5/perf.dummy"; + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-0.9!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-0.9!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-0.9!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.0!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.0!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-1.0!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.1!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.1!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-1.1!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild4!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild5!); + }; +} + +sub make_slackbuilds_txt { + state $made = 0; + my $fname = "/usr/sbo/repo/SLACKBUILDS.TXT"; + if ($_[0]) { + if ($made) { return system(qw!rm -rf!, $fname); } + } else { + if (not -e $fname) { $made = 1; system('mkdir', '-p', '/usr/sbo/repo'); system('touch', $fname); } + } +} + +sub set_lo { + state $set = 0; + state $lo; + if ($_[0]) { + if ($set) { script (qw/ sboconfig -o /, $lo, { test => 0 }); } + } else { + ($lo) = script (qw/ sboconfig -l /, { expected => qr/LOCAL_OVERRIDES=(.*)/, test => 0 }); + $lo //= 'FALSE'; + note "Saving original value of LOCAL_OVERRIDES: $lo"; + $set = 1; + script (qw/ sboconfig -o /, "$RealBin/LO", { test => 0 }); + } +} + +cleanup(); +make_slackbuilds_txt(); +set_lo(); + +sub install { + cleanup(); + my $lo = shift; + my @pkgs = @_; + + script (qw/ sboconfig -o /, "$RealBin/LO", { test => 0 }); + for my $pkg (@pkgs) { + script (qw/ sboinstall -r /, $pkg, { test => 0 }); + } + script (qw/ sboconfig -o /, "$RealBin/$lo", { test => 0 }); +} + +# 1-2: sboupgrade nonexistentslackbuild when it doesn't need to be upgraded +install( 'LO', 'nonexistentslackbuild' ); +script (qw/ sboupgrade nonexistentslackbuild /, { expected => '' }); +script (qw/ sboupgrade -f nonexistentslackbuild /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild\b.*Upgrade queue: nonexistentslackbuild\n/s }); + +# 3-7: sboupgrade nonexistentslackbuild4 and 5 when they don't need to be upgraded +install( 'LO', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); +script (qw/ sboupgrade nonexistentslackbuild4 /, { expected => '' }); +script (qw/ sboupgrade nonexistentslackbuild5 /, { expected => '' }); +script (qw/ sboupgrade -f nonexistentslackbuild4 /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild4\b.*Upgrade queue: nonexistentslackbuild4\n/s }); +script (qw/ sboupgrade -f nonexistentslackbuild5 /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Upgrade queue: nonexistentslackbuild5\n/s }); +script (qw/ sboupgrade -f -z nonexistentslackbuild4 /, { input => "y\ny\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Proceed with nonexistentslackbuild4\b.*Upgrade queue: nonexistentslackbuild5 nonexistentslackbuild4\n/s }); + +# 8: sboupgrade nonexistentslackbuild when it needs to be upgraded +install( 'LO2', 'nonexistentslackbuild' ); +script (qw/ sboupgrade nonexistentslackbuild /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild\b.*Upgrade queue: nonexistentslackbuild\n/s }); + +# 9: sboupgrade nonexistentslackbuild4 and 5 when they need to be upgraded +install( 'LO2', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); +script (qw/ sboupgrade nonexistentslackbuild4 /, { input => "y\ny\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Proceed with nonexistentslackbuild4\b.*Upgrade queue: nonexistentslackbuild5 nonexistentslackbuild4\n/s }); + +# 10-11: sboupgrade nonexistentslackbuild4 and 5 when only 5 needs an update +install( 'LO3', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); +script (qw/ sboupgrade nonexistentslackbuild4 /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Upgrade queue: nonexistentslackbuild5\n/s }); +install( 'LO3', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); +script (qw/ sboupgrade -f nonexistentslackbuild4 /, { input => "y\ny\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Proceed with nonexistentslackbuild4\b.*Upgrade queue: nonexistentslackbuild5 nonexistentslackbuild4\n/s }); + +# 12-13: sboupgrade --all +install( 'LO2', 'nonexistentslackbuild' ); +my @sbos = glob("/var/log/packages/*_SBo"); +script (qw/ sboupgrade --all /, { input => ("n\n" x (@sbos+1)), expected => qr/Proceed with nonexistentslackbuild\b/ }); +install( 'LO2', 'nonexistentslackbuild', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); +script(qw/ sboupgrade --all /, { input => ("n\n" x (@sbos+3)), expected => qr/Proceed with nonexistentslackbuild\b.*Proceed with nonexistentslackbuild5\b.*Proceed with nonexistentslackbuild4\b/s }); + +# Cleanup +END { + set_lo('delete'); + make_slackbuilds_txt('delete'); + cleanup(); +} diff --git a/t/06-remove.t b/t/06-remove.t new file mode 100755 index 0000000..dfe4c6f --- /dev/null +++ b/t/06-remove.t @@ -0,0 +1,90 @@ +#!/usr/bin/env perl + +use 5.16.0; +use strict; +use warnings FATAL => 'all'; +use Test::More; +use Capture::Tiny qw/ capture_merged /; +use FindBin '$RealBin'; +use lib $RealBin; +use lib "$RealBin/../SBO-Lib/lib"; +use Test::Execute; + +if ($ENV{TEST_INSTALL}) { + plan tests => 4; +} else { + plan skip_all => 'Only run these tests if TEST_INSTALL=1'; +} +$ENV{TEST_ONLINE} //= 0; + +$path = "$RealBin/../"; + +sub cleanup { + capture_merged { + system(qw!/sbin/removepkg nonexistentslackbuild!); + system(qw!/sbin/removepkg nonexistentslackbuild4!); + system(qw!/sbin/removepkg nonexistentslackbuild5!); + unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; + unlink "$RealBin/LO/nonexistentslackbuild4/perf.dummy"; + unlink "$RealBin/LO/nonexistentslackbuild5/perf.dummy"; + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.0!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.0!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-1.0!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild4!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild5!); + }; +} + +sub make_slackbuilds_txt { + state $made = 0; + my $fname = "/usr/sbo/repo/SLACKBUILDS.TXT"; + if ($_[0]) { + if ($made) { return system(qw!rm -rf!, $fname); } + } else { + if (not -e $fname) { $made = 1; system('mkdir', '-p', '/usr/sbo/repo'); system('touch', $fname); } + } +} + +sub set_lo { + state $set = 0; + state $lo; + if ($_[0]) { + if ($set) { script (qw/ sboconfig -o /, $lo, { test => 0 }); } + } else { + ($lo) = script (qw/ sboconfig -l /, { expected => qr/LOCAL_OVERRIDES=(.*)/, test => 0 }); + $lo //= 'FALSE'; + note "Saving original value of LOCAL_OVERRIDES: $lo"; + $set = 1; + script (qw/ sboconfig -o /, "$RealBin/LO", { test => 0 }); + } +} + +cleanup(); +make_slackbuilds_txt(); +set_lo(); + + +# 1: sboremove nonexistentslackbuild +script (qw/ sboinstall nonexistentslackbuild /, { input => "y\ny", test => 0 }); +script (qw/ sboremove nonexistentslackbuild /, { input => "y\ny", expected => qr/Remove nonexistentslackbuild\b.*Removing 1 package\(s\)/s }); + +# 2: sboremove nonexistentslackbuild5 +script (qw/ sboinstall nonexistentslackbuild4 /, { input => "y\ny\ny", test => 0 }); +script (qw/ sboremove nonexistentslackbuild5 /, { input => "y\ny", expected => qr/Remove nonexistentslackbuild5\b.*Removing 1 package\(s\)/s }); + +# 3: sboremove nonexistentslackbuild4 +script (qw/ sboinstall nonexistentslackbuild5 /, { input => "y\ny", test => 0 }); +script (qw/ sboremove nonexistentslackbuild4 /, { input => "y\ny\ny", expected => qr/Remove nonexistentslackbuild4\b.*Remove nonexistentslackbuild5\b.*Removing 2 package\(s\)/s }); + +# 4: sboremove nonexistentslackbuild4 nonexistentslackbuild5 +script (qw/ sboinstall nonexistentslackbuild4 /, { input => "y\ny\ny", test => 0 }); +script (qw/ sboremove nonexistentslackbuild4 nonexistentslackbuild5 /, { input => "y\ny\ny", + expected => qr/Remove nonexistentslackbuild4\b.*Remove nonexistentslackbuild5\b.*Removing 2 package\(s\)/s }); + +# Cleanup +END { + set_lo('delete'); + make_slackbuilds_txt('delete'); + cleanup(); +} diff --git a/t/07-fail.t b/t/07-fail.t new file mode 100755 index 0000000..c747bfb --- /dev/null +++ b/t/07-fail.t @@ -0,0 +1,181 @@ +#!/usr/bin/env perl + +use 5.16.0; +use strict; +use warnings FATAL => 'all'; +use Test::More; +use Capture::Tiny qw/ capture_merged /; +use FindBin '$RealBin'; +use lib $RealBin; +use lib "$RealBin/../SBO-Lib/lib"; +use Test::Execute; + +if ($ENV{TEST_INSTALL}) { + plan tests => 16; +} else { + plan skip_all => 'Only run these tests if TEST_INSTALL=1'; +} +$ENV{TEST_ONLINE} //= 0; +$ENV{TEST_MULTILIB} //= 0; + +$path = "$RealBin/../"; + +sub cleanup { + capture_merged { + unlink "$RealBin/LO-fail/failingslackbuild/perf.dummy"; + unlink "$RealBin/LO-fail/failingslackbuild2/perf.dummy"; + unlink "$RealBin/LO-fail/failingdownload/perf.dummy.fail"; + unlink "$RealBin/LO-fail/failingdownload2/perf.dummy.fail"; + unlink "$RealBin/LO-fail/failingmd5sum/perf.dummy"; + unlink "$RealBin/LO-fail/failingmd5sum2/perf.dummy"; + unlink "$RealBin/LO-fail/nonexistentslackbuild/perf.dummy"; + unlink "$RealBin/LO-fail/nonexistentslackbuild2/perf.dummy"; + unlink "$RealBin/LO-fail/nonexistentslackbuild3/perf.dummy"; + unlink "$RealBin/LO-fail/nonexistentslackbuild4/perf.dummy"; + unlink "$RealBin/LO-fail/malformed-noinfo/perf.dummy"; + unlink "$RealBin/LO-fail/malformed-info/perf.dummy"; + unlink "$RealBin/LO-fail/malformed-readme/perf.dummy"; + unlink "$RealBin/LO-fail/malformed-slackbuild/perf.dummy"; + unlink "$RealBin/LO-fail/multilibfail/perf.dummy"; + system(qw!rm -rf /tmp/SBo/failingslackbuild-1.0!); + system(qw!rm -rf /tmp/SBo/failingslackbuild2-1.0!); + system(qw!rm -rf /tmp/SBo/failingdownload-1.0!); + system(qw!rm -rf /tmp/SBo/failingdownload2-1.0!); + system(qw!rm -rf /tmp/SBo/failingmd5sum-1.0!); + system(qw!rm -rf /tmp/SBo/failingmd5sum2-1.0!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.0!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild2-1.0!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild3-1.0!); + system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.0!); + system(qw!rm -rf /tmp/SBo/malformed-noinfo-1.0!); + system(qw!rm -rf /tmp/SBo/malformed-info-1.0!); + system(qw!rm -rf /tmp/SBo/malformed-readme-1.0!); + system(qw!rm -rf /tmp/SBo/malformed-slackbuild-1.0!); + system(qw!rm -rf /tmp/SBo/multilibfail-1.0!); + system(qw!rm -rf /tmp/package-failingslackbuild!); + system(qw!rm -rf /tmp/package-failingslackbuild2!); + system(qw!rm -rf /tmp/package-failingdownload!); + system(qw!rm -rf /tmp/package-failingdownload2!); + system(qw!rm -rf /tmp/package-failingmd5sum!); + system(qw!rm -rf /tmp/package-failingmd5sum2!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild2!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild3!); + system(qw!rm -rf /tmp/package-nonexistentslackbuild4!); + system(qw!rm -rf /tmp/package-malformed-noinfo!); + system(qw!rm -rf /tmp/package-malformed-info!); + system(qw!rm -rf /tmp/package-malformed-readme!); + system(qw!rm -rf /tmp/package-malformed-slackbuild!); + system(qw!rm -rf /tmp/package-multilibfail!); + }; +} + +sub make_slackbuilds_txt { + state $made = 0; + my $fname = "/usr/sbo/repo/SLACKBUILDS.TXT"; + if ($_[0]) { + if ($made) { return system(qw!rm -rf!, $fname); } + } else { + if (not -e $fname) { $made = 1; system('mkdir', '-p', '/usr/sbo/repo'); system('touch', $fname); } + } +} + +sub set_lo { + state $set = 0; + state $lo; + if ($_[0]) { + if ($set) { script (qw/ sboconfig -o /, $lo, { test => 0 }); } + } else { + ($lo) = script (qw/ sboconfig -l /, { expected => qr/LOCAL_OVERRIDES=(.*)/, test => 0 }); + $lo //= 'FALSE'; + note "Saving original value of LOCAL_OVERRIDES: $lo"; + $set = 1; + script (qw/ sboconfig -o /, "$RealBin/LO-fail", { test => 0 }); + } +} + +cleanup(); +make_slackbuilds_txt(); +set_lo(); + +# 1: Failing slackbuild script +script (qw/ sboinstall failingslackbuild /, { input => "y\ny", expected => qr/Failures:\n failingslackbuild: failingslackbuild.SlackBuild return non-zero\n\z/, exit => 3 }); + +# 2-3: Failing download and md5sum +SKIP: { + skip "Not doing online tests", 2 unless $ENV{TEST_ONLINE}; + + script (qw/ sboinstall failingdownload /, { input => "y\ny\nn", expected => qr!Failures:\n failingdownload: Unable to wget http://www[.]pastemobile[.]org/perf[.]dummy[.]fail[.]\n!, exit => 5 }); + script (qw/ sboinstall failingmd5sum /, { input => "y\ny\nn", expected => qr!Failures:\n failingmd5sum: md5sum failure for /usr/sbo/distfiles/perf[.]dummy[.]\n!, exit => 4 }); +} + +# 4: Failing dependency +script (qw/ sboinstall nonexistentslackbuild2 /, { input => "y\ny\ny\nn", expected => qr/Failures:\n failingslackbuild: failingslackbuild.SlackBuild return non-zero\n/, exit => 3 }); + +# 5-6: Failing download and md5sum in dependency +SKIP: { + skip "Not doing online tests", 2 unless $ENV{TEST_ONLINE}; + + script (qw/ sboinstall nonexistentslackbuild3 /, { input => "y\ny\ny\nn", expected => qr!Failures:\n failingdownload: Unable to wget http://www[.]pastemobile[.]org/perf[.]dummy[.]fail[.]\n!, exit => 5 }); + script (qw/ sboinstall nonexistentslackbuild4 /, { input => "y\ny\ny\nn", expected => qr!Failures:\n failingmd5sum: md5sum failure for /usr/sbo/distfiles/perf[.]dummy[.]\n!, exit => 4 }); +} + +# 7: Failing build with working dep +script (qw/ sboinstall failingslackbuild2 /, { input => "y\ny\ny", expected => qr/Failures:\n failingslackbuild2: failingslackbuild2[.]SlackBuild return non-zero\n\z/, exit => 3 }); +script (qw/ sboremove nonexistentslackbuild /, { input => "y\ny", test => 0 }); + +# 8-9: Failing download and md5sum with working dep +SKIP: { + skip "Not doing online tests", 2 unless $ENV{TEST_ONLINE}; + + script (qw/ sboinstall failingdownload2 /, { input => "y\ny\ny\nn", expected => qr!Failures:\n!, exit => 5 }); + script (qw/ sboinstall failingmd5sum2 /, { input => "y\ny\ny\nn", expected => qr!Failures:\n!, exit => 4 }); +} + +# 10: Malformed slackbuild - no .info +script (qw/ sboinstall malformed-noinfo /, { expected => "A fatal script error has occurred:\nopen_fh, $RealBin/LO-fail/malformed-noinfo/malformed-noinfo.info is not a file\nExiting.\n", exit => 2 }); + +# 11: Malformed slackbuild - malformed .info +script (qw/ sboinstall malformed-info /, { input => "y\ny\nn", expected => qr!Failures:\n malformed-info: Unable to get download info from $RealBin/LO-fail/malformed-info/malformed-info[.]info\n!, exit => 7 }); + +# 12: Malformed slackbuild - no readme +script (qw/ sboinstall malformed-readme /, { expected => "A fatal script error has occurred:\nopen_fh, $RealBin/LO-fail/malformed-readme/README is not a file\nExiting.\n", exit => 2 }); + +# 13: Malformed slackbuild - no .SlackBuild +script (qw/ sboinstall malformed-slackbuild /, + { input => "y\ny", expected => qr!Failures:\n malformed-slackbuild: Unable to backup \Q$RealBin/LO-fail/malformed-slackbuild/malformed-slackbuild.SlackBuild to $RealBin/LO-fail/malformed-slackbuild/malformed-slackbuild.SlackBuild.orig\E!, exit => 6 }); + +# 14: Multilib fails - no multilib +SKIP: { + skip "No multilib test only valid when TEST_MULTILIB=0", 1 unless $ENV{TEST_MULTILIB} == 0; + skip "/etc/profile.d/32dev.sh exists", 1 if -e "/etc/profile.d/32dev.sh"; + + script (qw/ sboinstall -p nonexistentslackbuild /, { input => "y\ny\ny", expected => qr/Failures:\n nonexistentslackbuild-compat32: compat32 requires multilib[.]\n/, exit => 9 }); + script (qw/ sboremove nonexistentslackbuild /, { input => "y\ny", test => 0 }); +} + +# 15: Multilib fails - no convertpkg +SKIP: { + skip "No convertpkg test only valid when TEST_MULTILIB=1", 1 unless $ENV{TEST_MULTILIB} == 1; + skip "/etc/profile.d/32dev.sh doesn't exist", 1 unless -e "/etc/profile.d/32dev.sh"; + skip "/usr/sbin/convertpkg-compat32 exists", 1 if -e "/usr/sbin/convertpkg-compat32"; + + script (qw/ sboinstall -p nonexistentslackbuild /, { input => "y\ny\ny", expected => qr!Failures:\n nonexistentslackbuild-compat32: compat32 requires /usr/sbin/convertpkg-compat32[.]\n!, exit => 11 }); +} + +# 16: Multilib fails - convertpkg fail +SKIP: { + skip "Multilib convertpkg fail test only valid if TEST_MULTILIB=2", 1 unless $ENV{TEST_MULTILIB} == 2; + skip "This test is designed to be run in the Travis CI environment", 1 unless $ENV{TRAVIS}; + skip "No /etc/profile.d/32dev.sh", 1 unless -e "/etc/profile.d/32dev.sh"; + skip "No /usr/sbin/convertpkg-compat32", 1 unless -e "/usr/sbin/convertpkg-compat32"; + + script (qw/ sboinstall -p multilibfail /, { input => "y\ny\ny", expected => qr/Failures:\n multilibfail-compat32: convertpkg-compt32 returned non-zero exit status\n/, exit => 10 }); +} + +# Cleanup +END { + set_lo('delete'); + make_slackbuilds_txt('delete'); + cleanup(); +} diff --git a/t/08-env.t b/t/08-env.t new file mode 100755 index 0000000..e7573bd --- /dev/null +++ b/t/08-env.t @@ -0,0 +1,199 @@ +#!/usr/bin/env perl + +use 5.16.0; +use strict; +use warnings FATAL => 'all'; +use Test::More; +use Capture::Tiny qw/ capture_merged /; +use FindBin '$RealBin'; +use lib $RealBin; +use lib "$RealBin/../SBO-Lib/lib"; +use Test::Execute; + +if ($ENV{TEST_INSTALL}) { + plan tests => 5; +} else { + plan skip_all => 'Only run these tests if TEST_INSTALL=1'; +} +$ENV{TEST_ONLINE} //= 0; + +$path = "$RealBin/../"; + +sub cleanup { + my $tmp = shift; + my $output = shift; + capture_merged { + system(qw!/sbin/removepkg nonexistentslackbuild!); + system(qw!/sbin/removepkg nonexistentslackbuild4!); + system(qw!/sbin/removepkg nonexistentslackbuild5!); + unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; + unlink "$RealBin/LO/nonexistentslackbuild4/perf.dummy"; + unlink "$RealBin/LO/nonexistentslackbuild5/perf.dummy"; + system(qw!rm -rf!, "$tmp/nonexistentslackbuild-1.0"); + system(qw!rm -rf!, "$tmp/nonexistentslackbuild4-1.0"); + system(qw!rm -rf!, "$tmp/nonexistentslackbuild5-1.0"); + system(qw!rm -rf!, "$output/package-nonexistentslackbuild"); + system(qw!rm -rf!, "$output/package-nonexistentslackbuild4"); + system(qw!rm -rf!, "$output/package-nonexistentslackbuild5"); + }; +} + +sub make_slackbuilds_txt { + state $made = 0; + my $fname = "/usr/sbo/repo/SLACKBUILDS.TXT"; + if ($_[0]) { + if ($made) { return system(qw!rm -rf!, $fname); } + } else { + if (not -e $fname) { $made = 1; system('mkdir', '-p', '/usr/sbo/repo'); system('touch', $fname); } + } +} + +sub set_lo { + state $set = 0; + state $lo; + if ($_[0]) { + if ($set) { script (qw/ sboconfig -o /, $lo, { test => 0 }); } + } else { + ($lo) = script (qw/ sboconfig -l /, { expected => qr/LOCAL_OVERRIDES=(.*)/, test => 0 }); + $lo //= 'FALSE'; + note "Saving original value of LOCAL_OVERRIDES: $lo"; + $set = 1; + script (qw/ sboconfig -o /, "$RealBin/LO", { test => 0 }); + } +} + +cleanup('/tmp/SBo', '/tmp'); +make_slackbuilds_txt(); +set_lo(); + + +SKIP: { + skip "Not testing unset OUTPUT", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne ''; + subtest 'OUTPUT unset', + sub { + delete local $ENV{OUTPUT}; + tmp_tests(); + }; +} + +SKIP: { + skip "Not testing OUTPUT=/tmp", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne '/tmp'; + subtest 'OUTPUT=/tmp', + sub { + local $ENV{OUTPUT}='/tmp'; + tmp_tests(); + }; +} + +SKIP: { + skip "Not testing OUTPUT=/tmp", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne '/tmp/SBo'; + subtest 'OUTPUT=/tmp/SBo', + sub { + local $ENV{OUTPUT}='/tmp/SBo'; + tmp_tests(); + }; +} + +SKIP: { + skip "Not testing OUTPUT=/tmp/foo", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne '/tmp/foo'; + subtest 'OUTPUT=/tmp/foo', + sub { + local $ENV{OUTPUT}='/tmp/foo'; + tmp_tests(); + }; +} + +SKIP: { + skip "Not testing OUTPUT=/tmp/bar", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne '/tmp/bar'; + subtest 'OUTPUT=/tmp/bar', + sub { + local $ENV{OUTPUT}='/tmp/bar'; + tmp_tests(); + }; +} + +sub tmp_tests { + plan tests => 4; + + SKIP: { + skip "Not testing unset TMP", 1 if exists $ENV{TEST_TMP} and $ENV{TEST_TMP} ne ''; + subtest 'TMP unset', + sub { + delete local $ENV{TMP}; + env_tests(); + }; + } + + SKIP: { + skip "Not testing TMP=/tmp", 1 if exists $ENV{TEST_TMP} and $ENV{TEST_TMP} ne '/tmp'; + subtest 'TMP=/tmp', + sub { + local $ENV{TMP}='/tmp'; + env_tests(); + }; + } + + SKIP: { + skip "Not testing TMP=/tmp/SBo", 1 if exists $ENV{TEST_TMP} and $ENV{TEST_TMP} ne '/tmp/SBo'; + subtest 'TMP=/tmp/SBo', + sub { + local $ENV{TMP}='/tmp/SBo'; + env_tests(); + }; + } + + SKIP: { + skip "Not testing TMP=/tmp/foo", 1 if exists $ENV{TEST_TMP} and $ENV{TEST_TMP} ne '/tmp/foo'; + subtest 'TMP=/tmp/foo', + sub { + local $ENV{TMP}='/tmp/foo'; + env_tests(); + }; + } +} + +sub env_tests { + my $tmp = $ENV{TMP} // '/tmp/SBo'; + my $output = $ENV{OUTPUT} // '/tmp'; + cleanup($tmp, $output); + my $tmpmsg = "TMP=" . ( defined $ENV{TMP} ? $tmp : '' ); + my $outmsg = "OUTPUT=" . ( defined $ENV{OUTPUT} ? $output : '' ); + + plan tests => 20; + + ok (! -e "$tmp/nonexistentslackbuild-1.0/README", "README file 1 doesn't exist ($tmpmsg)"); + ok (! -e "$tmp/nonexistentslackbuild4-1.0/README", "README file 4 doesn't exist ($tmpmsg)"); + ok (! -e "$tmp/nonexistentslackbuild5-1.0/README", "README file 5 doesn't exist ($tmpmsg)"); + ok (! -e "$output/package-nonexistentslackbuild", "package dir 1 doesn't exist ($outmsg)"); + ok (! -e "$output/package-nonexistentslackbuild4", "package4 dir 1 doesn't exist ($outmsg)"); + ok (! -e "$output/package-nonexistentslackbuild5", "package5 dir 1 doesn't exist ($outmsg)"); + script (qw/ sboinstall -c FALSE nonexistentslackbuild /, { input => "y\ny", expected => qr!Cleaning for nonexistentslackbuild-1\.0!, note => 0 }); + ok (! -e "$tmp/nonexistentslackbuild-1.0/README", "README file 1 doesn't exist after sboinstall ($tmpmsg)"); + ok (! -e "$output/package-nonexistentslackbuild", "package dir 1 doesn't exist after sboinstall ($outmsg)"); + script (qw/ sboinstall -c FALSE nonexistentslackbuild4 /, + { input => "y\ny\ny", expected => qr!Cleaning for nonexistentslackbuild5-1\.0.*Cleaning for nonexistentslackbuild4-1\.0!s, note => 0 }); + ok (! -e "$tmp/nonexistentslackbuild4-1.0/README", "README file 4 doesn't exist after sboinstall ($tmpmsg)"); + ok (! -e "$tmp/nonexistentslackbuild5-1.0/README", "README file 5 doesn't exist after sboinstall ($tmpmsg)"); + ok (! -e "$output/package-nonexistentslackbuild4", "package dir 4 doesn't exist after sboinstall ($outmsg)"); + ok (! -e "$output/package-nonexistentslackbuild5", "package dir 5 doesn't exist after sboinstall ($outmsg)"); + + cleanup($tmp, $output); + + script (qw/ sboinstall -c TRUE nonexistentslackbuild /, { input => "y\ny", test => 0, note => 0 }); + ok (-e "$tmp/nonexistentslackbuild-1.0/README", "README file 1 exists after sboinstall -c TRUE ($tmpmsg)"); + ok (-e "$output/package-nonexistentslackbuild", "package dir 1 exists after sboinstall -c TRUE ($outmsg)"); + script (qw/ sboinstall -c TRUE nonexistentslackbuild4 /, { input => "y\ny\ny", test => 0, note => 0 }); + ok (-e "$tmp/nonexistentslackbuild4-1.0/README", "README file 4 exists after sboinstall -c TRUE ($tmpmsg)"); + ok (-e "$tmp/nonexistentslackbuild5-1.0/README", "README file 5 exists after sboinstall -c TRUE ($tmpmsg)"); + ok (-e "$output/package-nonexistentslackbuild4", "package dir 4 exists after sboinstall -c TRUE ($outmsg)"); + ok (-e "$output/package-nonexistentslackbuild5", "package dir 5 exists after sboinstall -c TRUE ($outmsg)"); + + cleanup($tmp, $output); +} + +# Cleanup +END { + set_lo('delete'); + make_slackbuilds_txt('delete'); + cleanup('/tmp/SBo', '/tmp'); +} diff --git a/t/env.t b/t/env.t deleted file mode 100755 index e7573bd..0000000 --- a/t/env.t +++ /dev/null @@ -1,199 +0,0 @@ -#!/usr/bin/env perl - -use 5.16.0; -use strict; -use warnings FATAL => 'all'; -use Test::More; -use Capture::Tiny qw/ capture_merged /; -use FindBin '$RealBin'; -use lib $RealBin; -use lib "$RealBin/../SBO-Lib/lib"; -use Test::Execute; - -if ($ENV{TEST_INSTALL}) { - plan tests => 5; -} else { - plan skip_all => 'Only run these tests if TEST_INSTALL=1'; -} -$ENV{TEST_ONLINE} //= 0; - -$path = "$RealBin/../"; - -sub cleanup { - my $tmp = shift; - my $output = shift; - capture_merged { - system(qw!/sbin/removepkg nonexistentslackbuild!); - system(qw!/sbin/removepkg nonexistentslackbuild4!); - system(qw!/sbin/removepkg nonexistentslackbuild5!); - unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; - unlink "$RealBin/LO/nonexistentslackbuild4/perf.dummy"; - unlink "$RealBin/LO/nonexistentslackbuild5/perf.dummy"; - system(qw!rm -rf!, "$tmp/nonexistentslackbuild-1.0"); - system(qw!rm -rf!, "$tmp/nonexistentslackbuild4-1.0"); - system(qw!rm -rf!, "$tmp/nonexistentslackbuild5-1.0"); - system(qw!rm -rf!, "$output/package-nonexistentslackbuild"); - system(qw!rm -rf!, "$output/package-nonexistentslackbuild4"); - system(qw!rm -rf!, "$output/package-nonexistentslackbuild5"); - }; -} - -sub make_slackbuilds_txt { - state $made = 0; - my $fname = "/usr/sbo/repo/SLACKBUILDS.TXT"; - if ($_[0]) { - if ($made) { return system(qw!rm -rf!, $fname); } - } else { - if (not -e $fname) { $made = 1; system('mkdir', '-p', '/usr/sbo/repo'); system('touch', $fname); } - } -} - -sub set_lo { - state $set = 0; - state $lo; - if ($_[0]) { - if ($set) { script (qw/ sboconfig -o /, $lo, { test => 0 }); } - } else { - ($lo) = script (qw/ sboconfig -l /, { expected => qr/LOCAL_OVERRIDES=(.*)/, test => 0 }); - $lo //= 'FALSE'; - note "Saving original value of LOCAL_OVERRIDES: $lo"; - $set = 1; - script (qw/ sboconfig -o /, "$RealBin/LO", { test => 0 }); - } -} - -cleanup('/tmp/SBo', '/tmp'); -make_slackbuilds_txt(); -set_lo(); - - -SKIP: { - skip "Not testing unset OUTPUT", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne ''; - subtest 'OUTPUT unset', - sub { - delete local $ENV{OUTPUT}; - tmp_tests(); - }; -} - -SKIP: { - skip "Not testing OUTPUT=/tmp", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne '/tmp'; - subtest 'OUTPUT=/tmp', - sub { - local $ENV{OUTPUT}='/tmp'; - tmp_tests(); - }; -} - -SKIP: { - skip "Not testing OUTPUT=/tmp", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne '/tmp/SBo'; - subtest 'OUTPUT=/tmp/SBo', - sub { - local $ENV{OUTPUT}='/tmp/SBo'; - tmp_tests(); - }; -} - -SKIP: { - skip "Not testing OUTPUT=/tmp/foo", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne '/tmp/foo'; - subtest 'OUTPUT=/tmp/foo', - sub { - local $ENV{OUTPUT}='/tmp/foo'; - tmp_tests(); - }; -} - -SKIP: { - skip "Not testing OUTPUT=/tmp/bar", 1 if exists $ENV{TEST_OUTPUT} and $ENV{TEST_OUTPUT} ne '/tmp/bar'; - subtest 'OUTPUT=/tmp/bar', - sub { - local $ENV{OUTPUT}='/tmp/bar'; - tmp_tests(); - }; -} - -sub tmp_tests { - plan tests => 4; - - SKIP: { - skip "Not testing unset TMP", 1 if exists $ENV{TEST_TMP} and $ENV{TEST_TMP} ne ''; - subtest 'TMP unset', - sub { - delete local $ENV{TMP}; - env_tests(); - }; - } - - SKIP: { - skip "Not testing TMP=/tmp", 1 if exists $ENV{TEST_TMP} and $ENV{TEST_TMP} ne '/tmp'; - subtest 'TMP=/tmp', - sub { - local $ENV{TMP}='/tmp'; - env_tests(); - }; - } - - SKIP: { - skip "Not testing TMP=/tmp/SBo", 1 if exists $ENV{TEST_TMP} and $ENV{TEST_TMP} ne '/tmp/SBo'; - subtest 'TMP=/tmp/SBo', - sub { - local $ENV{TMP}='/tmp/SBo'; - env_tests(); - }; - } - - SKIP: { - skip "Not testing TMP=/tmp/foo", 1 if exists $ENV{TEST_TMP} and $ENV{TEST_TMP} ne '/tmp/foo'; - subtest 'TMP=/tmp/foo', - sub { - local $ENV{TMP}='/tmp/foo'; - env_tests(); - }; - } -} - -sub env_tests { - my $tmp = $ENV{TMP} // '/tmp/SBo'; - my $output = $ENV{OUTPUT} // '/tmp'; - cleanup($tmp, $output); - my $tmpmsg = "TMP=" . ( defined $ENV{TMP} ? $tmp : '' ); - my $outmsg = "OUTPUT=" . ( defined $ENV{OUTPUT} ? $output : '' ); - - plan tests => 20; - - ok (! -e "$tmp/nonexistentslackbuild-1.0/README", "README file 1 doesn't exist ($tmpmsg)"); - ok (! -e "$tmp/nonexistentslackbuild4-1.0/README", "README file 4 doesn't exist ($tmpmsg)"); - ok (! -e "$tmp/nonexistentslackbuild5-1.0/README", "README file 5 doesn't exist ($tmpmsg)"); - ok (! -e "$output/package-nonexistentslackbuild", "package dir 1 doesn't exist ($outmsg)"); - ok (! -e "$output/package-nonexistentslackbuild4", "package4 dir 1 doesn't exist ($outmsg)"); - ok (! -e "$output/package-nonexistentslackbuild5", "package5 dir 1 doesn't exist ($outmsg)"); - script (qw/ sboinstall -c FALSE nonexistentslackbuild /, { input => "y\ny", expected => qr!Cleaning for nonexistentslackbuild-1\.0!, note => 0 }); - ok (! -e "$tmp/nonexistentslackbuild-1.0/README", "README file 1 doesn't exist after sboinstall ($tmpmsg)"); - ok (! -e "$output/package-nonexistentslackbuild", "package dir 1 doesn't exist after sboinstall ($outmsg)"); - script (qw/ sboinstall -c FALSE nonexistentslackbuild4 /, - { input => "y\ny\ny", expected => qr!Cleaning for nonexistentslackbuild5-1\.0.*Cleaning for nonexistentslackbuild4-1\.0!s, note => 0 }); - ok (! -e "$tmp/nonexistentslackbuild4-1.0/README", "README file 4 doesn't exist after sboinstall ($tmpmsg)"); - ok (! -e "$tmp/nonexistentslackbuild5-1.0/README", "README file 5 doesn't exist after sboinstall ($tmpmsg)"); - ok (! -e "$output/package-nonexistentslackbuild4", "package dir 4 doesn't exist after sboinstall ($outmsg)"); - ok (! -e "$output/package-nonexistentslackbuild5", "package dir 5 doesn't exist after sboinstall ($outmsg)"); - - cleanup($tmp, $output); - - script (qw/ sboinstall -c TRUE nonexistentslackbuild /, { input => "y\ny", test => 0, note => 0 }); - ok (-e "$tmp/nonexistentslackbuild-1.0/README", "README file 1 exists after sboinstall -c TRUE ($tmpmsg)"); - ok (-e "$output/package-nonexistentslackbuild", "package dir 1 exists after sboinstall -c TRUE ($outmsg)"); - script (qw/ sboinstall -c TRUE nonexistentslackbuild4 /, { input => "y\ny\ny", test => 0, note => 0 }); - ok (-e "$tmp/nonexistentslackbuild4-1.0/README", "README file 4 exists after sboinstall -c TRUE ($tmpmsg)"); - ok (-e "$tmp/nonexistentslackbuild5-1.0/README", "README file 5 exists after sboinstall -c TRUE ($tmpmsg)"); - ok (-e "$output/package-nonexistentslackbuild4", "package dir 4 exists after sboinstall -c TRUE ($outmsg)"); - ok (-e "$output/package-nonexistentslackbuild5", "package dir 5 exists after sboinstall -c TRUE ($outmsg)"); - - cleanup($tmp, $output); -} - -# Cleanup -END { - set_lo('delete'); - make_slackbuilds_txt('delete'); - cleanup('/tmp/SBo', '/tmp'); -} diff --git a/t/fail.t b/t/fail.t deleted file mode 100755 index c747bfb..0000000 --- a/t/fail.t +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/env perl - -use 5.16.0; -use strict; -use warnings FATAL => 'all'; -use Test::More; -use Capture::Tiny qw/ capture_merged /; -use FindBin '$RealBin'; -use lib $RealBin; -use lib "$RealBin/../SBO-Lib/lib"; -use Test::Execute; - -if ($ENV{TEST_INSTALL}) { - plan tests => 16; -} else { - plan skip_all => 'Only run these tests if TEST_INSTALL=1'; -} -$ENV{TEST_ONLINE} //= 0; -$ENV{TEST_MULTILIB} //= 0; - -$path = "$RealBin/../"; - -sub cleanup { - capture_merged { - unlink "$RealBin/LO-fail/failingslackbuild/perf.dummy"; - unlink "$RealBin/LO-fail/failingslackbuild2/perf.dummy"; - unlink "$RealBin/LO-fail/failingdownload/perf.dummy.fail"; - unlink "$RealBin/LO-fail/failingdownload2/perf.dummy.fail"; - unlink "$RealBin/LO-fail/failingmd5sum/perf.dummy"; - unlink "$RealBin/LO-fail/failingmd5sum2/perf.dummy"; - unlink "$RealBin/LO-fail/nonexistentslackbuild/perf.dummy"; - unlink "$RealBin/LO-fail/nonexistentslackbuild2/perf.dummy"; - unlink "$RealBin/LO-fail/nonexistentslackbuild3/perf.dummy"; - unlink "$RealBin/LO-fail/nonexistentslackbuild4/perf.dummy"; - unlink "$RealBin/LO-fail/malformed-noinfo/perf.dummy"; - unlink "$RealBin/LO-fail/malformed-info/perf.dummy"; - unlink "$RealBin/LO-fail/malformed-readme/perf.dummy"; - unlink "$RealBin/LO-fail/malformed-slackbuild/perf.dummy"; - unlink "$RealBin/LO-fail/multilibfail/perf.dummy"; - system(qw!rm -rf /tmp/SBo/failingslackbuild-1.0!); - system(qw!rm -rf /tmp/SBo/failingslackbuild2-1.0!); - system(qw!rm -rf /tmp/SBo/failingdownload-1.0!); - system(qw!rm -rf /tmp/SBo/failingdownload2-1.0!); - system(qw!rm -rf /tmp/SBo/failingmd5sum-1.0!); - system(qw!rm -rf /tmp/SBo/failingmd5sum2-1.0!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.0!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild2-1.0!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild3-1.0!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.0!); - system(qw!rm -rf /tmp/SBo/malformed-noinfo-1.0!); - system(qw!rm -rf /tmp/SBo/malformed-info-1.0!); - system(qw!rm -rf /tmp/SBo/malformed-readme-1.0!); - system(qw!rm -rf /tmp/SBo/malformed-slackbuild-1.0!); - system(qw!rm -rf /tmp/SBo/multilibfail-1.0!); - system(qw!rm -rf /tmp/package-failingslackbuild!); - system(qw!rm -rf /tmp/package-failingslackbuild2!); - system(qw!rm -rf /tmp/package-failingdownload!); - system(qw!rm -rf /tmp/package-failingdownload2!); - system(qw!rm -rf /tmp/package-failingmd5sum!); - system(qw!rm -rf /tmp/package-failingmd5sum2!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild2!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild3!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild4!); - system(qw!rm -rf /tmp/package-malformed-noinfo!); - system(qw!rm -rf /tmp/package-malformed-info!); - system(qw!rm -rf /tmp/package-malformed-readme!); - system(qw!rm -rf /tmp/package-malformed-slackbuild!); - system(qw!rm -rf /tmp/package-multilibfail!); - }; -} - -sub make_slackbuilds_txt { - state $made = 0; - my $fname = "/usr/sbo/repo/SLACKBUILDS.TXT"; - if ($_[0]) { - if ($made) { return system(qw!rm -rf!, $fname); } - } else { - if (not -e $fname) { $made = 1; system('mkdir', '-p', '/usr/sbo/repo'); system('touch', $fname); } - } -} - -sub set_lo { - state $set = 0; - state $lo; - if ($_[0]) { - if ($set) { script (qw/ sboconfig -o /, $lo, { test => 0 }); } - } else { - ($lo) = script (qw/ sboconfig -l /, { expected => qr/LOCAL_OVERRIDES=(.*)/, test => 0 }); - $lo //= 'FALSE'; - note "Saving original value of LOCAL_OVERRIDES: $lo"; - $set = 1; - script (qw/ sboconfig -o /, "$RealBin/LO-fail", { test => 0 }); - } -} - -cleanup(); -make_slackbuilds_txt(); -set_lo(); - -# 1: Failing slackbuild script -script (qw/ sboinstall failingslackbuild /, { input => "y\ny", expected => qr/Failures:\n failingslackbuild: failingslackbuild.SlackBuild return non-zero\n\z/, exit => 3 }); - -# 2-3: Failing download and md5sum -SKIP: { - skip "Not doing online tests", 2 unless $ENV{TEST_ONLINE}; - - script (qw/ sboinstall failingdownload /, { input => "y\ny\nn", expected => qr!Failures:\n failingdownload: Unable to wget http://www[.]pastemobile[.]org/perf[.]dummy[.]fail[.]\n!, exit => 5 }); - script (qw/ sboinstall failingmd5sum /, { input => "y\ny\nn", expected => qr!Failures:\n failingmd5sum: md5sum failure for /usr/sbo/distfiles/perf[.]dummy[.]\n!, exit => 4 }); -} - -# 4: Failing dependency -script (qw/ sboinstall nonexistentslackbuild2 /, { input => "y\ny\ny\nn", expected => qr/Failures:\n failingslackbuild: failingslackbuild.SlackBuild return non-zero\n/, exit => 3 }); - -# 5-6: Failing download and md5sum in dependency -SKIP: { - skip "Not doing online tests", 2 unless $ENV{TEST_ONLINE}; - - script (qw/ sboinstall nonexistentslackbuild3 /, { input => "y\ny\ny\nn", expected => qr!Failures:\n failingdownload: Unable to wget http://www[.]pastemobile[.]org/perf[.]dummy[.]fail[.]\n!, exit => 5 }); - script (qw/ sboinstall nonexistentslackbuild4 /, { input => "y\ny\ny\nn", expected => qr!Failures:\n failingmd5sum: md5sum failure for /usr/sbo/distfiles/perf[.]dummy[.]\n!, exit => 4 }); -} - -# 7: Failing build with working dep -script (qw/ sboinstall failingslackbuild2 /, { input => "y\ny\ny", expected => qr/Failures:\n failingslackbuild2: failingslackbuild2[.]SlackBuild return non-zero\n\z/, exit => 3 }); -script (qw/ sboremove nonexistentslackbuild /, { input => "y\ny", test => 0 }); - -# 8-9: Failing download and md5sum with working dep -SKIP: { - skip "Not doing online tests", 2 unless $ENV{TEST_ONLINE}; - - script (qw/ sboinstall failingdownload2 /, { input => "y\ny\ny\nn", expected => qr!Failures:\n!, exit => 5 }); - script (qw/ sboinstall failingmd5sum2 /, { input => "y\ny\ny\nn", expected => qr!Failures:\n!, exit => 4 }); -} - -# 10: Malformed slackbuild - no .info -script (qw/ sboinstall malformed-noinfo /, { expected => "A fatal script error has occurred:\nopen_fh, $RealBin/LO-fail/malformed-noinfo/malformed-noinfo.info is not a file\nExiting.\n", exit => 2 }); - -# 11: Malformed slackbuild - malformed .info -script (qw/ sboinstall malformed-info /, { input => "y\ny\nn", expected => qr!Failures:\n malformed-info: Unable to get download info from $RealBin/LO-fail/malformed-info/malformed-info[.]info\n!, exit => 7 }); - -# 12: Malformed slackbuild - no readme -script (qw/ sboinstall malformed-readme /, { expected => "A fatal script error has occurred:\nopen_fh, $RealBin/LO-fail/malformed-readme/README is not a file\nExiting.\n", exit => 2 }); - -# 13: Malformed slackbuild - no .SlackBuild -script (qw/ sboinstall malformed-slackbuild /, - { input => "y\ny", expected => qr!Failures:\n malformed-slackbuild: Unable to backup \Q$RealBin/LO-fail/malformed-slackbuild/malformed-slackbuild.SlackBuild to $RealBin/LO-fail/malformed-slackbuild/malformed-slackbuild.SlackBuild.orig\E!, exit => 6 }); - -# 14: Multilib fails - no multilib -SKIP: { - skip "No multilib test only valid when TEST_MULTILIB=0", 1 unless $ENV{TEST_MULTILIB} == 0; - skip "/etc/profile.d/32dev.sh exists", 1 if -e "/etc/profile.d/32dev.sh"; - - script (qw/ sboinstall -p nonexistentslackbuild /, { input => "y\ny\ny", expected => qr/Failures:\n nonexistentslackbuild-compat32: compat32 requires multilib[.]\n/, exit => 9 }); - script (qw/ sboremove nonexistentslackbuild /, { input => "y\ny", test => 0 }); -} - -# 15: Multilib fails - no convertpkg -SKIP: { - skip "No convertpkg test only valid when TEST_MULTILIB=1", 1 unless $ENV{TEST_MULTILIB} == 1; - skip "/etc/profile.d/32dev.sh doesn't exist", 1 unless -e "/etc/profile.d/32dev.sh"; - skip "/usr/sbin/convertpkg-compat32 exists", 1 if -e "/usr/sbin/convertpkg-compat32"; - - script (qw/ sboinstall -p nonexistentslackbuild /, { input => "y\ny\ny", expected => qr!Failures:\n nonexistentslackbuild-compat32: compat32 requires /usr/sbin/convertpkg-compat32[.]\n!, exit => 11 }); -} - -# 16: Multilib fails - convertpkg fail -SKIP: { - skip "Multilib convertpkg fail test only valid if TEST_MULTILIB=2", 1 unless $ENV{TEST_MULTILIB} == 2; - skip "This test is designed to be run in the Travis CI environment", 1 unless $ENV{TRAVIS}; - skip "No /etc/profile.d/32dev.sh", 1 unless -e "/etc/profile.d/32dev.sh"; - skip "No /usr/sbin/convertpkg-compat32", 1 unless -e "/usr/sbin/convertpkg-compat32"; - - script (qw/ sboinstall -p multilibfail /, { input => "y\ny\ny", expected => qr/Failures:\n multilibfail-compat32: convertpkg-compt32 returned non-zero exit status\n/, exit => 10 }); -} - -# Cleanup -END { - set_lo('delete'); - make_slackbuilds_txt('delete'); - cleanup(); -} diff --git a/t/install.t b/t/install.t deleted file mode 100755 index db1c87a..0000000 --- a/t/install.t +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env perl - -use 5.16.0; -use strict; -use warnings FATAL => 'all'; -use Test::More; -use Capture::Tiny qw/ capture_merged /; -use FindBin '$RealBin'; -use lib $RealBin; -use lib "$RealBin/../SBO-Lib/lib"; -use Test::Execute; - -if ($ENV{TEST_INSTALL}) { - plan tests => 8; -} else { - plan skip_all => 'Only run these tests if TEST_INSTALL=1'; -} -$ENV{TEST_ONLINE} //= 0; - -$path = "$RealBin/../"; - -sub cleanup { - capture_merged { - system(qw!/sbin/removepkg nonexistentslackbuild!); - system(qw!/sbin/removepkg nonexistentslackbuild4!); - system(qw!/sbin/removepkg nonexistentslackbuild5!); - unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; - unlink "$RealBin/LO/nonexistentslackbuild4/perf.dummy"; - unlink "$RealBin/LO/nonexistentslackbuild5/perf.dummy"; - unlink "$RealBin/LO/failingslackbuild/perf.dummy"; - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.0!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.0!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-1.0!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild4!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild5!); - }; -} - -sub make_slackbuilds_txt { - state $made = 0; - my $fname = "/usr/sbo/repo/SLACKBUILDS.TXT"; - if ($_[0]) { - if ($made) { return system(qw!rm -rf!, $fname); } - } else { - if (not -e $fname) { $made = 1; system('mkdir', '-p', '/usr/sbo/repo'); system('touch', $fname); } - } -} - -sub set_lo { - state $set = 0; - state $lo; - if ($_[0]) { - if ($set) { script (qw/ sboconfig -o /, $lo, { test => 0 }); } - } else { - ($lo) = script (qw/ sboconfig -l /, { expected => qr/LOCAL_OVERRIDES=(.*)/, test => 0 }); - $lo //= 'FALSE'; - note "Saving original value of LOCAL_OVERRIDES: $lo"; - $set = 1; - script (qw/ sboconfig -o /, "$RealBin/LO", { test => 0 }); - } -} - -cleanup(); -make_slackbuilds_txt(); -set_lo(); - - -# 1-2: sboinstall nonexistentslackbuild -script (qw/ sboinstall nonexistentslackbuild /, { input => "y\ny", expected => qr/nonexistentslackbuild added to install queue.*Install queue: nonexistentslackbuild/s }); -ok (! -e "$RealBin/LO/nonexistentslackbuild/perf.dummy", "Source symlink removed"); -script (qw/ sboremove nonexistentslackbuild /, { input => "y\ny", test => 0 }); - -# 3: sboinstall nonexistentslackbuild2 -script (qw/ sboinstall nonexistentslackbuild2 /, { exit => 1, expected => "Unable to locate nonexistentslackbuild3 in the SlackBuilds.org tree.\n" }); - -# 4: sboinstall nonexistentslackbuild3 -script (qw/ sboinstall nonexistentslackbuild3 /, { exit => 1, expected => "Unable to locate nonexistentslackbuild3 in the SlackBuilds.org tree.\n" }); - -# 5: sboinstall nonexistentslackbuild4 -script(qw/ sboinstall nonexistentslackbuild4 /, { input => "y\ny\ny", - expected => qr/nonexistentslackbuild5 added to install queue.*nonexistentslackbuild4 added to install queue.*Install queue: nonexistentslackbuild5 nonexistentslackbuild4/s }); -script (qw/ sboremove nonexistentslackbuild5 /, { input => "y\ny", test => 0 }); - -# 6: sboinstall nonexistentslackbuild5 -script (qw/ sboinstall nonexistentslackbuild5 /, { input => "y\ny", expected => qr/nonexistentslackbuild5 added to install queue.*Install queue: nonexistentslackbuild5/s }); -script (qw/ sboremove nonexistentslackbuild4 /, { input => "y\ny\ny", test => 0 }); - -# 7: sboinstall nonexistentslackbuild4 -script (qw/ sboinstall nonexistentslackbuild4 /, { input => "y\ny\ny", - expected => qr/nonexistentslackbuild5 added to install queue.*nonexistentslackbuild4 added to install queue.*Install queue: nonexistentslackbuild5 nonexistentslackbuild4/s }); -script (qw/ sboremove nonexistentslackbuild5 /, { input => "y\ny", test => 0 }); - -# 8: sboinstall nonexistentslackbuild4 -script (qw/ sboinstall nonexistentslackbuild4 /, { input => "y\ny", expected => qr/nonexistentslackbuild5 added to install queue.*Install queue: nonexistentslackbuild5/s }); -script (qw/ sboremove nonexistentslackbuild4 nonexistentslackbuild5 /, { input => "y\ny\ny", test => 0 }); - -# Cleanup -END { - set_lo('delete'); - make_slackbuilds_txt('delete'); - cleanup(); -} diff --git a/t/online.t b/t/online.t deleted file mode 100755 index c04366f..0000000 --- a/t/online.t +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/env perl - -use 5.16.0; -use strict; -use warnings FATAL => 'all'; -use File::Temp qw(tempdir tempfile); -use Test::More; -use Test::Output; -use File::Copy; -use FindBin '$RealBin'; - -BEGIN { - chdir($RealBin); - system($^X, 'prep.pl') unless -d 'SBO'; -} - -use lib "."; -use SBO::Lib qw/ :all /; - -if (defined $ENV{TEST_ONLINE} and $ENV{TEST_ONLINE} eq '1') { - plan tests => 7; -} else { - plan skip_all => 'Not doing online tests unless TEST_ONLINE is set to 1'; -} - -chomp(my $pwd = `pwd`); -my $sbo_home = "$pwd/sbo"; - -$conf_file = "$pwd/sbotools.conf"; -$SBO::Lib::conf_file = $conf_file; -@SBO::Lib::config{'LOCAL_OVERRIDES', 'REPO'} = ('FALSE', 'FALSE'); -read_config; -$config{SBO_HOME} = $sbo_home; -my $repo_path = "$sbo_home/repo"; -$SBO::Lib::repo_path = $repo_path; -$SBO::Lib::distfiles = "$sbo_home/distfiles"; -$SBO::Lib::slackbuilds_txt = "$repo_path/SLACKBUILDS.TXT"; -$SBO::Lib::pkg_db = "$pwd/packages"; -chk_slackbuilds_txt(); - -# 1-2: check_distfiles test -{ - my $symlinks; - stderr_like(sub { $symlinks = check_distfiles(LOCATION => "$repo_path/perl/perl-Sort-Versions"); }, - qr/Resolving search[.]cpan[.]org/, 'check_distfiles output good'); - is($$symlinks[0], "$repo_path/perl/perl-Sort-Versions/Sort-Versions-1.5.tar.gz", - 'check_distfiles test 01'); -} - -# 3-4: get_distfile tests -{ - my $distfile = "$sbo_home/distfiles/Sort-Versions-1.5.tar.gz"; - unlink $distfile if -f $distfile; - my $ret; - stderr_like ( - sub { $ret = get_distfile('http://search.cpan.org/CPAN/authors/id/E/ED/EDAVIS/Sort-Versions-1.5.tar.gz', '5434f948fdea6406851c77bebbd0ed19') }, - qr/Resolving search[.]cpan[.]org/, 'get_distfile output good'); - is ($ret, 1, 'get_distfile test 01'); - unlink $distfile; -} - -# 5: test sbosrcarch -SKIP: { - skip "Not doing sbosrcarch test under Travis CI", 1 if $ENV{TRAVIS}; - - subtest 'sbosrcarch tests', - sub { - plan tests => 5; - - my $symlinks; - stderr_like ( sub { $symlinks = check_distfiles(LOCATION => "$repo_path/audio/test"); }, - qr/ERROR 404: Not Found[.].*Resolving slackware[.]uk/s, 'link not found, using sbosrcarch'); - my $sym = $symlinks->[0]; - my $fn = "eawpats12_full.tar.gz"; - is ($sym, "$repo_path/audio/test/$fn", 'symlink is in the right place'); - ok (-l $sym, 'symlink is actually a symlink'); - is (readlink($sym), "$sbo_home/distfiles/$fn", 'symlink leads to the right place'); - ok (unlink(readlink($sym), $sym), "deleting $fn works"); - }; -} - -# 6: test pull_sbo_tree -SKIP: { - skip "Travis doesn't have a new enough rsync", 1 if $ENV{TRAVIS}; - - local $SBO::Lib::repo_path = "$repo_path/tmp"; - local $SBO::Lib::config{SLACKWARE_VERSION} = '14.2'; - local $SBO::Lib::config{REPO} = 'rsync://slackbuilds.org/slackbuilds/14.1/'; - check_repo(); - - use Capture::Tiny 'capture_stdout'; - my $stdout = capture_stdout( sub { pull_sbo_tree() } ); - like ($stdout, qr/100%/, 'pull_sbo_tree output correct'); - - system('rm', '-rf', $SBO::Lib::repo_path); -} - -# 7: move things back to pre-migration state -subtest 'move things back to pre-migration state', -sub { - foreach my $fname (glob("$repo_path/*")) { - is(system('mv', $fname, $sbo_home), 0, "moving $fname to pre-migration place works"); - } - ok (rmdir($repo_path), "removing $repo_path works"); -}; - -# end of tests. diff --git a/t/remove.t b/t/remove.t deleted file mode 100755 index dfe4c6f..0000000 --- a/t/remove.t +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env perl - -use 5.16.0; -use strict; -use warnings FATAL => 'all'; -use Test::More; -use Capture::Tiny qw/ capture_merged /; -use FindBin '$RealBin'; -use lib $RealBin; -use lib "$RealBin/../SBO-Lib/lib"; -use Test::Execute; - -if ($ENV{TEST_INSTALL}) { - plan tests => 4; -} else { - plan skip_all => 'Only run these tests if TEST_INSTALL=1'; -} -$ENV{TEST_ONLINE} //= 0; - -$path = "$RealBin/../"; - -sub cleanup { - capture_merged { - system(qw!/sbin/removepkg nonexistentslackbuild!); - system(qw!/sbin/removepkg nonexistentslackbuild4!); - system(qw!/sbin/removepkg nonexistentslackbuild5!); - unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; - unlink "$RealBin/LO/nonexistentslackbuild4/perf.dummy"; - unlink "$RealBin/LO/nonexistentslackbuild5/perf.dummy"; - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.0!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.0!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-1.0!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild4!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild5!); - }; -} - -sub make_slackbuilds_txt { - state $made = 0; - my $fname = "/usr/sbo/repo/SLACKBUILDS.TXT"; - if ($_[0]) { - if ($made) { return system(qw!rm -rf!, $fname); } - } else { - if (not -e $fname) { $made = 1; system('mkdir', '-p', '/usr/sbo/repo'); system('touch', $fname); } - } -} - -sub set_lo { - state $set = 0; - state $lo; - if ($_[0]) { - if ($set) { script (qw/ sboconfig -o /, $lo, { test => 0 }); } - } else { - ($lo) = script (qw/ sboconfig -l /, { expected => qr/LOCAL_OVERRIDES=(.*)/, test => 0 }); - $lo //= 'FALSE'; - note "Saving original value of LOCAL_OVERRIDES: $lo"; - $set = 1; - script (qw/ sboconfig -o /, "$RealBin/LO", { test => 0 }); - } -} - -cleanup(); -make_slackbuilds_txt(); -set_lo(); - - -# 1: sboremove nonexistentslackbuild -script (qw/ sboinstall nonexistentslackbuild /, { input => "y\ny", test => 0 }); -script (qw/ sboremove nonexistentslackbuild /, { input => "y\ny", expected => qr/Remove nonexistentslackbuild\b.*Removing 1 package\(s\)/s }); - -# 2: sboremove nonexistentslackbuild5 -script (qw/ sboinstall nonexistentslackbuild4 /, { input => "y\ny\ny", test => 0 }); -script (qw/ sboremove nonexistentslackbuild5 /, { input => "y\ny", expected => qr/Remove nonexistentslackbuild5\b.*Removing 1 package\(s\)/s }); - -# 3: sboremove nonexistentslackbuild4 -script (qw/ sboinstall nonexistentslackbuild5 /, { input => "y\ny", test => 0 }); -script (qw/ sboremove nonexistentslackbuild4 /, { input => "y\ny\ny", expected => qr/Remove nonexistentslackbuild4\b.*Remove nonexistentslackbuild5\b.*Removing 2 package\(s\)/s }); - -# 4: sboremove nonexistentslackbuild4 nonexistentslackbuild5 -script (qw/ sboinstall nonexistentslackbuild4 /, { input => "y\ny\ny", test => 0 }); -script (qw/ sboremove nonexistentslackbuild4 nonexistentslackbuild5 /, { input => "y\ny\ny", - expected => qr/Remove nonexistentslackbuild4\b.*Remove nonexistentslackbuild5\b.*Removing 2 package\(s\)/s }); - -# Cleanup -END { - set_lo('delete'); - make_slackbuilds_txt('delete'); - cleanup(); -} diff --git a/t/test.t b/t/test.t deleted file mode 100755 index ee7e1fb..0000000 --- a/t/test.t +++ /dev/null @@ -1,642 +0,0 @@ -#!/usr/bin/env perl - -use 5.16.0; -use strict; -use warnings FATAL => 'all'; -use File::Temp qw(tempdir tempfile); -use Test::More; -use Test::Output; -use File::Copy; -use Text::Diff; -use FindBin '$RealBin'; - -BEGIN { - chdir($RealBin); - system($^X, 'prep.pl') unless -d 'SBO'; -} - -use lib "."; -use SBO::Lib qw/ :all /; - -plan tests => 60; - -chomp(my $pwd = `pwd`); -my $sbo_home = "$pwd/sbo"; - -$conf_file = "$pwd/sbotools.conf"; -$SBO::Lib::conf_file = $conf_file; -@SBO::Lib::config{'LOCAL_OVERRIDES', 'REPO'} = ('FALSE', 'FALSE'); -read_config; -$config{SBO_HOME} = $sbo_home; -my $repo_path = "$sbo_home/repo"; -$SBO::Lib::repo_path = $repo_path; -$SBO::Lib::distfiles = "$sbo_home/distfiles"; -$SBO::Lib::slackbuilds_txt = "$repo_path/SLACKBUILDS.TXT"; -$SBO::Lib::pkg_db = "$pwd/packages"; - -# 1-6: config settings tests -is($config{DISTCLEAN}, 'FALSE', 'config{DISTCLEAN} is good'); -is($config{JOBS}, 2, 'config{JOBS} is good'); -is($config{NOCLEAN}, 'FALSE', 'config{NOCLEAN} is good'); -is($config{PKG_DIR}, 'FALSE', 'config{PKG_DIR} is good'); -is($config{SBO_HOME}, "$pwd/sbo", 'config{SBO_HOME} is good'); -is($config{LOCAL_OVERRIDES}, 'FALSE', 'config{LOCAL_OVERRIDES} is good'); - -# 7: open_read, open_fh tests -{ - my $fh = open_read('./test.t'); - is(ref $fh, 'GLOB', 'open_read works'); - close $fh; -} - -# 8: test to ensure tempdir is defined by default -ok(defined $tempdir, '$tempdir is defined'); - -# 9-10: show_version test -my $version_output = <<"VERSION"; -sbotools version 2.0 -licensed under the WTFPL - -VERSION -my $ret; -stdout_is (sub { $ret = show_version(); }, $version_output, 'show_version output is good'); -is( $ret, 1, 'show_version return value is good'); - -# 11-16: get_slack_version test -SKIP: { - skip 'no /etc/slackware-version', 1 unless -f '/etc/slackware-version'; - - local $config{SLACKWARE_VERSION} = 'FALSE'; - chomp(my $version = qx(awk '{print \$2}' /etc/slackware-version)); - is (get_slack_version(), $version, 'get_slack_version is good'); -} -for my $ver (qw/ 14.0 14.1 14.2 15.0 26.80 /) { - local $config{SLACKWARE_VERSION} = $ver; - is (get_slack_version(), $ver, 'get_slack_version gets custom SLACK_VERSION'); -} - -# 17: make sure we migrate when we should -ok(-f "$sbo_home/SLACKBUILDS.TXT", 'SLACKBUILDS.TXT exists pre-migration'); - -# 18-19: chk_slackbuilds_txt tests -is(chk_slackbuilds_txt(), 1, 'chk_slackbuilds_txt is good'); -move("$repo_path/SLACKBUILDS.TXT", "$sbo_home/SLACKBUILDS.TXT.moved"); -is(chk_slackbuilds_txt(), undef, - 'chk_slackbuilds_txt returns false with no SLACKBUILDS.TXT'); -move("$sbo_home/SLACKBUILDS.TXT.moved", "$repo_path/SLACKBUILDS.TXT"); - -# 20: slackbuilds_or_fetch test -is(slackbuilds_or_fetch(), 1, 'slackbuilds_or_fetch is good'); - -# 21: get_installed_packages 'SBO' test -subtest "pseudo-random sampling of get_installed_packages 'SBO' output...", -sub { - plan tests => 8; - - my %expected = ( - OpenAL => '1.13', - 'adobe-reader' => '9.5.1_enu', - libdvdnav => '4.1.3', - libmodplug => '0.8.8.4', - unetbootin => '575', - zdoom => '2.6.0', - 'p7zip-compat32' => '9.20.1', - 'lame-compat32' => '3.99.5', - ); - my $installed = get_installed_packages('SBO'); - - for my $inst (@$installed) { - my $ver = $expected{ $inst->{name} }; - next if not defined $ver; - - is( $inst->{version}, $ver, $inst->{name} ); - } -}; - -# 22: get_installed_packages 'ALL' test -subtest "pseudo-random sampling of get_installed_packages 'ALL' output...", -sub { - plan tests => 8; - - my %expected = ( - OpenAL => '1.13', - gimp => '2.8.2', - libdvdnav => '4.1.3', - perl => '5.16.1', - unetbootin => '575', - zlib => '1.2.6', - 'p7zip-compat32' => '9.20.1', - 'lame-compat32' => '3.99.5', - ); - my $installed = get_installed_packages('ALL'); - - for my $inst (@$installed) { - my $ver = $expected{ $inst->{name} }; - next if not defined $ver; - - is( $inst->{version}, $ver, $inst->{name} ); - } -}; - -# 23: get_sbo_location/get_sbo_locations tests -subtest 'get_sbo_location tests', -sub { - plan tests => 7; - - is(get_sbo_location ('nginx'), "$repo_path/network/nginx", - 'get_sbo_location is good'); - is(get_sbo_locations('omgwtfbbq'), 0, - 'get_sbo_locations returns false with not-an-sbo input'); - is(get_sbo_location ('omgwtfbbq'), undef, - 'get_sbo_location returns false with not-an-sbo input'); - my @finds = qw(nginx gmpc); - my %locs = get_sbo_locations(@finds); - is($locs{nginx}, "$repo_path/network/nginx", - 'get_sbo_locations passed array #1 good'); - is($locs{gmpc}, "$repo_path/audio/gmpc", 'get_sbo_locations passed array #2 good'); - %locs = get_sbo_locations(\@finds); - is($locs{nginx}, "$repo_path/network/nginx", - 'get_sbo_locations passed array ref #1 good'); - is($locs{gmpc}, "$repo_path/audio/gmpc", - 'get_sbo_locations passed array ref #2 good'); -}; - -# 24: get_available_updates tests -subtest 'get_available_updates tests', -sub { - plan tests => 2; - - my $updates = get_available_updates(); - my %expected = ( - mutagen => { installed => '1.15', update => '1.20', }, - ); - for my $upd (@$updates) { - my $vers = $expected{ $upd->{name} }; - next if not defined $vers; - - is ($upd->{installed}, $vers->{installed}, 'installed version is good for mutagen'); - is ($upd->{update}, $vers->{update}, 'update version is good for mutagen'); - } -}; - -# 25: get_arch test -# TODO: uh, this will fail on 32bit, right? -is(get_arch(), 'x86_64', 'get_arch is good'); - -# 26: get_download_info tests -subtest 'get_download_info tests', -sub { - plan tests => 2; - - my $dl_info = get_download_info(LOCATION => "$repo_path/system/wine", X64 => 0); - my $link = 'http://downloads.sf.net/wine/source/1.4/wine-1.4.1.tar.bz2'; - is($$dl_info{$link}, '0c28702ed478df7a1c097f3a9c4cabd6', - 'get_download_info test 01 good.'); - $link = 'http://www.unrealize.co.uk/source/dibeng-max-2010-11-12.zip'; - is($$dl_info{$link}, '97159d77631da13952fe87e846cf1f3b', - 'get_download_info test 02 good.'); -}; - -# 27: get_sbo_downloads tests -subtest 'get_sbo_downloads tests', -sub { - plan tests => 5; - - my $dl_info = get_sbo_downloads(LOCATION => "$repo_path/system/wine"); - my $link = 'http://downloads.sf.net/wine/source/1.4/wine-1.4.1.tar.bz2'; - is($$dl_info{$link}, '0c28702ed478df7a1c097f3a9c4cabd6', - 'get_sbo_downloads test 01 good.'); - $link = 'http://www.unrealize.co.uk/source/dibeng-max-2010-11-12.zip'; - is($$dl_info{$link}, '97159d77631da13952fe87e846cf1f3b', - 'get_sbo_downloads test 02 good.'); - my $downloads = get_sbo_downloads(LOCATION => "$repo_path/system/ifuse"); - $link = 'http://www.libimobiledevice.org/downloads/ifuse-1.1.1.tar.bz2'; - is($$downloads{$link}, '8d528a79de024b91f12f8ac67965c37c', - 'get_sbo_downloads test 03 good.'); - $downloads = get_sbo_downloads(LOCATION => "$repo_path/multimedia/mpv"); - my @links = qw' - https://github.com/mpv-player/mpv/archive/v0.10.0.tar.gz - http://www.freehackers.org/~tnagy/release/waf-1.8.12 - '; - is ($$downloads{$links[0]}, 'e81a975e4fa17f500dc2e7ea3d3ecf25', - 'get_sbo_downloads test 04 good.'); - is ($$downloads{$links[1]}, 'cef4ee82206b1843db082d0b0506bf71', - 'get_sbo_downloads test 05 good.'); -}; - -# 28-29: get_filename_from_link tests -is(get_filename_from_link( - 'http://www.libimobiledevice.org/downloads/ifuse-1.1.1.tar.bz2'), - "$sbo_home/distfiles/ifuse-1.1.1.tar.bz2", 'get_file_from_link good'); -is(get_filename_from_link('adf;lkajsdfaksjdfalsdjfalsdkfjdsfj'), undef, - 'get_filename_from_link good with invalid input'); - -# 30: compute_md5sum test -is(compute_md5sum("$sbo_home/distfiles/test.file"), - '593d3125d3170f0b5326a40a253aa6fd', 'compute_md5sum good'); - -# 31: verify_distfile test -is(verify_distfile("http://dawnrazor.net/test.file", - '593d3125d3170f0b5326a40a253aa6fd'), 1, 'verify_distfile good'); - -# 32: get_sbo_version test -is(get_sbo_version("$repo_path/system/wine"), '1.4.1', 'get_sbo_version good'); - -# 33: get_symlink_from_filename test -is(get_symlink_from_filename("$sbo_home/distfiles/test.file", - "$repo_path/system/laptop-mode-tools"), - "$repo_path/system/laptop-mode-tools/test.file", - 'get_symlink_from_filename good'); - -# 34-35: check_x32 tests -ok(check_x32("$repo_path/system/wine"), 'check_x32 true for 32-bit only wine'); -ok(!(check_x32("$repo_path/system/ifuse")), - 'check_x32 false for not-32-bit-only ifuse'); - -# 36: check_multilib tests -SKIP: { - skip "This is useless to test if TEST_MULTILIB=1", 1 if ($ENV{TEST_MULTILIB} // 0) == 1; - if (-x '/usr/sbin/convertpkg-compat32') { - ok(check_multilib(), 'check_multilib good'); - } else { - ok(!check_multilib(), 'check_multilib good'); - } -} - -# 37: create_symlinks tests -subtest 'create_sumlinks tests', -sub { - plan tests => 2; - - my $downloads = get_sbo_downloads(LOCATION => "$repo_path/system/wine", 32 => 1); - my $symlinks = create_symlinks("$repo_path/system/wine", $downloads); - my ($have1, $have2); - for my $sl (@$symlinks) { - $have1++ if $sl eq "$repo_path/system/wine/wine-1.4.1.tar.bz2"; - $have2++ if $sl eq "$repo_path/system/wine/dibeng-max-2010-11-12.zip"; - } - ok($have1, '$create_symlinks test 1 passed.'); - ok($have2, '$create_symlinks test 2 passed.'); -}; - -# 38: grok_temp_file, get_src_dir/get_pkg_name tests -{ - my $tempdir = tempdir(CLEANUP => 1); - my $tempfh = tempfile(DIR => $tempdir); - my $lmt = 'laptop-mode-tools_1.60'; - print {$tempfh} "$lmt/COPYING\n"; - print {$tempfh} "$lmt/Documentation/\n"; - print {$tempfh} "$lmt/README\n"; - print {$tempfh} "Slackware package skype-2.2.0.35-i486-1_SBo.tgz created.\n"; - is(get_pkg_name($tempfh), 'skype-2.2.0.35-i486-1_SBo.tgz', 'get_pkg_name good'); -} - -# 39-40: get_src_dir tests -SKIP: { - skip 'Need to look into how to do the get_src_dir tests', 2; - # TODO: get this working as it should - # we can not test get_src_dir() at present - we will need to support $TMP in - # order to be able to test this. because user can't write to /tmp/SBo - #close $tempfh; - #$tempfh = tempfile(DIR => $tempdir); - #opendir (my $tsbo_dh, '/tmp/SBo'); - #FIRST: while (readdir $tsbo_dh) { - # next FIRST if /^\.[\.]{0,1}$/; - # say {$tempfh} $_; - #} - #close $tsbo_dh; - #mkdir '/tmp/SBo/test.d.1'; - #mkdir '/tmp/SBo/test.2.d'; - #my $src = get_src_dir $tempfh; - #say ref $src; - #say $_ for @$src; - #is($$src[0], 'test.d.1', 'get_src_dir test 01'); - #is($$src[1], 'test.2.d', 'get_src_dir test 02'); - #rmdir '/tmp/SBo/test.d.1'; - #rmdir '/tmp/SBo/test.2.d'; -} - -# 41: check_repo tests -subtest 'check_repo tests', -sub { - plan tests => 3; - - local $config{SBO_HOME} = "$pwd/test_sbo"; - local $SBO::Lib::repo_path = "$config{SBO_HOME}/repo"; - ok(check_repo(), 'check_repo returns true with new non-existent directory'); - ok(-d "$pwd/test_sbo", 'check_repo creates $config{SBO_HOME}'); - ok(check_repo(), 'check_repo returns true with new existent empty directory'); - rmdir "$pwd/test_sbo"; -}; - -# 42-43: get_sbo_from_loc tests -is(get_sbo_from_loc('/home/d4wnr4z0r/sbo.git/system/ifuse'), 'ifuse', - 'get_sbo_from_loc returns correctly with valid input'); -ok(! get_sbo_from_loc('omg_wtf_bbq'), - 'get_sbo_from_loc returns false with invalid input'); - -# 44: rewrite_slackbuild/revert_slackbuild tests -subtest 'rewrite_slackbuild/revert_slackbuild tests', -sub { - plan tests => 7; - - my $rewrite_dir = tempdir(CLEANUP => 1); - copy("$repo_path/system/ifuse/ifuse.SlackBuild", $rewrite_dir); - my $slackbuild = "$rewrite_dir/ifuse.SlackBuild"; - my $tempfh = tempfile(DIR => $rewrite_dir); - my $tempfn = get_tmp_extfn($tempfh); - my %changes = (); - is(rewrite_slackbuild (SLACKBUILD => $slackbuild, TEMPFN => $tempfn, - CHANGES => \%changes), 1, 'rewrite_slackbuild with no %changes good'); - ok(-f "$slackbuild.orig", 'rewrite_slackbuild backing up original is good.'); - is(revert_slackbuild($slackbuild), 1, 'revert_slackbuild is good'); - $changes{libdirsuffix} = ''; - $changes{make} = '-j 5'; - $changes{arch_out} = 'i486'; - is(rewrite_slackbuild (SLACKBUILD => $slackbuild, CHANGES => \%changes, - C32 => 1, SBO => 'ifuse'), 1, 'rewrite_slackbuild test w/ all %changes'); - ok(-f "$slackbuild.orig", 'rewrite_slackbuild backing up original is good.'); - my $expected_out = <<'END'; -55c55 -< LIBDIRSUFFIX="64" ---- -> LIBDIRSUFFIX="" -67c67 -< tar xvf $CWD/$PRGNAM-$VERSION.tar.bz2 ---- -> tar xvf $CWD/ifuse-1.1.1.tar.bz2 -103c103 -< /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz} ---- -> /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-i486-$BUILD$TAG.${PKGTYPE:-tgz} -END - is(diff("$slackbuild.orig", $slackbuild, {STYLE => 'OldStyle'}), - $expected_out, 'all changed lines rewritten correctly'); - is(revert_slackbuild($slackbuild), 1, 'revert_slackbuild is good again'); -}; - -# 45: get_from_info tests -subtest 'get_from_info tests', -sub { - plan tests => 3; - - my $test_loc = "$repo_path/system/ifuse"; - my %params = (LOCATION => $test_loc); - my $info = get_from_info(%params, GET => 'VERSION'); - is($$info[0], '1.1.1', 'get_from_info GET => VERSION is good'); - $info = get_from_info(%params, GET => 'HOMEPAGE'); - is($$info[0], 'http://www.libimobiledevice.org', - 'get_from_info GET => HOMEPAGE is good'); - $info = get_from_info(%params, GET => 'DOWNLOAD_x86_64'); - is($$info[0], "", 'get_from_info GET => DOWNLOAD_x86_64 is good'); -}; - -# 46: get_update_list tests -subtest 'get_update_list tests', -sub { - plan tests => 5; - - my $listing; - stdout_is(sub { $listing = get_update_list(); }, "Checking for updated SlackBuilds...\n", 'output of get_update_list() good'); - s/\s//g for @$listing; - is (shift(@$listing), 'adobe-reader9.5.1_enu 'Path /omg/wtf/bbq needs to not exist for this test.'; - } else { - plan tests => 2; - } - - my $ret; - stdout_is (sub { $ret = remove_stuff('/omg/wtf/bbq') }, "Nothing to do.\n", 'output for remove_stuff good'); - is($ret, 1, 'remove_stuff good for invalid input'); -}; - -# 48: perform_search tests -subtest 'perform_search tests', -sub { - plan tests => 7; - - my $findings = perform_search('desktop'); - for my $found (@$findings) { - my $name = $found->{name}; - my $location = $found->{location}; - my $section = 'desktop';; - if ($name eq 'libdesktop-agnostic') { - $section = 'libraries'; - } elsif ($name eq 'mendeleydesktop') { - $section = 'academic'; - } elsif ($name eq 'gtk-recordmydesktop' || $name eq 'huludesktop') { - $section = 'multimedia'; - } elsif ($name eq 'gnome-python-desktop') { - $section = 'python'; - } elsif ($name eq 'gsettings-desktop-schemas') { - $section = 'system'; - } - is($location, "$repo_path/$section/$name", - 'perform_search good for $search eq desktop'); - } -}; - -# 49: get_inst_names test -my $inst_names; -{ - my $installed = get_installed_packages('SBO'); - $inst_names = get_inst_names($installed); - my %inst_names; - $inst_names{$_} = 1 for @$inst_names; - ok($inst_names{zdoom}, 'get_inst_names is good'); -} - -# 50: get_reqs tests -subtest 'get_reqs tests', -sub { - plan tests => 5; - - my $reqs = get_requires('gmpc');#, "$sbo_home/audio/gmpc"; - my $name = 'get_requires good for normal req list'; - is($$reqs[0], 'gob2', $name); - is($$reqs[1], 'libmpd', $name); - is($$reqs[2], 'vala', $name); - $reqs = get_requires('doomseeker'); - is($$reqs[0], '%README%', 'get_requires good for REQUIRES="%README%"'); - is(get_requires('krb5')->[0], '', 'get_requires good for REQUIRES=""'); -}; - -# 51: get_user_group tests -subtest 'get_user_group tests', -sub { - plan tests => 4; - - my $fh = open_read("$repo_path/network/nagios/README"); - my $readme = do {local $/; <$fh>}; - close $fh; - my $cmds = get_user_group($readme); - is($$cmds[0], 'groupadd -g 213 nagios', 'get_user_group good for # groupadd'); - is($$cmds[1], 'useradd -u 213 -d /dev/null -s /bin/false -g nagios nagios', - 'get_user_group for # useradd'); - - $fh = open_read("$repo_path/network/havp/README"); - $readme = do {local $/; <$fh>}; - close $fh; - $cmds = get_user_group($readme); - is($$cmds[0], 'groupadd -g 210 clamav', 'get_user_group good for groupadd'); - is($$cmds[1], 'useradd -u 256 -d /dev/null -s /bin/false -g clamav havp', - 'get_user_group good for useradd'); -}; - -# 52: get_opts test -subtest 'get_opts test', -sub { - plan tests => 2; - - my $fh = open_read("$repo_path/games/vbam/README"); - my $readme = do {local $/; <$fh>}; - close $fh; - ok(get_opts($readme), 'get_opts good where README defines opts'); - - $fh = open_read("$repo_path/audio/gmpc/README"); - $readme = do {local $/; <$fh>}; - close $fh; - ok(! (get_opts($readme)), 'get_opts good where README does not define opts'); -}; - -# 53: queue tests -subtest 'queue tests', -sub { - plan tests => 30; - - # test multiple sbo's - # sbo's: zdoom', 'bsnes', 'spring', 'OpenAL' - # expected queue: eawpats TiMidity++ fmodapi p7zip zdoom OpenAL bsnes DevIL jdk spring - my $warnings = {}; - my @t_argv = ( 'zdoom', 'bsnes', 'spring', 'OpenAL' ); - my $queue; - for my $sbo (@t_argv) { - my $queue_sbo = get_build_queue([$sbo], $warnings); - $queue = merge_queues($queue, $queue_sbo); - } - my $count = @$queue; - is($count, 10, 'get_build_queue returns correct amount for multiple sbos'); - is($$queue[0], 'eawpats', 'get_build_queue first entry correct for multiple sbos'); - is($$queue[2], 'fmodapi', 'get_build_queue third entry correct for multiple sbos'); - is($$queue[4], 'zdoom', 'get_build_queue fifth entry correct for multiple sbos'); - is($$queue[6], 'bsnes', 'get_build_queue seventh entry correct for multiple sbos'); - is($$queue[8], 'jdk', 'get_build_queue ninth entry correct for multiple sbos'); - - # test single sbo - # sbo: zdoom - # expected queue: eawpats TiMidity++ fmodapi p7zip zdoom - $queue = get_build_queue(['zdoom'], $warnings); - $count = @$queue; - is($count, 5, 'get_build_queue returns correct amount for single sbo'); - is($$queue[0], 'eawpats', 'get_build_queue first entry correct for single sbo'); - is($$queue[2], 'fmodapi', 'get_build_queue third entry correct for single sbo'); - is($$queue[4], 'zdoom', 'get_build_queue fifth entry correct for single sbo'); - - # https://github.com/pink-mist/sbotools/issues/2 - my $bug_2 = get_build_queue(['dfvfs'], $warnings); - my $bug_2_test = "get_build_queue handles bug 2 properly (%s)"; - my @bug_2_req = qw( - six construct pytz pysetuptools python-dateutil python-gflags - protobuf libbde libewf libqcow - libsigscan libsmdev libsmraw libvhdi libvmdk - libvshadow sleuthkit pytsk dfvfs ); - for my $index (0 .. $#bug_2_req) { - is($$bug_2[$index], $bug_2_req[$index], sprintf($bug_2_test, $bug_2_req[$index])); - } - - # test that we get a warning in $warnings - $queue = get_build_queue(['ffmpeg'], $warnings); - is($warnings->{ffmpeg}, "%README%", 'got ffmpeg README warning'); -}; - -# 54: test get_required_by -subtest 'get_required_by tests', -sub { - plan tests => 3; - - get_reverse_reqs($inst_names); - my $required = get_required_by('p7zip'); - is($$required[0], 'unetbootin', 'get_required_by good for populated req_by list'); - is($$required[1], 'zdoom', 'get_required_by good for populated req_by list'); - is( get_required_by('zdoom'), undef, 'get_required_by good for empty req_by list'); -}; - -# 55-56: test confirm_remove -{ - local @SBO::Lib::confirmed=('p7zip', 'eawpats', 'bsnes'); - confirm_remove('zdoom'); - my $count = @SBO::Lib::confirmed; - is($count, 4, 'confirm_remove good for new sbo'); - confirm_remove('zdoom'); - $count = @SBO::Lib::confirmed; - is($count, 4, 'confirm_remove good for duplicate sbo'); -}; - -# 57: test get_readme_contents -ok(get_readme_contents("$repo_path/network/nagios"), 'get_readme_contents is good'); - -# 58: test get_dl_fns -subtest 'get_dl_fns tests', -sub { - plan tests => 3; - - my $downloads = [ - 'http://developer.download.nvidia.com/cg/Cg_3.1/Cg-3.1_April2012_x86.tgz' - ]; - my $fns = get_dl_fns($downloads); - is($$fns[0], 'Cg-3.1_April2012_x86.tgz', 'get_dl_fns test, one input'); - $downloads = [ - 'http://download.virtualbox.org/virtualbox/4.2.0/VirtualBox-4.2.0.tar.bz2', - 'http://download.virtualbox.org/virtualbox/4.2.0/VBoxGuestAdditions_4.2.0.iso', - 'http://download.virtualbox.org/virtualbox/4.2.0/UserManual.pdf', - 'http://download.virtualbox.org/virtualbox/4.2.0/SDKRef.pdf', - ]; - $fns = get_dl_fns($downloads); - is($$fns[0], 'VirtualBox-4.2.0.tar.bz2', 'get_dl_fns test, multiple inputs 01'); - is($$fns[2], 'UserManual.pdf', 'get_dl_fns test, multiple inputs 02'); -}; - -# 59: test get_dc_regex - multiple tests for various types of input -subtest 'get_dc_regex tests', -sub { - plan tests => 8; - - my $line = 'tar xvf $CWD/$PRGNAM-$VERSION.tar.?z*'; - my ($regex, $initial) = get_dc_regex($line); - is($regex, '(?^u:/[^-]+-[^-]+.tar.[a-z]z.*)', 'get_dc_regex test 01.1'); - is($initial, '/', 'get_dc_regex test 01.2'); - $line = 'tar xvf $CWD/Oracle_VM_VirtualBox_Extension_Pack-$VERSION.vbox-extpack'; - ($regex, $initial) = get_dc_regex($line); - is($regex, '(?^u:/Oracle_VM_VirtualBox_Extension_Pack-[^-]+.vbox-extpack)', - 'get_dc_regex test 02.1'); - is($initial, '/', 'get_dc_regex test 02.2'); - $line = 'tar xvf $CWD/${PRGNAM}-source-$(echo $VERSION).tar.gz'; - ($regex, $initial) = get_dc_regex($line); - is($regex, '(?^u:/[^-]+-source-[^-]+.tar.gz)', 'get_dc_regex test 03.1'); - is($initial, '/', 'get_dc_regex test 03.2'); - $line = '( tar xvf xapian-bindings-$VERSION.tar.gz'; - ($regex, $initial) = get_dc_regex($line); - is($regex, '(?^u: xapian-bindings-[^-]+.tar.gz)', 'get_dc_regex test 04.1'); - is($initial, ' ', 'get_dc_regex test 04.2'); -}; - -# 60: move things back to pre-migration state -subtest 'move things back to pre-migration state', -sub { - foreach my $fname (glob("$repo_path/*")) { - is(system('mv', $fname, $sbo_home), 0, "moving $fname to pre-migration place works"); - } - ok (rmdir($repo_path), "removing $repo_path works"); - ok (do { rmdir("$sbo_home/../test_sbo/repo") and rmdir("$sbo_home/../test_sbo") }, "removing test_sbo works"); -}; - -# end of tests. diff --git a/t/travis.t b/t/travis.t deleted file mode 100755 index 20b2665..0000000 --- a/t/travis.t +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env perl - -use 5.16.0; -use strict; -use warnings FATAL => 'all'; -use Test::More; -use Capture::Tiny qw/ capture_merged /; -use FindBin '$RealBin'; -use lib $RealBin; -use lib "$RealBin/../SBO-Lib/lib"; -use Test::Execute; - -if (defined $ENV{TRAVIS} and $ENV{TRAVIS} eq 'true') { - plan tests => 26; -} else { - plan skip_all => 'Only run these tests under Travis CI (TRAVIS=true)'; -} -$ENV{TEST_ONLINE} //= 0; - -$path = "$RealBin/../"; - -# 1-3: Test SLACKWARE_VERSION -script (qw/ sboconfig -V 14.1 /, { expected => "Setting SLACKWARE_VERSION to 14.1...\n" }); -SKIP: { - skip 'Not doing online tests without TEST_ONLINE=1', 2 if $ENV{TEST_ONLINE} ne '1'; - - script (qw/ sbosnap fetch /, { expected => qr/\APulling SlackBuilds tree\.\.\.\n/ }); - script (qw/ sbofind sbotools /, { expected => "SBo: sbotools\nPath: /usr/sbo/repo/system/sbotools\n\n" }); -} - -# 4-10: Test alternative REPO -is (system(qw!rm -rf /usr/sbo!), 0, 'Removing /usr/sbo works'); -ok (! -e "/usr/sbo/repo/SLACKBUILDS.TXT", "SLACKBUILDS.TXT doesn't exist"); -script (qw! sboconfig -r https://github.com/Ponce/slackbuilds.git !, { expected => "Setting REPO to https://github.com/Ponce/slackbuilds.git...\n", name => 'Alternative REPO' }); -SKIP: { - skip 'Not doing online tests without TEST_ONLINE=1', 4 if $ENV{TEST_ONLINE} ne '1'; - - script (qw/ sbosnap fetch /, { expected => qr!Pulling SlackBuilds tree.*Cloning into '/usr/sbo/repo'!s }); - ok (-e "/usr/sbo/repo/SLACKBUILDS.TXT", "SLACKBUILDS.TXT exists (REPO)"); - ok (! -e "/usr/sbo/repo/SLACKBUILDS.TXT.gz", "SLACKBUILDS.TXT.gz doesn't exist (REPO)"); - script (qw/ sbofind sbotools /, { expected => "SBo: sbotools\nPath: /usr/sbo/repo/system/sbotools\n\n" }); -} - -# 11-17: Test local overrides -script (qw/ sboconfig -o /, "$RealBin/LO", { expected => "Setting LOCAL_OVERRIDES to $RealBin/LO...\n", name => 'LOCAL_OVERRIDES' }); -my $skip = 0; -SKIP: { - if ($ENV{TEST_ONLINE} ne '1') { $skip = !(system(qw! mkdir -p /usr/sbo/repo !) == 0 and system(qw! touch /usr/sbo/repo/SLACKBUILDS.TXT !) == 0) } - skip "Online testing disabled (TEST_ONLINE!=1) and could not create dummy SLACKBUILDS.TXT", 9 if $skip; - - script (qw/ sbofind nonexistentslackbuild /, { expected => <<"LOCAL" }); -Local: nonexistentslackbuild5 -Path: /home/travis/build/pink-mist/sbotools/t/LO/nonexistentslackbuild5 - -Local: nonexistentslackbuild4 -Path: /home/travis/build/pink-mist/sbotools/t/LO/nonexistentslackbuild4 - -Local: nonexistentslackbuild2 -Path: $RealBin/LO/nonexistentslackbuild2 - -Local: nonexistentslackbuild -Path: $RealBin/LO/nonexistentslackbuild - -LOCAL - script (qw/ sboinstall -r nonexistentslackbuild /, - { expected => qr/nonexistentslackbuild added to install queue[.].*perf[.]dummy' saved.*Cleaning for nonexistentslackbuild-1[.]0/s }); - script (qw/ sboremove --nointeractive nonexistentslackbuild /, { expected => qr/Removing 1 package\(s\).*nonexistentslackbuild.*All operations have completed/s }); - is (system(qw!/sbin/installpkg nonexistentslackbuild-0.9-noarch-1_SBo.tgz!), 0, 'Old version fake installed'); - script (qw/ sbocheck /, { expected => qr/Updating SlackBuilds tree.*Checking for updated SlackBuilds.*nonexistentslackbuild 0[.]9.*needs updating/s }); - script (qw/ sboupgrade -r nonexistentslackbuild /, { expected => qr/nonexistentslackbuild added to upgrade queue.*Upgrade queue: nonexistentslackbuild/s }); - -# 18: Test missing dep - script (qw/ sboinstall nonexistentslackbuild2 /, { input => 'y', exit => 1, expected => "Unable to locate nonexistentslackbuild3 in the SlackBuilds.org tree.\n" }); -} - -# 19-23: Test sboupgrade --all -SKIP: { - my @files = glob("/var/log/packages/nonexistentslackbuild-*"); - skip 'nonexistentslackbuild not installed', 1 if @files == 0; - - is (system(qw!/sbin/removepkg nonexistentslackbuild!), 0, 'removepkging nonexistentslackbuild works'); -} -SKIP: { - skip "Online testing disabled (TEST_ONLINE!=1) and could not create dummy SLACKBUILDS.txt", 4 if $skip; - - my @files = glob("/var/log/packages/nonexistentslackbuild-*"); - skip 'Cannot test if nonexistentslackbuild is already installed', 4 if @files; - - is (system(qw!/sbin/installpkg nonexistentslackbuild-0.9-noarch-1_SBo.tgz!), 0, 'installpkg old version works'); - script (qw/ sboupgrade -r --all /, { expected => qr/Checking for updated SlackBuilds.*nonexistentslackbuild added to upgrade queue.*Cleaning for nonexistentslackbuild/s }); - ok (-e "/var/log/packages/nonexistentslackbuild-1.0-noarch-1_SBo", 'updated package is installed'); - ok (! -e "/var/log/packages/nonexistentslackbuild-0.9-noarch-1_SBo", 'old package is removed'); -} - -if (not glob("/var/log/packages/nonexistentslackbuild-*")) { - script (qw/ sboinstall -r nonexistentslackbuild /, { test => 0 }); -} -if (not glob("/var/log/packages/nonexistentslackbuild4-*")) { - script (qw/ sboinstall nonexistentslackbuild4 /, { input => "y\ny\ny", test => 0 }); -} -# 24-25: Test sboupgrade -f -script (qw/ sboupgrade -f nonexistentslackbuild /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild\?.*Upgrade queue: nonexistentslackbuild\n/s }); -script (qw/ sboupgrade -f nonexistentslackbuild4 /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild4\?.*Upgrade queue: nonexistentslackbuild4\n/s }); - -# 26: Test sboupgrade -f -z -script (qw/ sboupgrade -f -z nonexistentslackbuild4 /, { - input => "y\ny\ny", - expected => qr/nonexistentslackbuild5 added to upgrade queue.*nonexistentslackbuild4 added to upgrade queue.*Upgrade queue: nonexistentslackbuild5 nonexistentslackbuild4\n/s -}); - -# Cleanup -capture_merged { - system(qw!/sbin/removepkg nonexistentslackbuild!); - system(qw!/sbin/removepkg nonexistentslackbuild4!); - system(qw!/sbin/removepkg nonexistentslackbuild5!); - unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; - unlink "$RealBin/LO/nonexistentslackbuild4/perf.dummy"; - unlink "$RealBin/LO/nonexistentslackbuild5/perf.dummy"; -}; diff --git a/t/upgrade.t b/t/upgrade.t deleted file mode 100755 index 8417cf0..0000000 --- a/t/upgrade.t +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env perl - -use 5.16.0; -use strict; -use warnings FATAL => 'all'; -use Test::More; -use Capture::Tiny qw/ capture_merged /; -use FindBin '$RealBin'; -use lib $RealBin; -use lib "$RealBin/../SBO-Lib/lib"; -use Test::Execute; - -if ($ENV{TEST_INSTALL}) { - plan tests => 13; -} else { - plan skip_all => 'Only run these tests if TEST_INSTALL=1'; -} -$ENV{TEST_ONLINE} //= 0; - -$path = "$RealBin/../"; - -sub cleanup { - capture_merged { - system(qw!/sbin/removepkg nonexistentslackbuild!); - system(qw!/sbin/removepkg nonexistentslackbuild4!); - system(qw!/sbin/removepkg nonexistentslackbuild5!); - unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; - unlink "$RealBin/LO/nonexistentslackbuild4/perf.dummy"; - unlink "$RealBin/LO/nonexistentslackbuild5/perf.dummy"; - unlink "$RealBin/LO2/nonexistentslackbuild/perf.dummy"; - unlink "$RealBin/LO2/nonexistentslackbuild4/perf.dummy"; - unlink "$RealBin/LO2/nonexistentslackbuild5/perf.dummy"; - unlink "$RealBin/LO3/nonexistentslackbuild/perf.dummy"; - unlink "$RealBin/LO3/nonexistentslackbuild4/perf.dummy"; - unlink "$RealBin/LO3/nonexistentslackbuild5/perf.dummy"; - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-0.9!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-0.9!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-0.9!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.0!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.0!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-1.0!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.1!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.1!); - system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-1.1!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild4!); - system(qw!rm -rf /tmp/package-nonexistentslackbuild5!); - }; -} - -sub make_slackbuilds_txt { - state $made = 0; - my $fname = "/usr/sbo/repo/SLACKBUILDS.TXT"; - if ($_[0]) { - if ($made) { return system(qw!rm -rf!, $fname); } - } else { - if (not -e $fname) { $made = 1; system('mkdir', '-p', '/usr/sbo/repo'); system('touch', $fname); } - } -} - -sub set_lo { - state $set = 0; - state $lo; - if ($_[0]) { - if ($set) { script (qw/ sboconfig -o /, $lo, { test => 0 }); } - } else { - ($lo) = script (qw/ sboconfig -l /, { expected => qr/LOCAL_OVERRIDES=(.*)/, test => 0 }); - $lo //= 'FALSE'; - note "Saving original value of LOCAL_OVERRIDES: $lo"; - $set = 1; - script (qw/ sboconfig -o /, "$RealBin/LO", { test => 0 }); - } -} - -cleanup(); -make_slackbuilds_txt(); -set_lo(); - -sub install { - cleanup(); - my $lo = shift; - my @pkgs = @_; - - script (qw/ sboconfig -o /, "$RealBin/LO", { test => 0 }); - for my $pkg (@pkgs) { - script (qw/ sboinstall -r /, $pkg, { test => 0 }); - } - script (qw/ sboconfig -o /, "$RealBin/$lo", { test => 0 }); -} - -# 1-2: sboupgrade nonexistentslackbuild when it doesn't need to be upgraded -install( 'LO', 'nonexistentslackbuild' ); -script (qw/ sboupgrade nonexistentslackbuild /, { expected => '' }); -script (qw/ sboupgrade -f nonexistentslackbuild /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild\b.*Upgrade queue: nonexistentslackbuild\n/s }); - -# 3-7: sboupgrade nonexistentslackbuild4 and 5 when they don't need to be upgraded -install( 'LO', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); -script (qw/ sboupgrade nonexistentslackbuild4 /, { expected => '' }); -script (qw/ sboupgrade nonexistentslackbuild5 /, { expected => '' }); -script (qw/ sboupgrade -f nonexistentslackbuild4 /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild4\b.*Upgrade queue: nonexistentslackbuild4\n/s }); -script (qw/ sboupgrade -f nonexistentslackbuild5 /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Upgrade queue: nonexistentslackbuild5\n/s }); -script (qw/ sboupgrade -f -z nonexistentslackbuild4 /, { input => "y\ny\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Proceed with nonexistentslackbuild4\b.*Upgrade queue: nonexistentslackbuild5 nonexistentslackbuild4\n/s }); - -# 8: sboupgrade nonexistentslackbuild when it needs to be upgraded -install( 'LO2', 'nonexistentslackbuild' ); -script (qw/ sboupgrade nonexistentslackbuild /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild\b.*Upgrade queue: nonexistentslackbuild\n/s }); - -# 9: sboupgrade nonexistentslackbuild4 and 5 when they need to be upgraded -install( 'LO2', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); -script (qw/ sboupgrade nonexistentslackbuild4 /, { input => "y\ny\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Proceed with nonexistentslackbuild4\b.*Upgrade queue: nonexistentslackbuild5 nonexistentslackbuild4\n/s }); - -# 10-11: sboupgrade nonexistentslackbuild4 and 5 when only 5 needs an update -install( 'LO3', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); -script (qw/ sboupgrade nonexistentslackbuild4 /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Upgrade queue: nonexistentslackbuild5\n/s }); -install( 'LO3', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); -script (qw/ sboupgrade -f nonexistentslackbuild4 /, { input => "y\ny\ny", expected => qr/Proceed with nonexistentslackbuild5\b.*Proceed with nonexistentslackbuild4\b.*Upgrade queue: nonexistentslackbuild5 nonexistentslackbuild4\n/s }); - -# 12-13: sboupgrade --all -install( 'LO2', 'nonexistentslackbuild' ); -my @sbos = glob("/var/log/packages/*_SBo"); -script (qw/ sboupgrade --all /, { input => ("n\n" x (@sbos+1)), expected => qr/Proceed with nonexistentslackbuild\b/ }); -install( 'LO2', 'nonexistentslackbuild', 'nonexistentslackbuild5', 'nonexistentslackbuild4' ); -script(qw/ sboupgrade --all /, { input => ("n\n" x (@sbos+3)), expected => qr/Proceed with nonexistentslackbuild\b.*Proceed with nonexistentslackbuild5\b.*Proceed with nonexistentslackbuild4\b/s }); - -# Cleanup -END { - set_lo('delete'); - make_slackbuilds_txt('delete'); - cleanup(); -} -- cgit v1.2.3