summaryrefslogtreecommitdiff
path: root/t/dist/basic.t
diff options
context:
space:
mode:
Diffstat (limited to 't/dist/basic.t')
-rwxr-xr-xt/dist/basic.t59
1 files changed, 26 insertions, 33 deletions
diff --git a/t/dist/basic.t b/t/dist/basic.t
index 95a6986..6fcf2bc 100755
--- a/t/dist/basic.t
+++ b/t/dist/basic.t
@@ -17,6 +17,7 @@ use Cwd qw(getcwd);
use File::Copy::Recursive qw(dircopy);
use File::Spec;
use File::Temp;
+use Git::Repository;
use IPC::Run qw(run);
use IPC::System::Simple qw(capturex systemx);
@@ -27,53 +28,45 @@ local $ENV{XDG_CONFIG_HOME} = '/nonexistent';
local $ENV{XDG_CONFIG_DIRS} = '/nonexistent';
# Find the full path to the test data.
-my $cwd = getcwd() or die "$0: cannot get working directory: $!\n";
+my $cwd = getcwd() or die "$0: cannot get working directory: $!\n";
my $dataroot = File::Spec->catfile($cwd, 't', 'data', 'dist', 'package');
my $gpg_path = File::Spec->catfile($cwd, 't', 'data', 'dist', 'fake-gpg');
# Set up a temporary directory.
-my $dir = File::Temp->newdir();
+my $dir = File::Temp->newdir();
my $sourcedir = File::Spec->catfile($dir, 'source');
-my $distdir = File::Spec->catfile($dir, 'dist');
+my $distdir = File::Spec->catfile($dir, 'dist');
-# Check whether git is available and can be used to initialize a repository.
-eval {
- systemx(
- 'git', 'init', '-b', 'master', '-q',
- File::Spec->catfile($dir, 'source'),
- );
-};
-if ($@) {
- plan skip_all => 'git init failed (possibly no git binary)';
-}
-
-# Copy all files from the data directory, and commit them. We have to rename
-# the test while we copy it to avoid having it picked up by the main package
-# test suite.
+# Create a new repository, copy all files from the data directory, and commit
+# them. We have to rename the test while we copy it to avoid having it picked
+# up by the main package test suite.
dircopy($dataroot, $sourcedir)
or die "$0: cannot copy $dataroot to $sourcedir: $!\n";
my $testpath = File::Spec->catfile($sourcedir, 't', 'api', 'empty.t');
rename($testpath . '.in', $testpath);
-chdir($sourcedir);
-systemx(qw(git config --add user.name Test));
-systemx(qw(git config --add user.email test@example.com));
-systemx(qw(git add -A .));
-systemx(qw(git commit -q -m Initial));
+Git::Repository->run('init', { cwd => $sourcedir, quiet => 1 });
+my $repo = Git::Repository->new(work_tree => $sourcedir);
+$repo->run(config => '--add', 'user.name', 'Test');
+$repo->run(config => '--add', 'user.email', 'test@example.com');
+$repo->run(add => '-A', q{.});
+$repo->run(commit => '-q', '-m', 'Initial commit');
# Check whether we have all the necessary tools to run the test.
-my $out;
-my $result
- = eval { run(['git', 'archive', 'HEAD'], q{|}, ['tar', 'tf', q{-}], \$out) };
+my $result;
+eval {
+ my $archive = $repo->command(archive => 'HEAD');
+ my $out;
+ $result = run([qw(tar tf -)], '<', $archive->stdout, '>', \$out);
+ $archive->close();
+ $result &&= $archive->exit == 0;
+};
if ($@ || !$result) {
- chdir($cwd);
plan skip_all => 'git and tar not available';
} else {
plan tests => 20;
}
-# Load the module. Change back to the starting directory for this so that
-# coverage analysis works.
-chdir($cwd);
+# Load the module now that we're sure we can run tests.
require_ok('App::DocKnot::Dist');
# Put some existing files in the directory that are marked read-only. These
@@ -90,9 +83,9 @@ my $dist = App::DocKnot::Dist->new({ distdir => $distdir, perl => $^X });
capture_stdout {
eval { $dist->make_distribution() };
};
-ok(-e File::Spec->catfile($distdir, 'Empty-1.00.tar.gz'), 'dist exists');
-ok(-e File::Spec->catfile($distdir, 'Empty-1.00.tar.xz'), 'xz dist exists');
-ok(!-e File::Spec->catfile($distdir, 'Empty-1.00.tar'), 'tarball missing');
+ok(-e File::Spec->catfile($distdir, 'Empty-1.00.tar.gz'), 'dist exists');
+ok(-e File::Spec->catfile($distdir, 'Empty-1.00.tar.xz'), 'xz dist exists');
+ok(!-e File::Spec->catfile($distdir, 'Empty-1.00.tar'), 'tarball missing');
ok(!-e File::Spec->catfile($distdir, 'Empty-1.00.tar.gz.asc'), 'no signature');
ok(!-e File::Spec->catfile($distdir, 'Empty-1.00.tar.xz.asc'), 'no signature');
is($@, q{}, 'no errors');
@@ -152,7 +145,7 @@ $stdout = capture_stdout {
eval { $dist->make_distribution() };
};
is($@, "2 files missing from distribution\n", 'correct error for two files');
-like($stdout, qr{ some-file }xms, 'output mentions the first file');
+like($stdout, qr{ some-file }xms, 'output mentions the first file');
like($stdout, qr{ another-file }xms, 'output mentions the other file');
@missing = $dist->check_dist($sourcedir, $tarball);
is_deeply(['another-file', 'some-file'], \@missing, 'check_dist matches');