diff options
-rw-r--r-- | SBO-Lib/lib/SBO/Lib/Readme.pm | 24 | ||||
-rwxr-xr-x | sboremove | 4 | ||||
-rwxr-xr-x | t/01-unit.t | 13 | ||||
-rwxr-xr-x | t/02.1-unit-args.t | 6 | ||||
-rwxr-xr-x | t/07-fail.t | 6 |
5 files changed, 23 insertions, 30 deletions
diff --git a/SBO-Lib/lib/SBO/Lib/Readme.pm b/SBO-Lib/lib/SBO/Lib/Readme.pm index 6325ad1..a16bb49 100644 --- a/SBO-Lib/lib/SBO/Lib/Readme.pm +++ b/SBO-Lib/lib/SBO/Lib/Readme.pm @@ -6,7 +6,7 @@ use warnings; our $VERSION = '2.0'; -use SBO::Lib::Util qw/ script_error open_read _ERR_OPENFH usage_error /; +use SBO::Lib::Util qw/ script_error slurp open_read _ERR_OPENFH usage_error /; use SBO::Lib::Tree qw/ is_local /; use Exporter 'import'; @@ -118,23 +118,17 @@ sub get_opts { =head2 get_readme_contents - my ($ret, $exit) = get_readme_contents($location); + my $contents = get_readme_contents($location); -C<get_readme_contents()> will open the README file in C<$location>. - -It returns a list of two values. The second value is the exit status, and if it -is true, the first value will be the undefined value. Otherwise the frist value -will be the contents of the README. +C<get_readme_contents()> will open the README file in C<$location> and return +its contents. On error, it will return C<undef>. =cut sub get_readme_contents { script_error('get_readme_contents requires an argument.') unless @_ == 1; - return undef, _ERR_OPENFH if not defined $_[0]; - my ($fh, $exit) = open_read(shift .'/README'); - return undef, $exit if $exit; - my $readme = do {local $/; <$fh>}; - close $fh; + return undef unless defined $_[0]; + my $readme = slurp(shift . '/README'); return $readme; } @@ -179,9 +173,9 @@ sub user_prompt { script_error('user_prompt requires two arguments.') unless @_ == 2; my ($sbo, $location) = @_; if (not defined $location) { usage_error("Unable to locate $sbo in the SlackBuilds.org tree."); } - my ($readme, $exit) = get_readme_contents($location); - if (is_local($sbo)) { print "\nFound $sbo in local overrides.\n"; $exit = 0; } - return $readme, undef, $exit if $exit; + my $readme = get_readme_contents($location); + usage_error("Could not open README for $sbo.") unless defined $readme; + if (is_local($sbo)) { print "\nFound $sbo in local overrides.\n"; } # check for user/group add commands, offer to run any found my $user_group = get_user_group($readme); my $cmds; @@ -147,8 +147,8 @@ FIRST: for my $remove (@$remove_queue) { say "It is recommended that you view the README before continuing."; print "Display README now? [y]: "; if (<STDIN> =~ /^[Yy\n]/) { - my ($readme, $exit) = get_readme_contents(get_sbo_location($remove)); - if ($exit) { + my $readme = get_readme_contents(get_sbo_location($remove)); + if (not defined $readme) { warn "Unable to open README for $remove.\n"; } else { print "\n" . $readme; diff --git a/t/01-unit.t b/t/01-unit.t index 3e973aa..13d6e8e 100755 --- a/t/01-unit.t +++ b/t/01-unit.t @@ -11,7 +11,7 @@ use Capture::Tiny qw/ capture_merged /; use File::Temp 'tempdir'; use Cwd; -plan tests => 61; +plan tests => 60; # 1-2: test script_error(); { @@ -277,14 +277,13 @@ SKIP: { is (scalar @{ SBO::Lib::get_src_dir($fh) }, 0, "get_src_dir() returned an empty array ref"); } -# 49-50: test get_readme_contents(); +# 49: 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"); } -# 51-52: test user_prompt(); +# 50-51: test user_prompt(); { my $exit; my $out = capture_merged { $exit = exit_code { user_prompt('foo', undef); }; }; @@ -293,7 +292,7 @@ SKIP: { is ($out, "Unable to locate foo in the SlackBuilds.org tree.\n", 'user_prompt() gave correct output'); } -# 53-55: test perform_sbo(); +# 52-54: test perform_sbo(); SKIP: { skip 'Tests invalid if /foo exists.', 3 if -e "/foo"; @@ -304,7 +303,7 @@ SKIP: { is ($res[2], 6, 'perform_sbo returned correct exit'); } -# 56-60: test version_cmp(); +# 55-59: test version_cmp(); { chomp(my $kv = `uname -r`); $kv =~ s/-/_/g; @@ -322,7 +321,7 @@ SKIP: { is (SBO::Lib::version_cmp('1.0', '1.0_foo_bar'), 0, "version_cmp(1.0, 1.0_foo_bar) returned 0"); } -# 61: test check_multilib(); +# 60: test check_multilib(); { my $file = "/etc/profile.d/32dev.sh"; diff --git a/t/02.1-unit-args.t b/t/02.1-unit-args.t index bb70939..8b74fd4 100755 --- a/t/02.1-unit-args.t +++ b/t/02.1-unit-args.t @@ -11,7 +11,7 @@ use lib "$RealBin/../SBO-Lib/lib"; use SBO::Lib; use Capture::Tiny qw/ capture_merged /; -plan tests => 60; +plan tests => 59; sub test_args { my $sub = shift; @@ -34,8 +34,8 @@ test_args $_ for qw/ 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 + make_distclean do_upgradepkg get_build_queue merge_queues get_user_group + ask_user_group get_opts ask_opts user_prompt /; test_args 'get_from_info', LOCATION => 1; diff --git a/t/07-fail.t b/t/07-fail.t index 38569ed..507be68 100755 --- a/t/07-fail.t +++ b/t/07-fail.t @@ -129,7 +129,7 @@ sboinstall 'malformed-info2', { input => "y\ny\nn", expected => qr!Failures:\n sboinstall 'malformed-info3', { exit => 2, expected => "A fatal script error has occurred:\nerror when parsing malformed-info3.info file. Line: FAIL\nExiting.\n" }; # 14: Malformed slackbuild - no readme -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 }; +sboinstall 'malformed-readme', { expected => "Could not open README for malformed-readme.\n", exit => 1 }; # 15: Malformed slackbuild - no .SlackBuild sboinstall 'malformed-slackbuild', @@ -175,7 +175,7 @@ sboinstall qw/ -r failingslackbuild /, { expected => qr/Failures:\n failingslac # 22-24: Slackbuild with %README% req without a readme sboinstall qw/ -r noreadmebutreadmereq /; -sboremove qw/ noreadmebutreadmereq /, { input => 'y', expected => qr/fatal script error.*open_fh/s, exit => 2 }; +sboremove qw/ noreadmebutreadmereq /, { input => "y\nn", expected => qr/Unable to open README for noreadmebutreadmereq[.]/s, exit => 0 }; sboremove qw/ noreadmebutreadmereq /, { input => "n\ny\ny", expected => qr/Display README.*Remove noreadme.*Added to remove queue.*Removing 1 pack.*noreadme.*All operations/s, exit => 0 }; # 25: compat32 should fail for a perl sbo @@ -203,7 +203,7 @@ SKIP: { 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"; - sboinstall qw/ -p malformed-readme /, { exit => 2, expected => qr!A fatal script error has occurred:\nopen_fh, .*t/LO-fail/malformed-readme/README is not a file! }; + sboinstall qw/ -p malformed-readme /, { exit => 1, expected => qr!Could not open README for malformed-readme[.]! }; } # 27: sboupgrade with -r and -z |