From e77acc913f47bce50ad00fddf484faf6baf92df9 Mon Sep 17 00:00:00 2001 From: Andreas Guldstrand Date: Sun, 28 Aug 2016 18:34:17 +0200 Subject: 02*.t: add another unit test file with new tests --- t/02-unit-args.t | 60 -------------------- t/02.1-unit-args.t | 60 ++++++++++++++++++++ t/02.2-unit-repo.t | 91 ++++++++++++++++++++++++++++++ t/02.2-unit-repo/SLACKBUILDS.TXT | 2 + t/02.2-unit-repo/test/test/README | 1 + t/02.2-unit-repo/test/test/test.SlackBuild | 15 +++++ t/02.2-unit-repo/test/test/test.info | 10 ++++ 7 files changed, 179 insertions(+), 60 deletions(-) delete mode 100755 t/02-unit-args.t create mode 100755 t/02.1-unit-args.t create mode 100755 t/02.2-unit-repo.t create mode 100644 t/02.2-unit-repo/SLACKBUILDS.TXT create mode 100644 t/02.2-unit-repo/test/test/README create mode 100644 t/02.2-unit-repo/test/test/test.SlackBuild create mode 100644 t/02.2-unit-repo/test/test/test.info (limited to 't') diff --git a/t/02-unit-args.t b/t/02-unit-args.t deleted file mode 100755 index bb70939..0000000 --- a/t/02-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 => []; diff --git a/t/02.1-unit-args.t b/t/02.1-unit-args.t new file mode 100755 index 0000000..bb70939 --- /dev/null +++ b/t/02.1-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/02.2-unit-repo.t b/t/02.2-unit-repo.t new file mode 100755 index 0000000..2b71fcf --- /dev/null +++ b/t/02.2-unit-repo.t @@ -0,0 +1,91 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use Test::Exit; +use FindBin '$RealBin'; +use lib "$RealBin/../SBO-Lib/lib"; +use SBO::Lib qw/ do_slackbuild rsync_sbo_tree /; +use Capture::Tiny qw/ capture_merged /; +use File::Path qw/ remove_tree /; + +if (defined $ENV{TRAVIS} and $ENV{TRAVIS} eq 'true') { + plan tests => 12; +} else { + plan skip_all => 'Only run these tests under Travis CI (TRAVIS=true)'; +} + +# first set up the repo +my $repo = "/usr/sbo/repo"; +my $moved = rename $repo, "$repo.orig"; +my $url = "$RealBin/02.2-unit-repo/"; + +capture_merged { + rsync_sbo_tree($url); +}; + +# 1-3: test do_slackbuild() without /etc/profile.d/32dev.sh +{ + my $file = "/etc/profile.d/32dev.sh"; + my $moved = rename $file, "$file.orig"; + + my ($exit, @ret); + my $out = capture_merged { $exit = exit_code { @ret = do_slackbuild(LOCATION => "/usr/sbo/repo/test/test", COMPAT32 => 1); }; }; + + is ($exit, undef, "do_slackbuild() didn't exit without $file."); + is ($out, "", "do_slackbuild() didn't output anything without $file."); + is_deeply (\@ret, ["compat32 requires multilib.\n", undef, undef, 9], "do_slackbuild() returned the correct things without $file."); + + rename "$file.orig", $file if $moved; +} + +# 4-6: test do_slackbuild() without /usr/sbin/convertpkg-compat32 +SKIP: { + skip "These tests require /etc/profile.d/32dev.sh to be an existing file.", 3 unless -f "/etc/profile.d/32dev.sh"; + + my $file = "/usr/sbin/convertpkg-compat32"; + my $moved = rename $file, "$file.orig"; + + my ($exit, @ret); + my $out = capture_merged { $exit = exit_code { @ret = do_slackbuild(LOCATION => "/usr/sbo/repo/test/test", COMPAT32 => 1); }; }; + + is ($exit, undef, "do_slackbuild() didn't exit without $file."); + is ($out, "", "do_slackbuild() didn't output anything without $file."); + is_deeply (\@ret, ["compat32 requires $file.\n", undef, undef, 11], "do_slackbuild() returned the correct things without $file."); + + rename "$file.orig", $file if $moved; +} + +# 7-9: test do_slackbuild() without needed multilib +{ + no warnings 'redefine'; + + local *SBO::Lib::Build::get_arch = sub { return 'x86_64' }; + local *SBO::Lib::Build::check_multilib = sub { return (); }; + + my ($exit, @ret); + my $out = capture_merged { $exit = exit_code { @ret = do_slackbuild(LOCATION => "/usr/sbo/repo/test/test" ); }; }; + + is ($exit, undef, "do_slackbuild() didn't exit without needed multilib."); + is ($out, "", "do_slackbuild() didn't output anything without needed multilib."); + is_deeply (\@ret, ["test is 32-bit which requires multilib on x86_64.\n", undef, undef, 9], "do_slackbuild() returned the correct things without needed multilib."); +} + +# 10-12: test do_slackbuild() which thinks it's on 32bit +{ + no warnings 'redefine'; + + local *SBO::Lib::Build::get_arch = sub { return 'i586' }; + local *SBO::Lib::Build::perform_sbo = sub { return 'sentinel', undef, -1 }; + + my ($exit, @ret); + my $out = capture_merged { $exit = exit_code { @ret = do_slackbuild(LOCATION => "/usr/sbo/repo/test/test" ); }; }; + + is ($exit, undef, "do_slackbuild() didn't exit when it's on 32bit."); + is ($out, "", "do_slackbuild() didn't output anything when it's on 32bit."); + is_deeply (\@ret, ["sentinel", undef, undef, -1], "do_slackbuild() returned the correct things when it's on 32bit."); +} + +remove_tree($repo); +rename "$repo.orig", $repo if $moved; diff --git a/t/02.2-unit-repo/SLACKBUILDS.TXT b/t/02.2-unit-repo/SLACKBUILDS.TXT new file mode 100644 index 0000000..f6cebcf --- /dev/null +++ b/t/02.2-unit-repo/SLACKBUILDS.TXT @@ -0,0 +1,2 @@ +SLACKBUILD NAME: test +SLACKBUILD LOCATION: ./test/test diff --git a/t/02.2-unit-repo/test/test/README b/t/02.2-unit-repo/test/test/README new file mode 100644 index 0000000..6d388bb --- /dev/null +++ b/t/02.2-unit-repo/test/test/README @@ -0,0 +1 @@ +This doesn't exist! diff --git a/t/02.2-unit-repo/test/test/test.SlackBuild b/t/02.2-unit-repo/test/test/test.SlackBuild new file mode 100644 index 0000000..78f1fd2 --- /dev/null +++ b/t/02.2-unit-repo/test/test/test.SlackBuild @@ -0,0 +1,15 @@ +#!/bin/bash +PRGNAM="test" +VERSION=${VERSION:-1.0} +BUILD=${BUILD:-1} +TAG=${TAG:-_SBo} +TMP=${TMP:-/tmp/SBo} +OUTPUT=${OUTPUT:-/tmp} + +mkdir -p $TMP/$PRGNAM-$VERSION +cp README $TMP/$PRGNAM-$VERSION +mkdir -p $OUTPUT/package-$PRGNAM/usr/doc/$PRGNAM-$VERSION +cp README $OUTPUT/package-$PRGNAM/usr/doc/$PRGNAM-$VERSION +cd $OUTPUT/package-$PRGNAM + +/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-noarch-$BUILD$TAG.tgz diff --git a/t/02.2-unit-repo/test/test/test.info b/t/02.2-unit-repo/test/test/test.info new file mode 100644 index 0000000..294378c --- /dev/null +++ b/t/02.2-unit-repo/test/test/test.info @@ -0,0 +1,10 @@ +PRGNAM="test" +VERSION="1.0" +HOMEPAGE="http://www.example.com" +DOWNLOAD="http://pink-mist.github.io/sbotools/testing/perf.dummy" +MD5SUM="9cba6c70fb57a22a155073d54748b614" +DOWNLOAD_x86_64="UNSUPPORTED" +MD5SUM_x86_64="" +REQUIRES="" +MAINTAINER="Andreas Guldstrand" +EMAIL="doesnt@matter.org" -- cgit v1.2.3