summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2020-02-03 21:10:47 -0700
committerSean Whitton <spwhitton@spwhitton.name>2020-02-03 21:13:59 -0700
commitad60c0f67d30e658e785b0d9fc91880678c25b55 (patch)
tree74b58abb10c9664e8f432eb4fde6e3d0a97c3599 /t
parent6e723d0aee68ef490d415148bbaa3fddd120f197 (diff)
downloadp5-Git-Annex-ad60c0f67d30e658e785b0d9fc91880678c25b55.tar.gz
add Git::Annex::BatchCommand
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 't')
-rwxr-xr-xt/13_batchcommand.t62
1 files changed, 62 insertions, 0 deletions
diff --git a/t/13_batchcommand.t b/t/13_batchcommand.t
new file mode 100755
index 0000000..109b24d
--- /dev/null
+++ b/t/13_batchcommand.t
@@ -0,0 +1,62 @@
+#!/usr/bin/perl
+
+use 5.028;
+use strict;
+use warnings;
+use lib 't/lib';
+
+use Test::More;
+use Git::Annex;
+use Git::Annex::BatchCommand;
+use t::Setup;
+use Scalar::Util qw(looks_like_number);
+use Try::Tiny;
+
+with_temp_annexes {
+ my (undef, $source1) = @_;
+
+ my $annex = Git::Annex->new($source1->dir);
+ #<<<
+ try {
+ my $nope = Git::Annex::BatchCommand->new;
+ } catch {
+ ok grep(/not enough arguments/, $_), "it requires an annex";
+ };
+ #>>>
+ #<<<
+ try {
+ my $nope = $annex->batch;
+ } catch {
+ ok grep(/not enough arguments/, $_), "it requires a command";
+ };
+ #>>>
+
+ my $batch = $annex->batch("find", "--in=here");
+
+ # TODO there are races here due to the (faint) possibility of PID reuse
+ my $first_pid = $batch->{_pid};
+ ok looks_like_number $first_pid, "it stores a PID";
+ ok kill(0, $first_pid), "the PID is a running process";
+ $batch->restart;
+ ok !kill(0, $first_pid), "the old PID is no longer a running process";
+ my $second_pid = $batch->{_pid};
+ isnt $first_pid, $second_pid, "it starts a new process";
+ ok looks_like_number $second_pid, "it stores a PID again";
+ ok kill(0, $second_pid), "the new PID is a running process";
+
+ ok grep(/\A--batch\z/, @{ $batch->{_cmd} }),
+ "it passes --batch to git-annex";
+ my ($response1, $response2) = $batch->say("foo/foo2/baz", "foo/foo2/baz");
+ is $response1, $response2, "it returns a list in list context";
+ is scalar $batch->say("foo/foo2/baz", "foo/foo2/baz"), 2,
+ "it returns a scalar in scalar context";
+ my ($response3, $response4) = $batch->say("foo/foo2/baz", "foo/bar");
+ is_deeply [$response3, $response4], ["foo/foo2/baz", ""],
+ "it returns results in the correct order";
+
+ undef $batch;
+ ok !kill(0, $second_pid),
+ "it cleans up the process when object goes out of scope";
+};
+
+done_testing;