From 4aab7cb9631a8abedb5675baef772a65cb3539e8 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Sun, 17 Oct 2021 19:21:17 -0700 Subject: Support distribution from a main branch Support creating distributions from branches named main rather than master. The first of main or master that's found in the repository will be used. Use Git::Repository for creating distributions and testing the distribution code rather than hand-rolling git invocations. --- t/dist/basic.t | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) (limited to 't/dist') diff --git a/t/dist/basic.t b/t/dist/basic.t index 95a6986..f8ca97b 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); @@ -36,44 +37,36 @@ my $dir = File::Temp->newdir(); my $sourcedir = File::Spec->catfile($dir, 'source'); 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 => '-b', 'main', { 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 -- cgit v1.2.3 From 3bc6eae68d8206f232fc9835450e793758a8ea8c Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Sun, 17 Oct 2021 19:29:57 -0700 Subject: Fix tests with git without -b flag Don't require that git support a -b flag when running the dist/basic.t test. --- t/dist/basic.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/dist') diff --git a/t/dist/basic.t b/t/dist/basic.t index f8ca97b..319b5cb 100755 --- a/t/dist/basic.t +++ b/t/dist/basic.t @@ -44,7 +44,7 @@ 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); -Git::Repository->run(init => '-b', 'main', { cwd => $sourcedir, quiet => 1 }); +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'); -- cgit v1.2.3 From 9257e00ec67fb1c0ad07d8d91fb2bfbdd1c14949 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Fri, 24 Dec 2021 19:37:05 -0800 Subject: Reformat code Adopt the new -nvc option in Perl::Tidy 20211029 to disable the intrusive vertical alignment formatting. Unfortunately, this breaks all vertical alignment formatting, even when desired, so work around that in a few places with special comments. --- t/dist/basic.t | 20 ++++++++++---------- t/dist/commands.t | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 't/dist') diff --git a/t/dist/basic.t b/t/dist/basic.t index 319b5cb..6fcf2bc 100755 --- a/t/dist/basic.t +++ b/t/dist/basic.t @@ -28,14 +28,14 @@ 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'); # 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 @@ -46,10 +46,10 @@ my $testpath = File::Spec->catfile($sourcedir, 't', 'api', 'empty.t'); rename($testpath . '.in', $testpath); 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.name', 'Test'); $repo->run(config => '--add', 'user.email', 'test@example.com'); -$repo->run(add => '-A', q{.}); -$repo->run(commit => '-q', '-m', 'Initial commit'); +$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 $result; @@ -83,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'); @@ -145,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'); diff --git a/t/dist/commands.t b/t/dist/commands.t index cbd29c3..9ca697c 100755 --- a/t/dist/commands.t +++ b/t/dist/commands.t @@ -119,5 +119,5 @@ $metadata_path $docknot = App::DocKnot::Dist->new({ distdir => q{.}, metadata => $metadata_path }); @expected = (['make', 'dist']); -@seen = $docknot->commands(); +@seen = $docknot->commands(); is_deeply(\@seen, \@expected, 'make'); -- cgit v1.2.3