diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2020-02-07 22:59:11 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2020-02-07 23:03:56 -0700 |
commit | 64f954528b4c62abdf2de391afb6fe2715c60046 (patch) | |
tree | 3b95ce4dc6df7bbcadd9a94529bbf523ceeb0b54 /t | |
parent | 62513c36dcce2593615ad3567dd2b384c6ce89a3 (diff) | |
download | p5-Git-Annex-64f954528b4c62abdf2de391afb6fe2715c60046.tar.gz |
convert annex-review-unused into an App:: module
This solves the PATH problem of testing the right version of the
scripts.
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 't')
-rwxr-xr-x | t/24_annex-review-unused.t | 27 | ||||
-rw-r--r-- | t/lib/t/Util.pm | 27 |
2 files changed, 38 insertions, 16 deletions
diff --git a/t/24_annex-review-unused.t b/t/24_annex-review-unused.t index 30e4288..0e8742c 100755 --- a/t/24_annex-review-unused.t +++ b/t/24_annex-review-unused.t @@ -5,34 +5,31 @@ use strict; use warnings; use lib 't/lib'; +use App::annex_review_unused; use Test::More; use t::Setup; +use t::Util; use File::chdir; use File::Spec::Functions qw(rel2abs); - -# make sure that `make test` will always use the right version of the -# script we seek to test -my $aru = "annex-review-unused"; -$aru = rel2abs "blib/script/annex-review-unused" - if -x "blib/script/annex-review-unused"; +use Capture::Tiny qw(capture_stdout); with_temp_annexes { my (undef, $source1) = @_; + my ($output, $exit); { local $CWD = "source1"; - system $aru; - ok !$?, "it exits zero when no unused files"; + (undef, undef, $exit) = run_bin "annex-review-unused"; + ok !$exit, "it exits zero when no unused files"; sleep 1; $source1->rm("foo/foo2/baz"); $source1->commit({ message => "rm" }); - my @output = `$aru --just-print`; - my $exit = $? >> 8; - ok $?, "it exits nonzero when unused files"; - ok 20 < @output && @output < 30, "it prints ~two log entries"; - like $output[5], qr/unused file #1/, "it prints an expected line"; + + ($output, undef, $exit) = run_bin qw(annex-review-unused --just-print); + ok $exit, "it exits nonzero when unused files"; + ok 20 < @$output && @$output < 30, "it prints ~two log entries"; + like $output->[5], qr/unused file #1/, "it prints an expected line"; } -} -; +}; done_testing; diff --git a/t/lib/t/Util.pm b/t/lib/t/Util.pm index bb8f59e..b1312f5 100644 --- a/t/lib/t/Util.pm +++ b/t/lib/t/Util.pm @@ -8,8 +8,10 @@ use File::Slurp; use File::Spec::Functions qw(rel2abs); use File::chdir; use File::Temp qw(tempdir); +use Try::Tiny; +use Capture::Tiny qw(capture); -our @EXPORT = qw( corrupt_annexed_file device_id_issues ); +our @EXPORT = qw( corrupt_annexed_file device_id_issues run_bin ); sub corrupt_annexed_file { my ($git, $file) = @_; @@ -37,4 +39,27 @@ sub device_id_issues { return($foo_id != $bar_id); } +sub run_bin { + (my $bin = "App::" . shift) =~ tr/-/_/; + local @ARGV = @_; + my ($stdout, $stderr, $exit) = capture { + my $exit; + #<<< + # in order to simulate calling the program at the command + # line, convert exceptions into what happens when an ordinary + # perl script, invoked from the command line, calls 'die' + try { + $exit = $bin->main; + } catch { + say STDERR $_; + $exit = 255; + }; + #>>> + return $exit; + }; + my @stdout = split "\n", $stdout; + my @stderr = split "\n", $stderr; + return (\@stdout, \@stderr, $exit); +} + 1; |