From 4e169d71a6bffb28077389520feca7430d0d9556 Mon Sep 17 00:00:00 2001 From: Andreas Guldstrand Date: Mon, 23 May 2016 19:02:56 +0200 Subject: t/ reordered test files --- t/01-unit.t | 268 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ t/02-travis.t | 126 -------------------------- t/02-unit-args.t | 60 +++++++++++++ t/03-travis.t | 126 ++++++++++++++++++++++++++ t/19-unit.t | 268 ------------------------------------------------------- t/20-unit-args.t | 60 ------------- 6 files changed, 454 insertions(+), 454 deletions(-) create mode 100755 t/01-unit.t delete mode 100755 t/02-travis.t create mode 100755 t/02-unit-args.t create mode 100755 t/03-travis.t delete mode 100755 t/19-unit.t delete mode 100755 t/20-unit-args.t diff --git a/t/01-unit.t b/t/01-unit.t new file mode 100755 index 0000000..71697f5 --- /dev/null +++ b/t/01-unit.t @@ -0,0 +1,268 @@ +#!/usr/bin/env perl + +# This should probably replace 01-test.t once it's thorough enough + +use strict; +use warnings; +use Test::More; +use Test::Exit; +use FindBin '$RealBin'; +use lib "$RealBin/../SBO-Lib/lib"; +use SBO::Lib qw/ script_error usage_error open_fh %config indent get_installed_packages get_sbo_location get_sbo_locations get_local_outdated_versions get_readme_contents user_prompt /; +use Capture::Tiny qw/ capture_merged /; +use File::Temp 'tempdir'; + +plan tests => 47; + +# 1-2: test script_error(); +{ + my $exit; + my $out = capture_merged { $exit = exit_code { script_error(); }; }; + + is ($exit, 2, 'script_error() exited with 2'); + is ($out, "A fatal script error has occurred. Exiting.\n", 'script_error() gave correct output'); +} + +# 3-4: test usage_error(); +{ + my $exit; + my $out = capture_merged { $exit = exit_code { usage_error('whatever'); }; }; + + is ($exit, 1, 'usage_error() exited with 1'); + is ($out, "whatever\n", 'usage_error() gave correct output'); +} + +# 5-8: test open_fh(); +{ + my $exit; + my $out = capture_merged { $exit = exit_code { open_fh($0); }; }; + + is ($exit, 2, 'open_fh() exited with 2'); + is ($out, "A fatal script error has occurred:\nopen_fh requires two arguments\nExiting.\n", 'open_fh() gave correct output'); + + SKIP: { + skip 'Tests invalid if ./foo/bar exists.', 2 if -e "$RealBin/foo/bar"; + my ($warn, $status) = open_fh("$RealBin/foo/bar/baz", '>'); + + like ($warn, qr!Unable to open .*/foo/bar/baz\.\n!, 'open_fh() gave correct return value (1)'); + is ($status, 6, 'open_fh() gave correct return value (2)'); + } +} + +# 9-13: test get_slack_version(); +SKIP: { + skip 'Tests invalid if /etc/slackware-version exists.', 5 if -e '/etc/slackware-version'; + + local $config{SLACKWARE_VERSION} = 'FALSE'; + + my $exit; + my $out = capture_merged { $exit = exit_code{ SBO::Lib::get_slack_version(); }; }; + + is ($exit, 2, 'get_slack_version() exited with 2'); + is ($out, "A fatal script error has occurred:\nopen_fh, /etc/slackware-version is not a file\nExiting.\n", 'get_slack_version() gave correct output'); + + my ($fh) = open_fh('/etc/slackware-version', '>'); + print $fh "Slackware 0.0\n"; + close $fh; + + undef $exit; + $out = capture_merged { $exit = exit_code{ SBO::Lib::get_slack_version(); }; }; + + is ($exit, 1, 'get_slack_version() exited with 1'); + is ($out, "Unsupported Slackware version: 0.0\n\n", 'get_slack_version() gave correct output (Unsupported)'); + + ($fh) = open_fh('/etc/slackware-version', '>'); + print $fh "Slackware 14.1\n"; + close $fh; + + is (SBO::Lib::get_slack_version(), '14.1', 'get_slack_version() returned the correct version'); + + unlink '/etc/slackware-version'; +} + +# 14-15: test indent(); +is(indent(0, 'foo'), 'foo', 'indent(0,...) returns correctly'); +is(indent(1, "foo\n\nbar"), " foo\n\n bar", 'indent(1,...) returns correctly'); + +# 16-18: test check_repo() and migrate_repo(); +SKIP: { + skip 'Test invalid if no SLACKBUILDS.TXT exists.', 3 if ! -e '/usr/sbo/repo/SLACKBUILDS.TXT'; + + system(qw"cp /usr/sbo/repo/SLACKBUILDS.TXT /usr/sbo"); + system(qw"rm -rf", "$RealBin/repo.backup"); + system(qw"mv /usr/sbo/repo", "$RealBin/repo.backup"); + + is (SBO::Lib::check_repo(), 1, 'check_repo() returned 1 when /usr/sbo/repo was empty'); + + SBO::Lib::migrate_repo(); + ok (-e '/usr/sbo/repo/SLACKBUILDS.TXT', '/usr/sbo/repo/SLACKBUILDS.TXT moved back by migrate_repo()'); + + system("mv /usr/sbo/repo/* /usr/sbo"); + system(qw! rmdir /usr/sbo/repo !); + + SBO::Lib::migrate_repo(); + ok (-d '/usr/sbo/repo', '/usr/sbo/repo correctly recreated by migrate_repo()'); + + system(qw"rm /usr/sbo/repo/SLACKBUILDS.TXT"); + system(qw! rmdir /usr/sbo/repo !); + system("mv", "$RealBin/repo.backup", "/usr/sbo/repo"); +} + +# 19-23: test check_repo(); +SKIP: { + skip 'Test invalid if no SLACKBUILDS.TXT exists.', 5 if ! -e '/usr/sbo/repo/SLACKBUILDS.TXT'; + + my $exit; + my $out = capture_merged { $exit = exit_code { SBO::Lib::check_repo(); }; }; + + is ($exit, 1, 'check_repo() exited with 1'); + is ($out, "/usr/sbo/repo exists and is not empty. Exiting.\n\n", 'check_repo() gave correct output'); + + system(qq'rm -rf "$RealBin/repo.backup"'); + system(qq'mv /usr/sbo/repo "$RealBin/repo.backup"'); + system(qq'mkdir /usr/sbo/repo'); + + undef $exit; + my $res; + $out = capture_merged { $exit = exit_code { $res = SBO::Lib::check_repo(); }; }; + + is ($exit, undef, "check_repo() didn't exit"); + is ($out, '', "check_repo() didn't print anything"); + is ($res, 1, "check_repo() returned correctly"); + + system(qq'rmdir /usr/sbo/repo'); + system(qq'mv "$RealBin/repo.backup" /usr/sbo/repo'); +} + +# 24-25: test rsync_sbo_tree(); +SKIP: { + skip 'Test invalid if /foo-bar exists.', 2 if -e '/foo-bar'; + + my $res; + my $out = capture_merged { $res = SBO::Lib::rsync_sbo_tree('/foo-bar'); }; + + ok (!$res, q"rsync_sbo_tree('/foo-bar') returned false"); + like ($out, qr!rsync: change_dir "/foo-bar" failed!, q"rsync_sbo_tree('/foo-bar') gave correct output"); +} + +# 26-32: test git_sbo_tree(), check_git_remote(), generate_slackbuilds_txt(), and pull_sbo_tree();; +{ + system(qw! mv /usr/sbo/repo /usr/sbo/backup !) if -d '/usr/sbo/repo'; + system(qw! mkdir -p /usr/sbo/repo/.git !); + + my $res; + capture_merged { $res = SBO::Lib::git_sbo_tree(''); }; + is ($res, 0, q!git_sbo_tree('') returned 0!); + + system(qw! rm -r /usr/sbo/repo !) if -d '/usr/sbo/repo'; + system(qw! mkdir -p /usr/sbo/repo/.git !); + my ($fh) = open_fh('/usr/sbo/repo/.git/config', '>'); + print $fh qq'[remote "origin"]\n'; print $fh "foo=bar\n"; print $fh "url=\n"; + close $fh; + + undef $res; + capture_merged { $res = SBO::Lib::git_sbo_tree(''); }; + is ($res, 0, q!git_sbo_tree('') with .git/config returned 0 !); + undef $res; + capture_merged { $res = SBO::Lib::git_sbo_tree('foo'); }; + is ($res, 0, q!git_sbo_tree('foo') returned 0!); + + system(qw! rm -r /usr/sbo/repo !) if -d '/usr/sbo/repo'; + system(qw! mkdir -p /usr/sbo/repo/.git !); + ($fh) = open_fh('/usr/sbo/repo/.git/config', '>'); + print $fh qq'[remote "origin"]\n'; print $fh "[]"; + close $fh; + + undef $res; + capture_merged { $res = SBO::Lib::check_git_remote('/usr/sbo/repo', 'foo'); }; + is ($res, 0, 'check_git_remote() returned 0'); + + system(qw! rm -r /usr/sbo/repo !) if -d '/usr/sbo/repo'; + + is (SBO::Lib::generate_slackbuilds_txt(), 0, 'generate_slackbuilds_txt() returned 0'); + + system(qw! mkdir -p /usr/sbo/repo/foo/bar !); + + is (SBO::Lib::generate_slackbuilds_txt(), 1, 'generate_slackbuilds_txt() returned 1'); + + system(qw! rm -r /usr/sbo/repo !) if -d '/usr/sbo/repo'; + + local $config{REPO} = ''; + capture_merged { SBO::Lib::pull_sbo_tree(); }; + ok (!-e '/usr/sbo/repo/SLACKBUILDS.TXT', 'SLACKBUILDS.TXT was not generated by pull_sbo_tree()'); + + system(qw! rm -r /usr/sbo/repo !) if -d '/usr/sbo/repo'; + system(qw! mv /usr/sbo/backup /usr/sbo/repo !) if -d '/usr/sbo/backup'; +} + +# 33: test get_installed_packages(); +{ + system(qw!mv /var/log/packages /var/log/packages.backup!); + system(qw!mkdir -p /var/log/packages!); + system(qw!touch /var/log/packages/sbotoolstestingfile!); + is (@{ get_installed_packages('SBO') }, 0, 'get_installed_packages() returned an empty arrayref'); + system(qw!rm -r /var/log/packages!); + system(qw!mv /var/log/packages.backup /var/log/packages!); +} + +# 34-36: test get_sbo_location() and get_sbo_locations(); +{ + my $exit; + my $out = capture_merged { $exit = exit_code { get_sbo_location([]); }; }; + + is ($exit, 2, 'get_sbo_location([]) exited with 2'); + is ($out, "A fatal script error has occurred:\nget_sbo_location requires an argument.\nExiting.\n", 'get_sbo_location([]) gave correct output'); + + local $config{LOCAL_OVERRIDES} = 'FALSE'; + my %res = get_sbo_locations('nonexistentslackbuild'); + + is (%res+0, 0, q"get_sbo_locations('nonexistentslackbuild') returned an empty hash"); +} + +# 37: test get_local_outdated_versions(); +{ + local $config{LOCAL_OVERRIDES} = 'FALSE'; + is(scalar get_local_outdated_versions(), 0, 'get_local_outdated_versions() returned an empty list'); +} + +# 38: test get_filename_from_link(); +{ + is (SBO::Lib::get_filename_from_link('/'), undef, "get_filename_from_link() returned undef"); +} + +# 39-42: test revert_slackbuild(); +{ + my $tmp = tempdir(CLEANUP => 1); + is (SBO::Lib::revert_slackbuild("$tmp/foo"), 1, "revert_slackbuild() returned 1"); + + system('touch', "$tmp/foo.orig"); + is (SBO::Lib::revert_slackbuild("$tmp/foo"), 1, "revert_slackbuild() returned 1"); + ok (-f "$tmp/foo", 'foo.orig renamed to foo'); + ok (!-f "$tmp/foo.orig", 'foo.orig is no more'); +} + +# 43: test get_src_dir(); +SKIP: { + skip 'Test invalid if /foo-bar exists.', 1 if -e '/foo-bar'; + my $scalar = ''; + open(my $fh, '<', \$scalar) or skip "Could not open needed filehandle", 1; + + local $SBO::Lib::tmpd = "/foo-bar"; + is (scalar @{ SBO::Lib::get_src_dir($fh) }, 0, "get_src_dir() returned an empty array ref"); +} + +# 44-45: test get_readme_contents(); +{ + my @ret = get_readme_contents(undef); + is ($ret[0], undef, "get_readme_contents() returned undef"); + is ($ret[1], 6, "get_readme_contents() returned 6"); +} + +# 46-47: test user_prompt(); +{ + my $exit; + my $out = capture_merged { $exit = exit_code { user_prompt('foo', undef); }; }; + + is ($exit, 1, 'user_prompt() exited with 1'); + is ($out, "Unable to locate foo in the SlackBuilds.org tree.\n", 'user_prompt() gave correct output'); +} diff --git a/t/02-travis.t b/t/02-travis.t deleted file mode 100755 index ce0785f..0000000 --- a/t/02-travis.t +++ /dev/null @@ -1,126 +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::Sbotools qw/ sboconfig sbosnap sbofind sboinstall sboremove sbocheck sboupgrade /; - -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; - -# 1-3: Test SLACKWARE_VERSION -sboconfig qw/ -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'; - - sbosnap 'fetch', { expected => qr/\APulling SlackBuilds tree\.\.\.\n/ }; - 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"); -sboconfig qw! -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'; - - 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)"); - sbofind 'sbotools', { expected => "SBo: sbotools\nPath: /usr/sbo/repo/system/sbotools\n\n" }; -} - -# 11-17: Test local overrides -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; - - sbofind 'nonexistentslackbuild', { expected => sub { -m!\QLocal: nonexistentslackbuild6 -Path: $RealBin/LO/nonexistentslackbuild6! - and -m!\QLocal: nonexistentslackbuild5 -Path: $RealBin/LO/nonexistentslackbuild5! - and -m!\QLocal: nonexistentslackbuild4 -Path: $RealBin/LO/nonexistentslackbuild4! - and -m!\QLocal: nonexistentslackbuild2 -Path: $RealBin/LO/nonexistentslackbuild2! - and -m!\QLocal: nonexistentslackbuild7 -Path: $RealBin/LO/nonexistentslackbuild7! - and -m!\QLocal: nonexistentslackbuild -Path: $RealBin/LO/nonexistentslackbuild! - and -m!\QLocal: nonexistentslackbuild8 -Path: $RealBin/LO/nonexistentslackbuild8! - } }; - - sboinstall qw/ -r nonexistentslackbuild /, - { expected => qr/nonexistentslackbuild added to install queue[.].*perf[.]dummy' saved.*Cleaning for nonexistentslackbuild-1[.]0/s }; - sboremove qw/ --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'); - sbocheck { expected => qr/Updating SlackBuilds tree.*Checking for updated SlackBuilds.*nonexistentslackbuild 0[.]9.*needs updating/s }; - sboupgrade qw/ -r nonexistentslackbuild /, { expected => qr/nonexistentslackbuild added to upgrade queue.*Upgrade queue: nonexistentslackbuild/s }; - -# 18: Test missing dep - 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'); - sboupgrade qw/ -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-*")) { - sboinstall qw/ -r nonexistentslackbuild /, { test => 0 }; -} -if (not glob("/var/log/packages/nonexistentslackbuild4-*")) { - sboinstall 'nonexistentslackbuild4', { input => "y\ny\ny", test => 0 }; -} -# 24-25: Test sboupgrade -f -sboupgrade qw/ -f nonexistentslackbuild /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild\?.*Upgrade queue: nonexistentslackbuild\n/s }; -sboupgrade qw/ -f nonexistentslackbuild4 /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild4\?.*Upgrade queue: nonexistentslackbuild4\n/s }; - -# 26: Test sboupgrade -f -z -sboupgrade qw/ -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/02-unit-args.t b/t/02-unit-args.t new file mode 100755 index 0000000..bb70939 --- /dev/null +++ b/t/02-unit-args.t @@ -0,0 +1,60 @@ +#!/usr/bin/env perl + +# This should probably replace 01-test.t once it's thorough enough + +use strict; +use warnings; +use Test::More; +use Test::Exit; +use FindBin '$RealBin'; +use lib "$RealBin/../SBO-Lib/lib"; +use SBO::Lib; +use Capture::Tiny qw/ capture_merged /; + +plan tests => 60; + +sub test_args { + my $sub = shift; + my @args = @_; + subtest "Testing $sub exit status when called with too few arguments", sub { + plan tests => 2; + + my $exit; + my $out = capture_merged { $exit = exit_code { SBO::Lib->can("SBO::Lib::$sub")->(@args); }; }; + + is ($exit, 2, "$sub(@args) exited with 2"); + like ($out, qr!\QA fatal script error has occurred:\E\n\Q$sub\E.*\nExiting\.\n!, "$sub(@args) gave correct output"); + } +} + +test_args $_ for qw/ + rsync_sbo_tree git_sbo_tree check_git_remote get_installed_packages get_inst_names + get_sbo_location get_sbo_locations is_local get_orig_location get_orig_version + get_sbo_from_loc get_from_info get_sbo_version get_download_info get_sbo_downloads + get_filename_from_link verify_distfile get_distfile get_symlink_from_filename + check_x32 rewrite_slackbuild revert_slackbuild check_distfiles create_symlinks + get_src_dir get_tmp_extfn perform_sbo do_convertpkg do_slackbuild make_clean + make_distclean do_upgradepkg get_build_queue merge_queues get_readme_contents + get_user_group ask_user_group get_opts ask_opts user_prompt +/; + +test_args 'get_from_info', LOCATION => 1; +test_args 'get_from_info', GET => 1; +test_args 'get_sbo_downloads', LOCATION => $0; +test_args 'compute_md5sum', $RealBin; +test_args 'get_symlink_from_filename', $RealBin, 0; +test_args 'perform_sbo', LOCATION => 1; +test_args 'perform_sbo', ARCH => 1; +test_args 'make_clean', SBO => 1; +test_args 'make_clean', SRC => 1; +test_args 'make_clean', VERSION => 1; +test_args 'make_clean', SBO => 1, SRC => 1; +test_args 'make_clean', SBO => 1, VERSION => 1; +test_args 'make_clean', SRC => 1, VERSION => 1; +test_args 'make_distclean', SRC => 1; +test_args 'make_distclean', VERSION => 1; +test_args 'make_distclean', LOCATION => 1; +test_args 'make_distclean', SRC => 1, VERSION => 1; +test_args 'make_distclean', SRC => 1, LOCATION => 1; +test_args 'make_distclean', VERSION => 1, LOCATION => 1; +test_args 'process_sbos', TODO => []; diff --git a/t/03-travis.t b/t/03-travis.t new file mode 100755 index 0000000..ce0785f --- /dev/null +++ b/t/03-travis.t @@ -0,0 +1,126 @@ +#!/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::Sbotools qw/ sboconfig sbosnap sbofind sboinstall sboremove sbocheck sboupgrade /; + +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; + +# 1-3: Test SLACKWARE_VERSION +sboconfig qw/ -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'; + + sbosnap 'fetch', { expected => qr/\APulling SlackBuilds tree\.\.\.\n/ }; + 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"); +sboconfig qw! -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'; + + 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)"); + sbofind 'sbotools', { expected => "SBo: sbotools\nPath: /usr/sbo/repo/system/sbotools\n\n" }; +} + +# 11-17: Test local overrides +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; + + sbofind 'nonexistentslackbuild', { expected => sub { +m!\QLocal: nonexistentslackbuild6 +Path: $RealBin/LO/nonexistentslackbuild6! + and +m!\QLocal: nonexistentslackbuild5 +Path: $RealBin/LO/nonexistentslackbuild5! + and +m!\QLocal: nonexistentslackbuild4 +Path: $RealBin/LO/nonexistentslackbuild4! + and +m!\QLocal: nonexistentslackbuild2 +Path: $RealBin/LO/nonexistentslackbuild2! + and +m!\QLocal: nonexistentslackbuild7 +Path: $RealBin/LO/nonexistentslackbuild7! + and +m!\QLocal: nonexistentslackbuild +Path: $RealBin/LO/nonexistentslackbuild! + and +m!\QLocal: nonexistentslackbuild8 +Path: $RealBin/LO/nonexistentslackbuild8! + } }; + + sboinstall qw/ -r nonexistentslackbuild /, + { expected => qr/nonexistentslackbuild added to install queue[.].*perf[.]dummy' saved.*Cleaning for nonexistentslackbuild-1[.]0/s }; + sboremove qw/ --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'); + sbocheck { expected => qr/Updating SlackBuilds tree.*Checking for updated SlackBuilds.*nonexistentslackbuild 0[.]9.*needs updating/s }; + sboupgrade qw/ -r nonexistentslackbuild /, { expected => qr/nonexistentslackbuild added to upgrade queue.*Upgrade queue: nonexistentslackbuild/s }; + +# 18: Test missing dep + 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'); + sboupgrade qw/ -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-*")) { + sboinstall qw/ -r nonexistentslackbuild /, { test => 0 }; +} +if (not glob("/var/log/packages/nonexistentslackbuild4-*")) { + sboinstall 'nonexistentslackbuild4', { input => "y\ny\ny", test => 0 }; +} +# 24-25: Test sboupgrade -f +sboupgrade qw/ -f nonexistentslackbuild /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild\?.*Upgrade queue: nonexistentslackbuild\n/s }; +sboupgrade qw/ -f nonexistentslackbuild4 /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild4\?.*Upgrade queue: nonexistentslackbuild4\n/s }; + +# 26: Test sboupgrade -f -z +sboupgrade qw/ -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/19-unit.t b/t/19-unit.t deleted file mode 100755 index 71697f5..0000000 --- a/t/19-unit.t +++ /dev/null @@ -1,268 +0,0 @@ -#!/usr/bin/env perl - -# This should probably replace 01-test.t once it's thorough enough - -use strict; -use warnings; -use Test::More; -use Test::Exit; -use FindBin '$RealBin'; -use lib "$RealBin/../SBO-Lib/lib"; -use SBO::Lib qw/ script_error usage_error open_fh %config indent get_installed_packages get_sbo_location get_sbo_locations get_local_outdated_versions get_readme_contents user_prompt /; -use Capture::Tiny qw/ capture_merged /; -use File::Temp 'tempdir'; - -plan tests => 47; - -# 1-2: test script_error(); -{ - my $exit; - my $out = capture_merged { $exit = exit_code { script_error(); }; }; - - is ($exit, 2, 'script_error() exited with 2'); - is ($out, "A fatal script error has occurred. Exiting.\n", 'script_error() gave correct output'); -} - -# 3-4: test usage_error(); -{ - my $exit; - my $out = capture_merged { $exit = exit_code { usage_error('whatever'); }; }; - - is ($exit, 1, 'usage_error() exited with 1'); - is ($out, "whatever\n", 'usage_error() gave correct output'); -} - -# 5-8: test open_fh(); -{ - my $exit; - my $out = capture_merged { $exit = exit_code { open_fh($0); }; }; - - is ($exit, 2, 'open_fh() exited with 2'); - is ($out, "A fatal script error has occurred:\nopen_fh requires two arguments\nExiting.\n", 'open_fh() gave correct output'); - - SKIP: { - skip 'Tests invalid if ./foo/bar exists.', 2 if -e "$RealBin/foo/bar"; - my ($warn, $status) = open_fh("$RealBin/foo/bar/baz", '>'); - - like ($warn, qr!Unable to open .*/foo/bar/baz\.\n!, 'open_fh() gave correct return value (1)'); - is ($status, 6, 'open_fh() gave correct return value (2)'); - } -} - -# 9-13: test get_slack_version(); -SKIP: { - skip 'Tests invalid if /etc/slackware-version exists.', 5 if -e '/etc/slackware-version'; - - local $config{SLACKWARE_VERSION} = 'FALSE'; - - my $exit; - my $out = capture_merged { $exit = exit_code{ SBO::Lib::get_slack_version(); }; }; - - is ($exit, 2, 'get_slack_version() exited with 2'); - is ($out, "A fatal script error has occurred:\nopen_fh, /etc/slackware-version is not a file\nExiting.\n", 'get_slack_version() gave correct output'); - - my ($fh) = open_fh('/etc/slackware-version', '>'); - print $fh "Slackware 0.0\n"; - close $fh; - - undef $exit; - $out = capture_merged { $exit = exit_code{ SBO::Lib::get_slack_version(); }; }; - - is ($exit, 1, 'get_slack_version() exited with 1'); - is ($out, "Unsupported Slackware version: 0.0\n\n", 'get_slack_version() gave correct output (Unsupported)'); - - ($fh) = open_fh('/etc/slackware-version', '>'); - print $fh "Slackware 14.1\n"; - close $fh; - - is (SBO::Lib::get_slack_version(), '14.1', 'get_slack_version() returned the correct version'); - - unlink '/etc/slackware-version'; -} - -# 14-15: test indent(); -is(indent(0, 'foo'), 'foo', 'indent(0,...) returns correctly'); -is(indent(1, "foo\n\nbar"), " foo\n\n bar", 'indent(1,...) returns correctly'); - -# 16-18: test check_repo() and migrate_repo(); -SKIP: { - skip 'Test invalid if no SLACKBUILDS.TXT exists.', 3 if ! -e '/usr/sbo/repo/SLACKBUILDS.TXT'; - - system(qw"cp /usr/sbo/repo/SLACKBUILDS.TXT /usr/sbo"); - system(qw"rm -rf", "$RealBin/repo.backup"); - system(qw"mv /usr/sbo/repo", "$RealBin/repo.backup"); - - is (SBO::Lib::check_repo(), 1, 'check_repo() returned 1 when /usr/sbo/repo was empty'); - - SBO::Lib::migrate_repo(); - ok (-e '/usr/sbo/repo/SLACKBUILDS.TXT', '/usr/sbo/repo/SLACKBUILDS.TXT moved back by migrate_repo()'); - - system("mv /usr/sbo/repo/* /usr/sbo"); - system(qw! rmdir /usr/sbo/repo !); - - SBO::Lib::migrate_repo(); - ok (-d '/usr/sbo/repo', '/usr/sbo/repo correctly recreated by migrate_repo()'); - - system(qw"rm /usr/sbo/repo/SLACKBUILDS.TXT"); - system(qw! rmdir /usr/sbo/repo !); - system("mv", "$RealBin/repo.backup", "/usr/sbo/repo"); -} - -# 19-23: test check_repo(); -SKIP: { - skip 'Test invalid if no SLACKBUILDS.TXT exists.', 5 if ! -e '/usr/sbo/repo/SLACKBUILDS.TXT'; - - my $exit; - my $out = capture_merged { $exit = exit_code { SBO::Lib::check_repo(); }; }; - - is ($exit, 1, 'check_repo() exited with 1'); - is ($out, "/usr/sbo/repo exists and is not empty. Exiting.\n\n", 'check_repo() gave correct output'); - - system(qq'rm -rf "$RealBin/repo.backup"'); - system(qq'mv /usr/sbo/repo "$RealBin/repo.backup"'); - system(qq'mkdir /usr/sbo/repo'); - - undef $exit; - my $res; - $out = capture_merged { $exit = exit_code { $res = SBO::Lib::check_repo(); }; }; - - is ($exit, undef, "check_repo() didn't exit"); - is ($out, '', "check_repo() didn't print anything"); - is ($res, 1, "check_repo() returned correctly"); - - system(qq'rmdir /usr/sbo/repo'); - system(qq'mv "$RealBin/repo.backup" /usr/sbo/repo'); -} - -# 24-25: test rsync_sbo_tree(); -SKIP: { - skip 'Test invalid if /foo-bar exists.', 2 if -e '/foo-bar'; - - my $res; - my $out = capture_merged { $res = SBO::Lib::rsync_sbo_tree('/foo-bar'); }; - - ok (!$res, q"rsync_sbo_tree('/foo-bar') returned false"); - like ($out, qr!rsync: change_dir "/foo-bar" failed!, q"rsync_sbo_tree('/foo-bar') gave correct output"); -} - -# 26-32: test git_sbo_tree(), check_git_remote(), generate_slackbuilds_txt(), and pull_sbo_tree();; -{ - system(qw! mv /usr/sbo/repo /usr/sbo/backup !) if -d '/usr/sbo/repo'; - system(qw! mkdir -p /usr/sbo/repo/.git !); - - my $res; - capture_merged { $res = SBO::Lib::git_sbo_tree(''); }; - is ($res, 0, q!git_sbo_tree('') returned 0!); - - system(qw! rm -r /usr/sbo/repo !) if -d '/usr/sbo/repo'; - system(qw! mkdir -p /usr/sbo/repo/.git !); - my ($fh) = open_fh('/usr/sbo/repo/.git/config', '>'); - print $fh qq'[remote "origin"]\n'; print $fh "foo=bar\n"; print $fh "url=\n"; - close $fh; - - undef $res; - capture_merged { $res = SBO::Lib::git_sbo_tree(''); }; - is ($res, 0, q!git_sbo_tree('') with .git/config returned 0 !); - undef $res; - capture_merged { $res = SBO::Lib::git_sbo_tree('foo'); }; - is ($res, 0, q!git_sbo_tree('foo') returned 0!); - - system(qw! rm -r /usr/sbo/repo !) if -d '/usr/sbo/repo'; - system(qw! mkdir -p /usr/sbo/repo/.git !); - ($fh) = open_fh('/usr/sbo/repo/.git/config', '>'); - print $fh qq'[remote "origin"]\n'; print $fh "[]"; - close $fh; - - undef $res; - capture_merged { $res = SBO::Lib::check_git_remote('/usr/sbo/repo', 'foo'); }; - is ($res, 0, 'check_git_remote() returned 0'); - - system(qw! rm -r /usr/sbo/repo !) if -d '/usr/sbo/repo'; - - is (SBO::Lib::generate_slackbuilds_txt(), 0, 'generate_slackbuilds_txt() returned 0'); - - system(qw! mkdir -p /usr/sbo/repo/foo/bar !); - - is (SBO::Lib::generate_slackbuilds_txt(), 1, 'generate_slackbuilds_txt() returned 1'); - - system(qw! rm -r /usr/sbo/repo !) if -d '/usr/sbo/repo'; - - local $config{REPO} = ''; - capture_merged { SBO::Lib::pull_sbo_tree(); }; - ok (!-e '/usr/sbo/repo/SLACKBUILDS.TXT', 'SLACKBUILDS.TXT was not generated by pull_sbo_tree()'); - - system(qw! rm -r /usr/sbo/repo !) if -d '/usr/sbo/repo'; - system(qw! mv /usr/sbo/backup /usr/sbo/repo !) if -d '/usr/sbo/backup'; -} - -# 33: test get_installed_packages(); -{ - system(qw!mv /var/log/packages /var/log/packages.backup!); - system(qw!mkdir -p /var/log/packages!); - system(qw!touch /var/log/packages/sbotoolstestingfile!); - is (@{ get_installed_packages('SBO') }, 0, 'get_installed_packages() returned an empty arrayref'); - system(qw!rm -r /var/log/packages!); - system(qw!mv /var/log/packages.backup /var/log/packages!); -} - -# 34-36: test get_sbo_location() and get_sbo_locations(); -{ - my $exit; - my $out = capture_merged { $exit = exit_code { get_sbo_location([]); }; }; - - is ($exit, 2, 'get_sbo_location([]) exited with 2'); - is ($out, "A fatal script error has occurred:\nget_sbo_location requires an argument.\nExiting.\n", 'get_sbo_location([]) gave correct output'); - - local $config{LOCAL_OVERRIDES} = 'FALSE'; - my %res = get_sbo_locations('nonexistentslackbuild'); - - is (%res+0, 0, q"get_sbo_locations('nonexistentslackbuild') returned an empty hash"); -} - -# 37: test get_local_outdated_versions(); -{ - local $config{LOCAL_OVERRIDES} = 'FALSE'; - is(scalar get_local_outdated_versions(), 0, 'get_local_outdated_versions() returned an empty list'); -} - -# 38: test get_filename_from_link(); -{ - is (SBO::Lib::get_filename_from_link('/'), undef, "get_filename_from_link() returned undef"); -} - -# 39-42: test revert_slackbuild(); -{ - my $tmp = tempdir(CLEANUP => 1); - is (SBO::Lib::revert_slackbuild("$tmp/foo"), 1, "revert_slackbuild() returned 1"); - - system('touch', "$tmp/foo.orig"); - is (SBO::Lib::revert_slackbuild("$tmp/foo"), 1, "revert_slackbuild() returned 1"); - ok (-f "$tmp/foo", 'foo.orig renamed to foo'); - ok (!-f "$tmp/foo.orig", 'foo.orig is no more'); -} - -# 43: test get_src_dir(); -SKIP: { - skip 'Test invalid if /foo-bar exists.', 1 if -e '/foo-bar'; - my $scalar = ''; - open(my $fh, '<', \$scalar) or skip "Could not open needed filehandle", 1; - - local $SBO::Lib::tmpd = "/foo-bar"; - is (scalar @{ SBO::Lib::get_src_dir($fh) }, 0, "get_src_dir() returned an empty array ref"); -} - -# 44-45: test get_readme_contents(); -{ - my @ret = get_readme_contents(undef); - is ($ret[0], undef, "get_readme_contents() returned undef"); - is ($ret[1], 6, "get_readme_contents() returned 6"); -} - -# 46-47: test user_prompt(); -{ - my $exit; - my $out = capture_merged { $exit = exit_code { user_prompt('foo', undef); }; }; - - is ($exit, 1, 'user_prompt() exited with 1'); - is ($out, "Unable to locate foo in the SlackBuilds.org tree.\n", 'user_prompt() gave correct output'); -} diff --git a/t/20-unit-args.t b/t/20-unit-args.t deleted file mode 100755 index bb70939..0000000 --- a/t/20-unit-args.t +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env perl - -# This should probably replace 01-test.t once it's thorough enough - -use strict; -use warnings; -use Test::More; -use Test::Exit; -use FindBin '$RealBin'; -use lib "$RealBin/../SBO-Lib/lib"; -use SBO::Lib; -use Capture::Tiny qw/ capture_merged /; - -plan tests => 60; - -sub test_args { - my $sub = shift; - my @args = @_; - subtest "Testing $sub exit status when called with too few arguments", sub { - plan tests => 2; - - my $exit; - my $out = capture_merged { $exit = exit_code { SBO::Lib->can("SBO::Lib::$sub")->(@args); }; }; - - is ($exit, 2, "$sub(@args) exited with 2"); - like ($out, qr!\QA fatal script error has occurred:\E\n\Q$sub\E.*\nExiting\.\n!, "$sub(@args) gave correct output"); - } -} - -test_args $_ for qw/ - rsync_sbo_tree git_sbo_tree check_git_remote get_installed_packages get_inst_names - get_sbo_location get_sbo_locations is_local get_orig_location get_orig_version - get_sbo_from_loc get_from_info get_sbo_version get_download_info get_sbo_downloads - get_filename_from_link verify_distfile get_distfile get_symlink_from_filename - check_x32 rewrite_slackbuild revert_slackbuild check_distfiles create_symlinks - get_src_dir get_tmp_extfn perform_sbo do_convertpkg do_slackbuild make_clean - make_distclean do_upgradepkg get_build_queue merge_queues get_readme_contents - get_user_group ask_user_group get_opts ask_opts user_prompt -/; - -test_args 'get_from_info', LOCATION => 1; -test_args 'get_from_info', GET => 1; -test_args 'get_sbo_downloads', LOCATION => $0; -test_args 'compute_md5sum', $RealBin; -test_args 'get_symlink_from_filename', $RealBin, 0; -test_args 'perform_sbo', LOCATION => 1; -test_args 'perform_sbo', ARCH => 1; -test_args 'make_clean', SBO => 1; -test_args 'make_clean', SRC => 1; -test_args 'make_clean', VERSION => 1; -test_args 'make_clean', SBO => 1, SRC => 1; -test_args 'make_clean', SBO => 1, VERSION => 1; -test_args 'make_clean', SRC => 1, VERSION => 1; -test_args 'make_distclean', SRC => 1; -test_args 'make_distclean', VERSION => 1; -test_args 'make_distclean', LOCATION => 1; -test_args 'make_distclean', SRC => 1, VERSION => 1; -test_args 'make_distclean', SRC => 1, LOCATION => 1; -test_args 'make_distclean', VERSION => 1, LOCATION => 1; -test_args 'process_sbos', TODO => []; -- cgit v1.2.3