diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2020-02-01 10:52:36 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2020-02-01 10:53:07 -0700 |
commit | 067680560397147080a8eba480abd9637e6e0251 (patch) | |
tree | 01ce21eefce8850faa49fb60df9cf28aa1819cea /t | |
parent | a99a0e9e9f8cf83e7e1e41a4b4ac49a32ca76ee4 (diff) | |
download | p5-Git-Annex-067680560397147080a8eba480abd9637e6e0251.tar.gz |
factor out with_temp_annex
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 't')
-rwxr-xr-x | t/10_init.t | 20 | ||||
-rw-r--r-- | t/lib/t/Setup.pm | 26 |
2 files changed, 30 insertions, 16 deletions
diff --git a/t/10_init.t b/t/10_init.t index 02e284c..0d4b5a8 100755 --- a/t/10_init.t +++ b/t/10_init.t @@ -3,12 +3,13 @@ use 5.028; use strict; use warnings; +use lib 't/lib'; use Test::More; use Git::Annex; use File::chdir; -use File::Slurp; use File::Temp qw(tempdir); +use t::Setup; { my $temp = tempdir CLEANUP => 1; @@ -30,26 +31,13 @@ use File::Temp qw(tempdir); # lazy init of Git::Repository object requires an actual git repo, not # just an empty tempdir -with_temp_annex(sub { +with_temp_annex { my $temp = shift; my $annex = Git::Annex->new($temp); ok !defined $annex->{repo}, "Git::Repository instance lazily instantiated"; ok $annex->repo->isa("Git::Repository") && defined $annex->{repo}, "Git::Repository instance available"; ok $annex->repo->work_tree eq $temp, "Git::Repository has correct toplevel"; -}); - -sub with_temp_annex { - my $temp = tempdir CLEANUP => 1; - { - local $CWD = $temp; - system qw(git init); - system qw(git annex init); - write_file "foo", "my cool big file\n"; - system qw(git annex add foo); - system qw(git commit -madd); - } - &{$_[0]}($temp); -} +}; done_testing; diff --git a/t/lib/t/Setup.pm b/t/lib/t/Setup.pm new file mode 100644 index 0000000..d92b288 --- /dev/null +++ b/t/lib/t/Setup.pm @@ -0,0 +1,26 @@ +package t::Setup; + +use 5.028; +use strict; +use warnings; + +use Exporter 'import'; +use File::Slurp; +use File::Temp qw(tempdir); +use Git::Wrapper; +use File::Spec::Functions qw(catfile); + +our @EXPORT = qw( with_temp_annex ); + +sub with_temp_annex (&) { + my $temp = tempdir CLEANUP => 1; + my $git = Git::Wrapper->new($temp); + $git->init; + $git->annex("init"); + write_file catfile($temp, "foo"), "my cool big file\n"; + $git->annex(qw(add foo)); + $git->commit({message => "add"}); + &{$_[0]}($temp); +} + +1; |