diff options
-rw-r--r-- | t/SBO/Lib.pm | 43 | ||||
-rwxr-xr-x | t/prep.pl | 2 | ||||
-rwxr-xr-x | t/test.t | 24 | ||||
-rwxr-xr-x | t/test.t~ | 95 |
4 files changed, 43 insertions, 121 deletions
diff --git a/t/SBO/Lib.pm b/t/SBO/Lib.pm index 398e6a3..c2b9ef5 100644 --- a/t/SBO/Lib.pm +++ b/t/SBO/Lib.pm @@ -18,7 +18,7 @@ my $version = "1.0"; require Exporter; our @ISA = qw(Exporter); -our @EXPORT = qw(get_slack_version chk_slackbuilds_txt check_home rsync_sbo_tree get_sbo_from_loc get_sbo_version get_download_info get_arch get_sbo_downloads get_filename_from_link compute_md5sum compare_md5s verify_distfile get_distfile get_symlink_from_filename check_x32 check_multilib rewrite_slackbuild revert_slackbuild check_distfiles create_symlinks grok_temp_file get_src_dir get_pkg_name perform_sbo do_convertpkg +our @EXPORT = qw(get_slack_version chk_slackbuilds_txt check_home rsync_sbo_tree get_sbo_from_loc get_sbo_version get_download_info get_arch get_sbo_downloads get_filename_from_link compute_md5sum compare_md5s verify_distfile get_distfile get_symlink_from_filename check_x32 check_multilib rewrite_slackbuild revert_slackbuild check_distfiles create_symlinks grok_temp_file get_src_dir get_pkg_name clear_coe_bit perform_sbo do_convertpkg script_error open_fh open_read @@ -34,7 +34,8 @@ our @EXPORT = qw(get_slack_version chk_slackbuilds_txt check_home rsync_sbo_tree do_upgradepkg get_sbo_location get_from_info - get_tmp_fn + get_tmp_extfn + get_tmp_perlfn ); #$< == 0 or die "This script requires root privileges.\n"; @@ -47,7 +48,6 @@ use File::Path qw(make_path remove_tree); use Fcntl; use File::Find; use File::Temp qw(tempdir tempfile); -use Data::Dumper; use Fcntl qw(F_SETFD F_GETFD); our $tempdir = tempdir (CLEANUP => 1); @@ -61,7 +61,9 @@ sub script_error (;$) { # sub for opening files, second arg is like '<','>', etc sub open_fh ($$) { exists $_[1] or script_error 'open_fh requires two arguments'; - -f $_[0] or script_error 'open_fh first argument not a file'; + unless ($_[1] eq '>') { + -f $_[0] or script_error 'open_fh first argument not a file'; + } my ($file, $op) = @_; open my $fh, $op, $file or die "Unable to open $file.\n"; return $fh; @@ -154,13 +156,13 @@ sub rsync_sbo_tree () { sub fetch_tree () { check_home; say 'Pulling SlackBuilds tree...'; - rsync_sbo_tree, return $?; + rsync_sbo_tree, return 1; } sub update_tree () { fetch_tree, return unless chk_slackbuilds_txt; say 'Updating SlackBuilds tree...'; - rsync_sbo_tree, return $?; + rsync_sbo_tree, return 1; } # if the SLACKBUILDS.TXT is not in $config{SBO_HOME}, we assume the tree has @@ -445,7 +447,7 @@ sub revert_slackbuild ($) { my $slackbuild = shift; if (-f "$slackbuild.orig") { unlink $slackbuild if -f $slackbuild; - rename ("$slackbuild.orig", $slackbuild); + rename "$slackbuild.orig", $slackbuild; } return 1; } @@ -500,7 +502,6 @@ sub grok_temp_file (%) { last FIRST; } } -# close $fh; return $out; } @@ -516,11 +517,26 @@ sub get_pkg_name ($) { REGEX => qr/^Slackware\s+package\s+([^\s]+)\s+created\.$/); } -sub get_tmp_fn ($) { - exists $_[0] or script_error 'get_tmp_fn requires an argument.'; +# clear the close-on-exec bit from a temp file handle +sub clear_coe_bit ($) { + exists $_[0] or script_error 'clear_coe_bit requires an argument'; my $fh = shift; fcntl ($fh, F_SETFD, 0) or die "no unset exec-close thingy\n"; - return "/dev/fd/". fileno $fh; + return $fh; +} + +# return a filename from a temp fh for use externally +sub get_tmp_extfn ($) { + exists $_[0] or script_error 'get_tmp_extfn requires an argument.'; + my $fh = clear_coe_bit shift; + return '/dev/fd/'. fileno $fh; +} + +# return a filename from a temp fh for use internally +sub get_tmp_perlfn ($) { + exists $_[0] or script_error 'get_tmp_perlfn requires an argument.'; + my $fh = clear_coe_bit shift; + return '+<=&'. fileno $fh; } # prep and run .SlackBuild @@ -553,7 +569,7 @@ sub perform_sbo (%) { $cmd .= "/bin/sh $location/$sbo.SlackBuild"; $cmd = "$args{OPTS} $cmd" if $args{OPTS}; my $tempfh = tempfile (DIR => $tempdir); - my $fn = get_tmp_fn $tempfh; + my $fn = get_tmp_extfn $tempfh; rewrite_slackbuild "$location/$sbo.SlackBuild", $fn, %changes; chdir $location, my $out = system $cmd; revert_slackbuild "$location/$sbo.SlackBuild"; @@ -568,7 +584,7 @@ sub do_convertpkg ($) { exists $_[0] or script_error 'do_convertpkg requires an argument.'; my $pkg = shift; my $tempfh = tempfile (DIR => $tempdir); - my $fn = get_tmp_fn $tempfh; + my $fn = get_tmp_extfn $tempfh; my $cmd = "/usr/sbin/convertpkg-compat32 -i $pkg -d /tmp | tee $fn"; system ($cmd) == 0 or die; unlink $pkg; @@ -666,3 +682,4 @@ sub do_upgradepkg ($) { system ('/sbin/upgradepkg', '--reinstall', '--install-new', shift); return 1; } + @@ -7,7 +7,7 @@ use Tie::File; chomp (my $pwd = `pwd`); mkdir "$pwd/SBO" unless -d "$pwd/SBO"; -copy ('/home/d4wnr4z0r/projects/sbotools/SBO-Lib/lib/SBO/Lib.pm', "$pwd/SBO"); +copy ('/home/d4wnr4z0r/projects/slack14/sbotools/SBO-Lib/lib/SBO/Lib.pm', "$pwd/SBO"); my @subs; open my $file_h, '<', "$pwd/SBO/Lib.pm"; my $regex = qr/^sub\s+([^\s]+)\s+/; @@ -1,4 +1,4 @@ -#!/usr/bin/perl -I/home/d4wnr4z0r/projects/sbotools/t +#!/usr/bin/perl -I/home/d4wnr4z0r/projects/slack14/sbotools/t use 5.16.0; use strict; @@ -10,21 +10,21 @@ use SBO::Lib; ok (defined $SBO::Lib::tempdir, '$tempdir is defined'); my $fh = open_read ('/home/d4wnr4z0r/projects/sbotools/t/test.t'); -ok (ref ($fh) eq 'GLOB', 'open_read works'); +is (ref $fh, 'GLOB', 'open_read works'); close $fh; -ok ($SBO::Lib::config{DISTCLEAN} eq 'FALSE', 'config{DISTCLEAN} is good'); -ok ($SBO::Lib::config{JOBS} == 2, 'config{JOBS} is good'); -ok ($SBO::Lib::config{NOCLEAN} eq 'TRUE', 'config{NOCLEAN} is good'); -ok ($SBO::Lib::config{PKG_DIR} eq 'FALSE', 'config{PKG_DIR} is good'); -ok ($SBO::Lib::config{SBO_HOME} eq '/usr/sbo', 'config{SBO_HOME} is good'); +is ($SBO::Lib::config{DISTCLEAN}, 'FALSE', 'config{DISTCLEAN} is good'); +is ($SBO::Lib::config{JOBS}, 2, 'config{JOBS} is good'); +is ($SBO::Lib::config{NOCLEAN}, 'FALSE', 'config{NOCLEAN} is good'); +is ($SBO::Lib::config{PKG_DIR}, 'FALSE', 'config{PKG_DIR} is good'); +is ($SBO::Lib::config{SBO_HOME}, '/usr/sbo', 'config{SBO_HOME} is good'); -ok (show_version == 1, 'show_version is good'); -ok (get_slack_version eq '14.0', 'get_slack_version is good'); -ok (chk_slackbuilds_txt == 1, 'check_slackbuilds_txt is good'); +is (show_version, 1, 'show_version is good'); +is (get_slack_version, '14.0', 'get_slack_version is good'); +is (chk_slackbuilds_txt, 1, 'check_slackbuilds_txt is good'); #ok (rsync_sbo_tree == 1, 'rsync_sbo_tree is good'); #ok (update_tree == 1, 'update_tree is good'); -ok (slackbuilds_or_fetch == 1, 'slackbuilds_or_fetch is good'); +is (slackbuilds_or_fetch, 1, 'slackbuilds_or_fetch is good'); print "pseudo-random sampling of get_installed_sbos output...\n"; my $installed = get_installed_sbos; @@ -46,7 +46,7 @@ for my $key (keys @$updates) { is ($$updates[$key]{update}, '1.20', '$$updates[$key]{update} good for mutagen') if $$updates[$key]{name} eq 'mutagen'; } -ok (get_arch eq 'x86_64', 'get_arch is good'); +is (get_arch, 'x86_64', 'get_arch is good'); my %dl_info = get_download_info (LOCATION => '/usr/sbo/system/wine', X64 => 0); my $link = 'http://downloads.sf.net/wine/source/1.4/wine-1.4.1.tar.bz2'; diff --git a/t/test.t~ b/t/test.t~ deleted file mode 100755 index 9b0a256..0000000 --- a/t/test.t~ +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/perl -I/home/d4wnr4z0r/projects/sbotools/t - -use 5.16.0; -use strict; -use warnings FATAL => 'all'; -use File::Temp qw(tempdir tempfile); -use Test::More tests => 39; -use SBO::Lib; - -ok (defined $SBO::Lib::tempdir, '$tempdir is defined'); - -my $fh = open_read ('/home/d4wnr4z0r/projects/sbotools/t/test.t'); -ok (ref ($fh) eq 'GLOB', 'open_read works'); -close $fh; - -ok ($SBO::Lib::config{DISTCLEAN} eq 'FALSE', 'config{DISTCLEAN} is good'); -ok ($SBO::Lib::config{JOBS} == 2, 'config{JOBS} is good'); -ok ($SBO::Lib::config{NOCLEAN} eq 'TRUE', 'config{NOCLEAN} is good'); -ok ($SBO::Lib::config{PKG_DIR} eq 'FALSE', 'config{PKG_DIR} is good'); -ok ($SBO::Lib::config{SBO_HOME} eq '/usr/sbo', 'config{SBO_HOME} is good'); - -ok (show_version == 1, 'show_version is good'); -ok (get_slack_version eq '14.0', 'get_slack_version is good'); -ok (chk_slackbuilds_txt == 1, 'check_slackbuilds_txt is good'); -#ok (rsync_sbo_tree == 1, 'rsync_sbo_tree is good'); -#ok (update_tree == 1, 'update_tree is good'); -ok (slackbuilds_or_fetch == 1, 'slackbuilds_or_fetch is good'); - -print "pseudo-random sampling of get_installed_sbos output...\n"; -my $installed = get_installed_sbos; -for my $key (keys @$installed) { - is ($$installed[$key]{version}, '1.13') if $$installed[$key]{name} eq 'OpenAL'; - is ($$installed[$key]{version}, '9.5.1_enu') if $$installed[$key]{name} eq 'adobe-reader'; - is ($$installed[$key]{version}, '4.1.3') if $$installed[$key]{name} eq 'libdvdnav'; - is ($$installed[$key]{version}, '0.8.8.4') if $$installed[$key]{name} eq 'libmodplug'; - is ($$installed[$key]{version}, '3.12.4') if $$installed[$key]{name} eq 'mozilla-nss'; - is ($$installed[$key]{version}, '2.5.0') if $$installed[$key]{name} eq 'zdoom'; -} -print "completed pseudo-random testing of get_installed_sbos \n"; - -is (get_sbo_location 'nginx', '/usr/sbo/network/nginx', 'get_sbo_location is good'); - -my $updates = get_available_updates; -for my $key (keys @$updates) { - is ($$updates[$key]{installed}, '1.15', '$$updates[$key]{installed} good for mutagen') if $$updates[$key]{name} eq 'mutagen'; - is ($$updates[$key]{update}, '1.20', '$$updates[$key]{update} good for mutagen') if $$updates[$key]{name} eq 'mutagen'; -} - -ok (get_arch eq 'x86_64', 'get_arch is good'); - -my %dl_info = get_download_info (LOCATION => '/usr/sbo/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.'); - -%dl_info = get_sbo_downloads (LOCATION => '/usr/sbo/system/wine'); -$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 => '/usr/sbo/system/ifuse'); -$link = 'http://www.libimobiledevice.org/downloads/ifuse-1.1.1.tar.bz2'; -is ($downloads{$link}, '8d528a79de024b91f12f8ac67965c37c', 'get_sbo_downloads test 03 good.'); - -is (get_filename_from_link 'http://www.libimobiledevice.org/downloads/ifuse-1.1.1.tar.bz2', '/usr/sbo/distfiles/ifuse-1.1.1.tar.bz2', 'get_file_from_link good'); -is (compute_md5sum '/usr/sbo/distfiles//laptop-mode-tools_1.61.tar.gz', '6685af5dbb34c3d51ca27933b58f484e', 'compute_md5sum good'); -is ((verify_distfile '/usr/sbo/distfiles/laptop-mode-tools_1.61.tar.gz', '6685af5dbb34c3d51ca27933b58f484e'), 1, 'verify_distfile good'); -is (get_sbo_version '/usr/sbo/system/wine', '1.4.1', 'get_sbo_version good'); -is ((get_symlink_from_filename '/usr/sbo/distfiles/laptop-mode-tools_1.61.tar.gz', '/usr/sbo/system/laptop-mode-tools'), '/usr/sbo/system/laptop-mode-tools/laptop-mode-tools_1.61.tar.gz', 'get_symlink_from_filename good'); -ok (check_x32 '/usr/sbo/system/wine', 'check_x32 true for 32-bit only wine'); -ok (!(check_x32 '/usr/sbo/system/ifuse'), 'check_x32 false for not-32-bit-only ifuse'); -ok (check_multilib, 'check_multilib good'); - -# TODO: find a way to write a test for rewrite_slackbuild, revert_slackbuild. - -%downloads = get_sbo_downloads (LOCATION => '/usr/sbo/system/wine', 32 => 1); -my @symlinks = create_symlinks '/usr/sbo/system/wine', %downloads; -is ($symlinks[0], '/usr/sbo/system/wine/wine-1.4.1.tar.bz2', '$symlinks[0] good for create_symlinks'); -is ($symlinks[1], '/usr/sbo/system/wine/dibeng-max-2010-11-12.zip', '$symlinks[1] good for create_symlinks'); - -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"; -#close $tempfh; -is (get_src_dir $tempfh, 'laptop-mode-tools_1.60', 'get_src_dir good'); -is (get_pkg_name $tempfh, 'skype-2.2.0.35-i486-1_SBo.tgz', 'get_pkg_name good'); -%downloads = get_sbo_downloads (LOCATION => '/usr/sbo/system/wine', 32 => 1); -is (check_distfiles %downloads, 1, 'check_distfiles good'); -#is (do_convertpkg ($package), "$package-compat32", 'do_convertpkg good'); |