summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorRuss Allbery <rra@cpan.org>2022-01-11 20:45:16 -0800
committerRuss Allbery <rra@cpan.org>2022-01-11 20:45:16 -0800
commite7e6c9a95fb4cd68110ecd51a8ea2b5accc17e78 (patch)
tree509eb6dd650ff4664238dfc445abfb4b394b0a00 /t
parent66d9ae6a41b46481882c10474d92b8633a11e279 (diff)
Add docknot release command
Add new docknot release command and corresponding App::DocKnot::Release module to copy a tarball releaes (normally created by docknot dist) into a release area, update symlinks, archive any previous releases, and update the .versions file used by docknot spin. DocKnot now depends on Sort::Versions.
Diffstat (limited to 't')
-rw-r--r--t/data/generate/docknot/output/thread1
-rwxr-xr-xt/release/basic.t116
2 files changed, 117 insertions, 0 deletions
diff --git a/t/data/generate/docknot/output/thread b/t/data/generate/docknot/output/thread
index 2b4371a..30d83e7 100644
--- a/t/data/generate/docknot/output/thread
+++ b/t/data/generate/docknot/output/thread
@@ -121,6 +121,7 @@ The following additional Perl modules are required to use it:
\bullet(packed)[Path::Tiny 0.101 or later]
\bullet(packed)[Perl6::Slurp]
\bullet(packed)[Pod::Thread 3.01 or later]
+\bullet(packed)[Sort::Versions]
\bullet(packed)[Template (part of Template Toolkit)]
\bullet(packed)[YAML::XS 0.81 or later]
diff --git a/t/release/basic.t b/t/release/basic.t
new file mode 100755
index 0000000..4379136
--- /dev/null
+++ b/t/release/basic.t
@@ -0,0 +1,116 @@
+#!/usr/bin/perl
+#
+# Tests for the App::DocKnot::Release module API.
+#
+# Copyright 2022 Russ Allbery <rra@cpan.org>
+#
+# SPDX-License-Identifier: MIT
+
+use 5.024;
+use autodie;
+use warnings;
+
+use lib 't/lib';
+
+use Git::Repository ();
+use Path::Tiny qw(path);
+
+use Test::More tests => 30;
+
+# Isolate from the environment.
+local $ENV{XDG_CONFIG_HOME} = '/nonexistent';
+local $ENV{XDG_CONFIG_DIRS} = '/nonexistent';
+
+# Load the module.
+require_ok('App::DocKnot::Release');
+
+# Construct a working area.
+my $tempdir = Path::Tiny->tempdir();
+my $archive_path = $tempdir->child('archive');
+$archive_path->mkpath();
+my $old_path = $archive_path->child('ARCHIVE');
+my $dist_path = $tempdir->child('dist');
+$dist_path->mkpath();
+
+# Make a release when there are no existing files.
+my @extensions = qw(tar.gz tar.gz.asc tar.xz tar.xz.asc);
+for my $ext (@extensions) {
+ $dist_path->child('Empty-1.9.' . $ext)->touch();
+}
+my $metadata = path('t', 'data', 'dist', 'package', 'docs', 'docknot.yaml');
+my %options = (
+ archivedir => $archive_path,
+ distdir => $dist_path,
+ metadata => $metadata,
+);
+my $release = App::DocKnot::Release->new(\%options);
+$release->release();
+
+# Check that the files were copied correctly and the symlinks were created.
+for my $ext (@extensions) {
+ my $file = 'Empty-1.9.' . $ext;
+ ok($archive_path->child('devel', $file)->is_file(), "Copied $file");
+ my $link = 'Empty.' . $ext;
+ is(readlink($archive_path->child('devel', $link)), $file, "Linked $link");
+}
+
+# Build a Git repository and a .versions file.
+my $spin_path = $tempdir->child('spin');
+$spin_path->mkpath();
+my $versions_path = $spin_path->child('.versions');
+$versions_path->spew_utf8(
+ "empty 1.9 2022-01-01 16:00:00 software/empty/index.th\n",
+);
+Git::Repository->run('init', { cwd => "$spin_path", quiet => 1 });
+my $repo = Git::Repository->new(work_tree => "$spin_path");
+$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');
+
+# Construct a configuration file.
+my $config_path = $tempdir->child('docknot', 'config.yaml');
+$config_path->parent()->mkpath();
+my @config = (
+ "archivedir: $archive_path",
+ "distdir: $dist_path",
+ "versions: $versions_path",
+);
+$config_path->spew_utf8(join("\n", @config), "\n");
+local $ENV{XDG_CONFIG_HOME} = "$tempdir";
+
+# Make another release, now relying on the global configuration. Add some
+# other files to distdir to ensure they're ignored.
+for my $ext (@extensions) {
+ $dist_path->child('Empty-1.10.' . $ext)->touch();
+ $dist_path->child('foo-1.0.' . $ext)->touch();
+}
+$release = App::DocKnot::Release->new({ metadata => $metadata });
+$release->release();
+
+# Check that the files were copied correctly, the symlinks were created, and
+# the old files were moved. Check that the old files were copied to the
+# archive directory.
+for my $ext (@extensions) {
+ my $file = 'Empty-1.10.' . $ext;
+ ok($archive_path->child('devel', $file)->is_file(), "Copied $file");
+ my $old = 'Empty-1.9.' . $ext;
+ ok(!$archive_path->child('devel', $old)->is_file(), "Removed $old");
+ ok(
+ $archive_path->child('ARCHIVE', 'Empty', $old)->is_file(),
+ "Archived $old",
+ );
+ my $link = 'Empty.' . $ext;
+ is(readlink($archive_path->child('devel', $link)), $file, "Updated $link");
+}
+
+# Check that the version file was updated.
+my @versions = split(q{ }, $versions_path->slurp_utf8());
+is($versions[0], 'empty', '.versions line');
+is($versions[1], '1.10', '...version updated');
+isnt(join(q{ }, @versions[2, 3]), '2022-01-01 16:00:00', '...date updated');
+is($versions[4], 'software/empty/index.th', '...dependency unchanged');
+
+# Check that the change was staged.
+my $status = $repo->run('status', '-s');
+is($status, ' M .versions', '.versions change was staged');