summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorRuss Allbery <rra@cpan.org>2022-01-17 11:34:54 -0800
committerRuss Allbery <rra@cpan.org>2022-01-17 11:34:54 -0800
commit0e24930c21fe8374b8d4de5a3a349eaa4314532e (patch)
tree6b2a3c43287d8467eeeb614ddda0b54bb510f410 /t
parent62545b34acf312156563df17a8001b4e9975eff0 (diff)
Finish the Path::Tiny conversion
Convert the test suite to Path::Tiny and convert Test::DocKnot::Spin to Path::Iterator::Rule. Document that various module APIs now take Path::Tiny objects instead of paths, and bump the version for the backward compatibility break.
Diffstat (limited to 't')
-rwxr-xr-xt/cli/generate.t44
-rwxr-xr-xt/cli/spin.t57
-rwxr-xr-xt/config/basic.t9
-rwxr-xr-xt/data/regenerate-data39
-rw-r--r--t/data/spin/output/software/docknot/api/app-docknot.html6
-rwxr-xr-xt/dist/commands.t37
-rwxr-xr-xt/generate/basic.t16
-rwxr-xr-xt/generate/output.t40
-rwxr-xr-xt/generate/self.t8
-rw-r--r--t/lib/Test/DocKnot/Spin.pm91
-rwxr-xr-xt/spin/errors.t7
-rwxr-xr-xt/spin/file.t26
-rwxr-xr-xt/spin/markdown.t23
-rwxr-xr-xt/spin/thread.t30
-rwxr-xr-xt/spin/tree.t94
-rwxr-xr-xt/spin/versions.t34
-rwxr-xr-xt/update/basic.t27
17 files changed, 241 insertions, 347 deletions
diff --git a/t/cli/generate.t b/t/cli/generate.t
index 87c8f68..f3d37f3 100755
--- a/t/cli/generate.t
+++ b/t/cli/generate.t
@@ -2,7 +2,7 @@
#
# Tests for the App::DocKnot command dispatch for generate.
#
-# Copyright 2018-2021 Russ Allbery <rra@cpan.org>
+# Copyright 2018-2022 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT
@@ -13,9 +13,7 @@ use warnings;
use lib 't/lib';
use Cwd qw(getcwd);
-use File::Temp;
-use File::Spec;
-use Perl6::Slurp;
+use Path::Tiny qw(path);
use Test::RRA qw(is_file_contents);
use Test::More tests => 7;
@@ -32,48 +30,46 @@ my $docknot = App::DocKnot::Command->new();
isa_ok($docknot, 'App::DocKnot::Command');
# Create a temporary directory for test output.
-my $tempdir = File::Temp->newdir();
+my $tempdir = Path::Tiny->tempdir();
# Generate the package README file to a temporary file, read it into memory,
# and compare it to the actual README file. This duplicates part of the
# generate/self.t test, but via the command-line parser. Do this in a
# separate block so that $tempfile goes out of scope and will be cleaned up.
{
- my $tempfile = File::Temp->new(DIR => $tempdir);
- my $output_path = $tempfile->filename;
- $docknot->run('generate', 'readme', $output_path);
- my $output = slurp($output_path);
+ my $tempfile = $tempdir->tempfile();
+ $docknot->run('generate', 'readme', "$tempfile");
+ my $output = $tempfile->slurp_utf8();
is_file_contents($output, 'README', 'Generated README from argument list');
}
# Do the same thing again, but using arguments from @ARGV.
{
- my $tempfile = File::Temp->new(DIR => $tempdir);
- my $output_path = $tempfile->filename;
- local @ARGV = ('generate', 'readme-md', "$output_path");
+ my $tempfile = $tempdir->tempfile();
+ local @ARGV = ('generate', 'readme-md', "$tempfile");
$docknot->run();
- my $output = slurp($output_path);
+ my $output = $tempfile->slurp_utf8();
is_file_contents($output, 'README.md', 'Generated README.md from ARGV');
}
# Save the paths to various files in the source directory.
-my $readme_path = File::Spec->catfile(getcwd(), 'README');
-my $readme_md_path = File::Spec->catfile(getcwd(), 'README.md');
-my $metadata_path = File::Spec->catfile(getcwd(), 'docs', 'docknot.yaml');
+my $readme_path = path('README')->realpath();
+my $readme_md_path = path('README.md')->realpath();
+my $metadata_path = path('docs', 'docknot.yaml')->realpath();
# Generate all of the files using generate-all in a new temporary directory.
-my $tmpdir = File::Temp->newdir();
-chdir($tmpdir);
-$docknot->run('generate-all', '-m', $metadata_path);
-my $output = slurp('README');
+my $cwd = getcwd();
+chdir($tempdir);
+$docknot->run('generate-all', '-m', "$metadata_path");
+my $output = path('README')->slurp_utf8();
is_file_contents($output, $readme_path, 'README from generate_all');
-$output = slurp('README.md');
+$output = path('README.md')->slurp_utf8();
is_file_contents($output, $readme_md_path, 'README.md from generate_all');
# Ensure that generate works with a default argument.
-$docknot->run('generate', '-m', $metadata_path, 'readme');
-$output = slurp('README');
+$docknot->run('generate', '-m', "$metadata_path", 'readme');
+$output = path('README')->slurp_utf8();
is_file_contents($output, $readme_path, 'README from generate default args');
# Allow cleanup to delete our temporary directory.
-chdir(File::Spec->rootdir());
+chdir($cwd);
diff --git a/t/cli/spin.t b/t/cli/spin.t
index 37fc269..c1ba392 100755
--- a/t/cli/spin.t
+++ b/t/cli/spin.t
@@ -13,12 +13,9 @@ use warnings;
use lib 't/lib';
use Capture::Tiny qw(capture capture_stdout);
-use Cwd qw(getcwd realpath);
use File::Copy::Recursive qw(dircopy);
-use File::Spec ();
-use File::Temp ();
+use Path::Tiny qw(path);
use POSIX qw(LC_ALL setlocale);
-use Test::RRA qw(is_file_contents);
use Test::DocKnot::Spin qw(is_spin_output is_spin_output_tree);
use Test::More;
@@ -39,60 +36,50 @@ my $docknot = App::DocKnot::Command->new();
isa_ok($docknot, 'App::DocKnot::Command');
# Create a temporary directory for test output.
-my $tempdir = File::Temp->newdir();
+my $tempdir = Path::Tiny->tempdir();
# Spin a single file.
-my $datadir = File::Spec->catfile('t', 'data', 'spin');
-my $input = File::Spec->catfile($datadir, 'input', 'index.th');
-my $expected = File::Spec->catfile($datadir, 'output', 'index.html');
-my $output = File::Spec->catfile($tempdir->dirname, 'index.html');
-$docknot->run('spin-thread', '-s', '/~eagle/styles', $input, $output);
+my $datadir = path('t', 'data', 'spin');
+my $input = $datadir->child('input', 'index.th');
+my $expected = $datadir->child('output', 'index.html');
+my $output = $tempdir->child('index.html');
+$docknot->run('spin-thread', '-s', '/~eagle/styles', "$input", "$output");
is_spin_output($output, $expected, 'spin-thread (output specified)');
# Spin a single file to standard output.
my $stdout = capture_stdout {
- $docknot->run('spin-thread', '-s', '/~eagle/styles', $input);
+ $docknot->run('spin-thread', '-s', '/~eagle/styles', "$input");
};
-open(my $output_fh, '>', $output);
-print {$output_fh} $stdout or BAIL_OUT("Cannot write to $output: $!");
-close($output_fh);
+$output->spew($stdout);
is_spin_output($output, $expected, 'spin-thread (standard output)');
# Copy the input tree to a new temporary directory since .rss files generate
# additional thread files. Replace the .spin pointer since it points to a
# relative path in the source tree.
-my $indir = File::Temp->newdir();
-$input = File::Spec->catfile($datadir, 'input');
-dircopy($input, $indir->dirname)
+my $indir = Path::Tiny->tempdir();
+$input = $datadir->child('input');
+dircopy($input, $indir)
or die "Cannot copy $input to $indir: $!\n";
-my $pod_source = File::Spec->catfile(getcwd(), 'lib', 'App', 'DocKnot.pm');
-my $pointer_path = File::Spec->catfile(
- $indir->dirname, 'software', 'docknot', 'api',
- 'app-docknot.spin',
+my $pod_source = path('lib', 'App', 'DocKnot.pm')->realpath();
+my $pointer_path = $indir->child(
+ 'software', 'docknot', 'api', 'app-docknot.spin',
);
-chmod(0644, $pointer_path);
-open(my $fh, '>', $pointer_path);
-print_fh($fh, $pointer_path, "format: pod\n");
-print_fh($fh, $pointer_path, "path: $pod_source\n");
-close($fh);
+$pointer_path->chmod(0644);
+$pointer_path->spew_utf8("format: pod\n", "path: $pod_source\n");
# Spin a tree of files.
-my $cwd = getcwd();
-$expected = File::Spec->catfile($datadir, 'output');
+$expected = $datadir->child('output');
capture_stdout {
- $docknot->run(
- 'spin', '-s', '/~eagle/styles', $indir->dirname,
- $tempdir->dirname,
- );
+ $docknot->run('spin', '-s', '/~eagle/styles', "$indir", "$tempdir");
};
-my $count = is_spin_output_tree($tempdir->dirname, $expected, 'spin');
+my $count = is_spin_output_tree($tempdir, $expected, 'spin');
# Spin a file with warnings. The specific warnings are checked in
# t/spin/errors.t; here, we just check the rewrite of the warning.
-my $errors = realpath(File::Spec->catfile($datadir, 'errors', 'errors.th'));
+my $errors = $datadir->child('errors', 'errors.th')->realpath();
my $stderr;
($stdout, $stderr) = capture {
- $docknot->run('spin-thread', $errors);
+ $docknot->run('spin-thread', "$errors");
};
like(
$stderr, qr{ \A \Q$0\E [ ] spin-thread : \Q$errors\E : 1 : }xms,
diff --git a/t/config/basic.t b/t/config/basic.t
index 87cd0c5..9c94325 100755
--- a/t/config/basic.t
+++ b/t/config/basic.t
@@ -2,7 +2,7 @@
#
# Tests for the App::DocKnot::Config module API.
#
-# Copyright 2019-2021 Russ Allbery <rra@cpan.org>
+# Copyright 2019-2022 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT
@@ -11,7 +11,7 @@ use autodie;
use warnings;
use File::ShareDir qw(module_file);
-use File::Spec;
+use Path::Tiny qw(path);
use YAML::XS ();
use Test::More tests => 5;
@@ -24,11 +24,10 @@ local $ENV{XDG_CONFIG_DIRS} = '/nonexistent';
BEGIN { use_ok('App::DocKnot::Config') }
# Root of the test data.
-my $dataroot = File::Spec->catfile('t', 'data', 'generate');
+my $dataroot = path('t', 'data', 'generate');
# Load a test configuration and check a few inobvious pieces of it.
-my $metadata_path
- = File::Spec->catfile($dataroot, 'ansicolor', 'docknot.yaml');
+my $metadata_path = $dataroot->child('ansicolor', 'docknot.yaml');
my $config = App::DocKnot::Config->new({ metadata => $metadata_path });
isa_ok($config, 'App::DocKnot::Config');
my $data_ref = $config->config();
diff --git a/t/data/regenerate-data b/t/data/regenerate-data
index 87ee82d..f796f8f 100755
--- a/t/data/regenerate-data
+++ b/t/data/regenerate-data
@@ -7,56 +7,51 @@
# output data using the local instance of App::DocKnot. It should be run from
# the root of the DocKnot distribution directory.
#
+# Copyright 2018-2022 Russ Allbery <rra@cpan.org>
+#
# SPDX-License-Identifier: MIT
use 5.018;
use autodie;
use warnings;
-use File::Spec;
-
use lib 'blib/lib';
use App::DocKnot;
use App::DocKnot::Generate;
use App::DocKnot::Spin;
+use Path::Tiny qw(path);
use Pod::Thread;
# For each subdirectory of t/data/generate, regenerate each file in the output
# subdirectory using the metadata subdirectory and the template matching the
# output name. Special-case the docknot subdirectory, which uses DocKnot's
# own metadata.
-my $data = File::Spec->catdir('t', 'data', 'generate');
-opendir(my $datadir, $data);
-my @packages = grep { -d File::Spec->catdir($data, $_) }
- File::Spec->no_upwards(readdir($datadir));
-closedir($datadir);
+my $data = path('t', 'data', 'generate');
+my @packages = map { $_->basename() } grep { $_->is_dir() } $data->children();
for my $package (@packages) {
my $metadata;
if ($package eq 'docknot') {
- $metadata = File::Spec->catdir('docs', 'docknot.yaml');
+ $metadata = path('docs', 'docknot.yaml');
} else {
- $metadata = File::Spec->catdir($data, $package, 'docknot.yaml');
+ $metadata = $data->child($package, 'docknot.yaml');
}
- my $output = File::Spec->catdir($data, $package, 'output');
- opendir(my $outputdir, $output);
- for my $template (File::Spec->no_upwards(readdir($outputdir))) {
+ my $output = $data->child($package, 'output');
+ for my $template (map { $_->basename() } $output->children()) {
my $docknot = App::DocKnot::Generate->new({ metadata => $metadata });
- my $outpath = File::Spec->catdir($output, $template);
- $docknot->generate_output($template, $outpath);
+ $docknot->generate_output($template, $output->child($template));
}
- closedir($outputdir);
}
# The test of spinning a tree of files uses a reference to App::DocKnot's own
# POD documentation. Regenerate the expected output in case the POD has
# changed.
-my $source = File::Spec->catdir('lib', 'App', 'DocKnot.pm');
+my $source = path('lib', 'App', 'DocKnot.pm');
my $podthread = Pod::Thread->new(navbar => 1);
my $spin = App::DocKnot::Spin::Thread->new();
my $thread;
$podthread->output_string(\$thread);
-$podthread->parse_file($source);
+$podthread->parse_file("$source");
my $html = $spin->spin_thread($thread);
# Add the additional metadata that should be added by spin.
@@ -91,10 +86,8 @@ $html =~ s{ (<body> \n) }{$1$navbar}xms;
$html =~ s{ (</body>) }{$navbar\n$address$1}xms;
# Replace the expected data file.
-my $output = File::Spec->catdir(
- 't', 'data', 'spin', 'output', 'software', 'docknot',
- 'api', 'app-docknot.html',
+my $output = path(
+ 't', 'data', 'spin', 'output', 'software', 'docknot', 'api',
+ 'app-docknot.html',
);
-open(my $fh, '>', $output);
-print {$fh} $html or die "Cannot write to $output: $!\n";
-close($fh);
+$output->spew_utf8($html);
diff --git a/t/data/spin/output/software/docknot/api/app-docknot.html b/t/data/spin/output/software/docknot/api/app-docknot.html
index 85f242f..a64d7c3 100644
--- a/t/data/spin/output/software/docknot/api/app-docknot.html
+++ b/t/data/spin/output/software/docknot/api/app-docknot.html
@@ -44,8 +44,8 @@
<h2 id="S1"><a name="S1">REQUIREMENTS</a></h2>
<p>
-Perl 5.24 or later and the modules File::BaseDir, File::ShareDir, Kwalify, and
-YAML::XS, all of which are available from CPAN.
+Perl 5.24 or later and the modules File::BaseDir, File::ShareDir, Kwalify,
+Path::Tiny, and YAML::XS, all of which are available from CPAN.
</p>
<h2 id="S2"><a name="S2">DESCRIPTION</a></h2>
@@ -95,7 +95,7 @@ Russ Allbery &lt;rra@cpan.org&gt;
<h2 id="S5"><a name="S5">COPYRIGHT AND LICENSE</a></h2>
<p>
-Copyright 2013-2021 Russ Allbery &lt;rra@cpan.org&gt;
+Copyright 2013-2022 Russ Allbery &lt;rra@cpan.org&gt;
</p>
<p>
diff --git a/t/dist/commands.t b/t/dist/commands.t
index 9ca697c..a2a0597 100755
--- a/t/dist/commands.t
+++ b/t/dist/commands.t
@@ -2,7 +2,7 @@
#
# Tests for App::DocKnot::Dist command selection to generate a distribution.
#
-# Copyright 2019-2021 Russ Allbery <rra@cpan.org>
+# Copyright 2019-2022 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT
@@ -10,7 +10,7 @@ use 5.024;
use autodie;
use warnings;
-use File::Spec;
+use Path::Tiny qw(path);
use Test::More tests => 7;
@@ -23,7 +23,7 @@ BEGIN { use_ok('App::DocKnot::Dist') }
# Use the same test cases that we use for generate, since they represent the
# same variety of build systems.
-my $dataroot = File::Spec->catfile('t', 'data', 'generate');
+my $dataroot = path('t', 'data', 'generate');
# Module::Build distribution (use App::DocKnot itself and default paths).
my $docknot = App::DocKnot::Dist->new({ distdir => q{.} });
@@ -50,10 +50,10 @@ $docknot = App::DocKnot::Dist->new({ distdir => q{.}, perl => '/a/perl' });
is_deeply(\@seen, \@expected, 'Module::Build');
# ExtUtils::MakeMaker distribution.
-my $metadata_path
- = File::Spec->catfile($dataroot, 'ansicolor', 'docknot.yaml');
-$docknot
- = App::DocKnot::Dist->new({ distdir => q{.}, metadata => $metadata_path });
+my $metadata_path = $dataroot->child('ansicolor', 'docknot.yaml');
+$docknot = App::DocKnot::Dist->new(
+ { distdir => q{.}, metadata => "$metadata_path" },
+);
#<<<
@expected = (
['perl', 'Makefile.PL'],
@@ -65,9 +65,10 @@ $docknot
is_deeply(\@seen, \@expected, 'ExtUtils::MakeMaker');
# Autoconf distribution.
-$metadata_path = File::Spec->catfile($dataroot, 'lbcd', 'docknot.yaml');
-$docknot
- = App::DocKnot::Dist->new({ distdir => q{.}, metadata => $metadata_path });
+$metadata_path = $dataroot->child('lbcd', 'docknot.yaml');
+$docknot = App::DocKnot::Dist->new(
+ { distdir => q{.}, metadata => "$metadata_path" },
+);
#<<<
@expected = (
['./bootstrap'],
@@ -87,10 +88,10 @@ $docknot
is_deeply(\@seen, \@expected, 'Autoconf');
# Autoconf distribution with C++ and valgrind.
-$metadata_path
- = File::Spec->catfile($dataroot, 'c-tap-harness', 'docknot.yaml');
-$docknot
- = App::DocKnot::Dist->new({ distdir => q{.}, metadata => $metadata_path });
+$metadata_path = $dataroot->child('c-tap-harness', 'docknot.yaml');
+$docknot = App::DocKnot::Dist->new(
+ { distdir => q{.}, metadata => "$metadata_path" },
+);
#<<<
@expected = (
['./bootstrap'],
@@ -114,10 +115,10 @@ $docknot
is_deeply(\@seen, \@expected, 'Autoconf with C++');
# Makefile only distribution (make).
-$metadata_path
- = File::Spec->catfile($dataroot, 'control-archive', 'docknot.yaml');
-$docknot
- = App::DocKnot::Dist->new({ distdir => q{.}, metadata => $metadata_path });
+$metadata_path = $dataroot->child('control-archive', 'docknot.yaml');
+$docknot = App::DocKnot::Dist->new(
+ { distdir => q{.}, metadata => "$metadata_path" },
+);
@expected = (['make', 'dist']);
@seen = $docknot->commands();
is_deeply(\@seen, \@expected, 'make');
diff --git a/t/generate/basic.t b/t/generate/basic.t
index 20af8b0..ca5762b 100755
--- a/t/generate/basic.t
+++ b/t/generate/basic.t
@@ -2,7 +2,7 @@
#
# Tests for the App::DocKnot::Generate module API.
#
-# Copyright 2013, 2016-2021 Russ Allbery <rra@cpan.org>
+# Copyright 2013, 2016-2022 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT
@@ -13,7 +13,7 @@ use warnings;
use lib 't/lib';
use Encode qw(encode);
-use File::Spec;
+use Path::Tiny qw(path);
use Test::RRA qw(is_file_contents);
use Test::More;
@@ -27,24 +27,22 @@ BEGIN { use_ok('App::DocKnot::Generate') }
# We have a set of test cases in the data directory. Each of them contains
# metadata and output directories.
-my $dataroot = File::Spec->catfile('t', 'data', 'generate');
-opendir(my $tests, $dataroot);
-my @tests = File::Spec->no_upwards(readdir($tests));
-closedir($tests);
-@tests = grep { -e File::Spec->catfile($dataroot, $_, 'docknot.yaml') } @tests;
+my $dataroot = path('t', 'data', 'generate');
+my @tests = grep { $_->child('docknot.yaml')->exists() } $dataroot->children();
+@tests = map { $_->basename() } @tests;
# For each of those cases, initialize an object from the metadata directory,
# generate file from known templates, and compare that with the corresponding
# output file.
for my $test (@tests) {
- my $metadata_path = File::Spec->catfile($dataroot, $test, 'docknot.yaml');
+ my $metadata_path = $dataroot->child($test, 'docknot.yaml');
my $docknot = App::DocKnot::Generate->new({ metadata => $metadata_path });
isa_ok($docknot, 'App::DocKnot::Generate', "for $test");
# Loop through the possible templates.
for my $template (qw(readme readme-md thread)) {
my $got = encode('utf-8', $docknot->generate($template));
- my $path = File::Spec->catfile($dataroot, $test, 'output', $template);
+ my $path = $dataroot->child($test, 'output', $template);
is_file_contents($got, $path, "$template for $test");
}
}
diff --git a/t/generate/output.t b/t/generate/output.t
index 2a66451..bb2c272 100755
--- a/t/generate/output.t
+++ b/t/generate/output.t
@@ -3,7 +3,7 @@
# Test the generate_output method. This doubles as a test for whether the
# package metadata is consistent with the files currently in the distribution.
#
-# Copyright 2016, 2018-2021 Russ Allbery <rra@cpan.org>
+# Copyright 2016, 2018-2022 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT
@@ -14,9 +14,7 @@ use warnings;
use lib 't/lib';
use Cwd qw(getcwd);
-use File::Spec;
-use File::Temp;
-use Perl6::Slurp;
+use Path::Tiny qw(path);
use Test::RRA qw(is_file_contents);
use Test::More tests => 7;
@@ -29,39 +27,39 @@ local $ENV{XDG_CONFIG_DIRS} = '/nonexistent';
BEGIN { use_ok('App::DocKnot::Generate') }
# Initialize the App::DocKnot object using the default metadata path.
-my $metadata_path = File::Spec->catfile(getcwd(), 'docs', 'docknot.yaml');
+my $metadata_path = path('docs', 'docknot.yaml')->realpath();
my $docknot = App::DocKnot::Generate->new({ metadata => $metadata_path });
isa_ok($docknot, 'App::DocKnot::Generate');
# Save the paths to the real README and README.md files.
-my $readme_path = File::Spec->catfile(getcwd(), 'README');
-my $readme_md_path = File::Spec->catfile(getcwd(), 'README.md');
+my $readme_path = Path::Tiny->cwd()->child('README');
+my $readme_md_path = Path::Tiny->cwd()->child('README.md');
# Write the README output for the DocKnot package to a temporary file.
-my $tmp = File::Temp->new();
-my $tmpname = $tmp->filename;
-$docknot->generate_output('readme', $tmpname);
-my $output = slurp($tmpname);
+my $tmp = Path::Tiny->tempfile();
+$docknot->generate_output('readme', "$tmp");
+my $output = $tmp->slurp();
is_file_contents($output, 'README', 'README in package');
-$docknot->generate_output('readme-md', $tmpname);
-$output = slurp($tmpname);
+$docknot->generate_output('readme-md', "$tmp");
+$output = $tmp->slurp();
is_file_contents($output, 'README.md', 'README.md in package');
# Test default output destinations by creating a temporary directory and then
# generating the README file without an explicit output location.
-my $tmpdir = File::Temp->newdir();
+my $tmpdir = Path::Tiny->tempdir();
+my $cwd = getcwd();
chdir($tmpdir);
$docknot->generate_output('readme');
-$output = slurp('README');
-is_file_contents($output, $readme_path, 'README using default filename');
+$output = path('README')->slurp();
+is_file_contents($output, "$readme_path", 'README using default filename');
# Use generate_all to generate all the metadata with default output paths.
unlink('README');
$docknot->generate_all();
-$output = slurp('README');
-is_file_contents($output, $readme_path, 'README from generate_all');
-$output = slurp('README.md');
-is_file_contents($output, $readme_md_path, 'README.md from generate_all');
+$output = path('README')->slurp();
+is_file_contents($output, "$readme_path", 'README from generate_all');
+$output = path('README.md')->slurp();
+is_file_contents($output, "$readme_md_path", 'README.md from generate_all');
# Allow cleanup to delete our temporary directory.
-chdir(File::Spec->rootdir());
+chdir($cwd);
diff --git a/t/generate/self.t b/t/generate/self.t
index 49145ff..8e40949 100755
--- a/t/generate/self.t
+++ b/t/generate/self.t
@@ -2,7 +2,7 @@
#
# Test generated files against the files included in the package.
#
-# Copyright 2016, 2018-2019, 2021 Russ Allbery <rra@cpan.org>
+# Copyright 2016, 2018-2019, 2021-2022 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT
@@ -12,7 +12,7 @@ use warnings;
use lib 't/lib';
-use File::Spec;
+use Path::Tiny qw(path);
use Test::RRA qw(is_file_contents);
use Test::More tests => 5;
@@ -34,6 +34,6 @@ is_file_contents($output, 'README', 'README in package');
$output = $docknot->generate('readme-md');
is_file_contents($output, 'README.md', 'README.md in package');
$output = $docknot->generate('thread');
-my $dataroot = File::Spec->catfile('t', 'data', 'generate');
-my $expected = File::Spec->catfile($dataroot, 'docknot', 'output', 'thread');
+my $dataroot = path('t', 'data', 'generate');
+my $expected = $dataroot->child('docknot', 'output', 'thread');
is_file_contents($output, $expected, 'Thread output for package');
diff --git a/t/lib/Test/DocKnot/Spin.pm b/t/lib/Test/DocKnot/Spin.pm
index 2c520a2..8cc461f 100644
--- a/t/lib/Test/DocKnot/Spin.pm
+++ b/t/lib/Test/DocKnot/Spin.pm
@@ -6,17 +6,19 @@
# Modules and declarations
##############################################################################
-package Test::DocKnot::Spin 1.00;
+package Test::DocKnot::Spin 2.00;
use 5.024;
use autodie;
use warnings;
use Cwd qw(getcwd);
+use Encode qw(encode);
use Exporter qw(import);
use File::Compare qw(compare);
use File::Find qw(find);
-use Perl6::Slurp qw(slurp);
+use Path::Iterator::Rule ();
+use Path::Tiny qw(path);
use Test::RRA qw(is_file_contents);
use Test::More;
@@ -36,7 +38,7 @@ our @EXPORT_OK = qw(is_spin_output is_spin_output_tree);
# $message - The descriptive message of the test
sub is_spin_output {
my ($output_file, $expected, $message) = @_;
- my $results = slurp($output_file);
+ my $results = path($output_file)->slurp_utf8();
# Map dates to %DATE% and ignore the different output when the
# modification date is the same as the generation date.
@@ -60,7 +62,7 @@ sub is_spin_output {
$results =~ s{ DocKnot [ ] \d+ [.] \d+ }{DocKnot %VERSION%}xms;
# Check the results against the expected file.
- is_file_contents($results, $expected, $message);
+ is_file_contents(encode('utf-8', $results), $expected, $message);
return;
}
@@ -74,61 +76,38 @@ sub is_spin_output {
# Returns: The number of tests run.
sub is_spin_output_tree {
my ($output, $expected, $message) = @_;
- my $cwd = getcwd();
- my %seen;
- my @missing;
-
- # Function that compares each of the output files in the tree, called from
- # File::Find on the output directory.
- my $check_output = sub {
- my $file = $_;
- if ($file eq '.git') {
- $File::Find::prune = 1;
- return;
- }
- return if -d $file;
-
- # Determine the relative path and mark it as seen.
- my $path = File::Spec->abs2rel($File::Find::name, $output);
- $seen{$path} = 1;
+ my (%seen, @missing);
- # Find the corresponding expected file.
- my $expected_file
- = File::Spec->rel2abs(File::Spec->catfile($expected, $path), $cwd);
+ # Compare each of the output files in the tree.
+ my $rule = Path::Iterator::Rule->new()->skip_dirs('.git')->file();
+ my $iter = $rule->iter("$output", { follow_symlinks => 0 });
+ while (defined(my $file = $iter->())) {
+ my $path = path($file)->relative($output);
+ $seen{"$path"} = 1;
+ my $expected_file = $path->absolute($expected);
# Compare HTML output using is_spin_output and all other files as
# copies.
- if ($file =~ m{ [.] (?: html | rss ) \z }xms) {
+ if ($path->basename() =~ m{ [.] (?: html | rss ) \z }xms) {
is_spin_output($file, $expected_file, "$message ($path)");
} else {
is(compare($file, $expected_file), 0, "$message ($path)");
}
- return;
- };
-
- # Function that checks that every file in the expected output tree was
- # seen in the generated output tree, called from File::Find on the
- # expected directory.
- my $check_files = sub {
- my $file = $_;
- return if -d $file;
-
- # Determine the relative path and make sure it was in the %seen hash.
- my $path = File::Spec->abs2rel($File::Find::name, $expected);
- if ($seen{$path}) {
- delete $seen{$path};
+ }
+ my $count = keys(%seen);
+
+ # Check every file in the expected output tree was seen in the generated
+ # output tree.
+ $rule = Path::Iterator::Rule->new()->skip_dirs('.git')->file();
+ $iter = $rule->iter("$expected", { follow_symlinks => 0 });
+ while (defined(my $file = $iter->())) {
+ my $path = path($file)->relative($expected);
+ if ($seen{"$path"}) {
+ delete $seen{"$path"};
} else {
push(@missing, $path);
}
- return;
- };
-
- # Compare the output.
- find($check_output, $output);
- my $count = keys(%seen);
-
- # Check that there aren't any missing files.
- find($check_files, $expected);
+ }
is_deeply(\@missing, [], 'All expected files generated');
# Return the count of tests.
@@ -143,7 +122,7 @@ sub is_spin_output_tree {
__END__
=for stopwords
-Allbery Allbery sublicense MERCHANTABILITY NONINFRINGEMENT DocKnot
+Allbery Allbery sublicense MERCHANTABILITY NONINFRINGEMENT DocKnot RSS
=head1 NAME
@@ -176,16 +155,18 @@ should be explicitly imported.
=item is_spin_output(OUTPUT, EXPECTED, MESSAGE)
-Given OUTPUT, which should be the path to a file generated by
+Given OUTPUT, which should be a Path::Tiny object pointing to the output from
App::DocKnot::Spin, compare it to the expected output in the file named
-EXPECTED. MESSAGE is the message to print with the test results for easy
-identification.
+EXPECTED (also a Path::Tiny object). MESSAGE is the message to print with the
+test results for easy identification.
=item is_spin_output_tree(OUTPUT, EXPECTED, MESSAGE)
-Compare the output tree at OUTPUT with the expected output tree at EXPECTED,
-using the same comparison algorithm as is_spin_output(). MESSAGE with the
-message to print with the test results for easy identification.
+Compare the output tree at OUTPUT with the expected output tree at EXPECTED
+(both Path::Tiny objects), using the same comparison algorithm as
+is_spin_output() for HTML and RSS files and a straight content comparison for
+all other files. MESSAGE with the message to print with the test results for
+easy identification.
=back
diff --git a/t/spin/errors.t b/t/spin/errors.t
index c6e1ce6..c35669b 100755
--- a/t/spin/errors.t
+++ b/t/spin/errors.t
@@ -2,7 +2,7 @@
#
# Test errors generated by App::DocKnot::Spin::Thread.
#
-# Copyright 2021 Russ Allbery <rra@cpan.org>
+# Copyright 2021-2022 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT
@@ -11,8 +11,7 @@ use autodie;
use warnings;
use Capture::Tiny qw(capture);
-use File::Spec;
-use File::Temp;
+use Path::Tiny qw(path);
use Test::More tests => 2;
@@ -35,7 +34,7 @@ ERRORS
require_ok('App::DocKnot::Spin::Thread');
# Spin the errors file with output captured.
-my $input = File::Spec->catfile('t', 'data', 'spin', 'errors', 'errors.th');
+my $input = path('t', 'data', 'spin', 'errors', 'errors.th');
my $spin = App::DocKnot::Spin::Thread->new();
my ($stdout, $stderr) = capture {
$spin->spin_thread_file($input);
diff --git a/t/spin/file.t b/t/spin/file.t
index 2f645e5..260b03e 100755
--- a/t/spin/file.t
+++ b/t/spin/file.t
@@ -2,7 +2,7 @@
#
# Test running spin on a single file.
#
-# Copyright 2021 Russ Allbery <rra@cpan.org>
+# Copyright 2021-2022 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT
@@ -13,11 +13,8 @@ use warnings;
use lib 't/lib';
use Capture::Tiny qw(capture_stdout);
-use Cwd qw(getcwd);
use Fcntl qw(SEEK_SET);
-use File::Spec;
-use File::Temp;
-use Perl6::Slurp qw(slurp);
+use Path::Tiny qw(path);
use Test::DocKnot::Spin qw(is_spin_output);
use Test::More tests => 3;
@@ -25,22 +22,19 @@ use Test::More tests => 3;
require_ok('App::DocKnot::Spin::Thread');
# Spin a single file.
-my $tempfile = File::Temp->new();
-my $datadir = File::Spec->catfile('t', 'data', 'spin');
-my $inputdir = File::Spec->catfile($datadir, 'input');
-my $input = File::Spec->catfile($inputdir, 'index.th');
-my $expected = File::Spec->catfile($datadir, 'output', 'index.html');
+my $tempfile = Path::Tiny->tempfile();
+my $datadir = path('t', 'data', 'spin');
+my $inputdir = $datadir->child('input');
+my $input = $inputdir->child('index.th');
+my $expected = $datadir->child('output', 'index.html');
my $spin
= App::DocKnot::Spin::Thread->new({ 'style-url' => '/~eagle/styles/' });
-$spin->spin_thread_file($input, $tempfile->filename);
+$spin->spin_thread_file($input, $tempfile);
is_spin_output($tempfile, $expected, 'spin_thread_file with output path');
# The same but spin to standard output.
my $html = capture_stdout {
$spin->spin_thread_file($input);
};
-$tempfile->seek(0, SEEK_SET);
-$tempfile->truncate(0);
-print {$tempfile} $html or die "Cannot write to $tempfile: $!\n";
-$tempfile->flush();
-is_spin_output($tempfile->filename, $expected, 'spin_thread_file to stdout');
+$tempfile->spew($html);
+is_spin_output($tempfile, $expected, 'spin_thread_file to stdout');
diff --git a/t/spin/markdown.t b/t/spin/markdown.t
index ea17401..7b36e9f 100755
--- a/t/spin/markdown.t
+++ b/t/spin/markdown.t
@@ -14,10 +14,8 @@ use lib 't/lib';
use Capture::Tiny qw(capture_stdout);
use Carp qw(croak);
-use Cwd qw(getcwd);
-use File::Copy::Recursive qw(dircopy);
-use File::Temp ();
use IPC::Cmd qw(can_run);
+use Path::Tiny qw(path);
use Test::DocKnot::Spin qw(is_spin_output_tree);
use Template ();
@@ -35,22 +33,13 @@ local $ENV{XDG_CONFIG_DIRS} = '/nonexistent';
require_ok('App::DocKnot::Spin');
require_ok('App::DocKnot::Spin::Pointer');
-# Ensure Devel::Cover has loaded the HTML template before we start changing
-# the working directory with File::Find. (This is a dumb workaround, but I
-# can't find a better one; +ignore doesn't work.)
-my $pointer = App::DocKnot::Spin::Pointer->new();
-my $template = $pointer->appdata_path('templates', 'html.tmpl');
-my $tt = Template->new({ ABSOLUTE => 1, ENCODING => 'utf8' })
- or croak(Template->error());
-$tt->process($template, {}, \my $result);
-
# Spin the tree of files and check the result.
-my $datadir = File::Spec->catfile('t', 'data', 'spin', 'markdown');
-my $input = File::Spec->catfile($datadir, 'input');
-my $output = File::Temp->newdir();
-my $expected = File::Spec->catfile($datadir, 'output');
+my $datadir = path('t', 'data', 'spin', 'markdown');
+my $input = $datadir->child('input');
+my $output = Path::Tiny->tempdir();
+my $expected = $datadir->child('output');
my $spin = App::DocKnot::Spin->new({ 'style-url' => '/~eagle/styles/' });
-my $stdout = capture_stdout { $spin->spin($input, $output->dirname) };
+my $stdout = capture_stdout { $spin->spin($input, $output) };
my $count = is_spin_output_tree($output, $expected, 'spin');
# Report the end of testing.
diff --git a/t/spin/thread.t b/t/spin/thread.t
index c18a743..edacbe5 100755
--- a/t/spin/thread.t
+++ b/t/spin/thread.t
@@ -2,7 +2,7 @@
#
# Test running spin on a scalar containing thread source.
#
-# Copyright 2021 Russ Allbery <rra@cpan.org>
+# Copyright 2021-2022 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT
@@ -13,9 +13,7 @@ use warnings;
use lib 't/lib';
use Cwd qw(getcwd);
-use File::Spec;
-use File::Temp;
-use Perl6::Slurp qw(slurp);
+use Path::Tiny qw(path);
use Test::DocKnot::Spin qw(is_spin_output);
use Test::More tests => 2;
@@ -23,31 +21,29 @@ use Test::More tests => 2;
require_ok('App::DocKnot::Spin::Thread');
# Test data file paths.
-my $datadir = File::Spec->catfile('t', 'data', 'spin');
-my $inputdir = File::Spec->catfile($datadir, 'input');
-my $input = File::Spec->catfile($inputdir, 'index.th');
-my $expected = File::Spec->catfile($datadir, 'output', 'index.html');
+my $datadir = path('t', 'data', 'spin');
+my $inputdir = $datadir->child('input');
+my $input = $inputdir->child('index.th');
+my $expected = $datadir->child('output', 'index.html');
# The expected output is a bit different since we won't add timestamp
# information or the filename to the comment, so we have to generate our
# expected output file.
-my $tempfile = File::Temp->new();
-my $output = slurp($expected);
+my $tempfile = Path::Tiny->tempfile();
+my $output = $expected->slurp_utf8();
$output =~ s{ from [ ] index[.]th [ ] }{}xms;
$output =~ s{ <address> .* </address> \n }{}xms;
-print {$tempfile} $output or die "Cannot write to $tempfile: $!\n";
-$tempfile->flush();
+$tempfile->spew_utf8($output);
# Spin the file using the spin_thread() API, using the right working directory
# to expand \image and the like.
my $spin
= App::DocKnot::Spin::Thread->new({ 'style-url' => '/~eagle/styles/' });
-my $thread = slurp($input);
+my $thread = $input->slurp_utf8();
my $cwd = getcwd();
chdir($inputdir);
my $html = $spin->spin_thread($thread);
chdir($cwd);
-my $outfile = File::Temp->new();
-print {$outfile} $html or die "Cannot write to $outfile: $!\n";
-$outfile->flush();
-is_spin_output($outfile->filename, $tempfile->filename, 'spin_thread');
+my $outfile = Path::Tiny->tempfile();
+$outfile->spew_utf8($html);
+is_spin_output($outfile, $tempfile, 'spin_thread');
diff --git a/t/spin/tree.t b/t/spin/tree.t
index 2376bda..c57c413 100755
--- a/t/spin/tree.t
+++ b/t/spin/tree.t
@@ -13,11 +13,8 @@ use warnings;
use lib 't/lib';
use Capture::Tiny qw(capture_stdout);
-use Cwd qw(getcwd);
use File::Copy::Recursive qw(dircopy);
-use File::Spec ();
-use File::Temp ();
-use Perl6::Slurp qw(slurp);
+use Path::Tiny qw(path);
use POSIX qw(LC_ALL setlocale strftime);
use Test::DocKnot::Spin qw(is_spin_output_tree);
@@ -74,87 +71,72 @@ require_ok('App::DocKnot::Spin');
# additional thread files. Replace the POD pointer since it points to a
# relative path in the source tree, but change its modification timestamp to
# something in the past.
-my $tmpdir = File::Temp->newdir();
-my $datadir = File::Spec->catfile('t', 'data', 'spin');
-my $input = File::Spec->catfile($datadir, 'input');
-dircopy($input, $tmpdir->dirname)
- or die "Cannot copy $input to $tmpdir: $!\n";
-my $pod_source = File::Spec->catfile(getcwd(), 'lib', 'App', 'DocKnot.pm');
-my $pointer_path = File::Spec->catfile(
- $tmpdir->dirname, 'software', 'docknot', 'api',
- 'app-docknot.spin',
+my $tmpdir = Path::Tiny->tempdir();
+my $datadir = path('t', 'data', 'spin');
+my $input = $datadir->child('input');
+dircopy($input, $tmpdir) or die "Cannot copy $input to $tmpdir: $!\n";
+my $pod_source = path('lib', 'App', 'DocKnot.pm')->realpath();
+my $pointer_path = $tmpdir->path(
+ 'software', 'docknot', 'api', 'app-docknot.spin',
);
-chmod(0644, $pointer_path);
-open(my $fh, '>', $pointer_path);
-print_fh($fh, $pointer_path, "format: pod\n");
-print_fh($fh, $pointer_path, "path: $pod_source\n");
-close($fh);
+$pointer_path->spew_utf8("format: pod\n", "path: $pod_source\n");
my $old_timestamp = time() - 10;
# Spin a tree of files.
-my $output = File::Temp->newdir();
-my $expected = File::Spec->catfile($datadir, 'output');
+my $output = Path::Tiny->tempdir();
+my $expected = $datadir->child('output');
my $spin = App::DocKnot::Spin->new({ 'style-url' => '/~eagle/styles/' });
-my $stdout = capture_stdout {
- $spin->spin($tmpdir->dirname, $output->dirname);
-};
+my $stdout = capture_stdout { $spin->spin($tmpdir, $output) };
my $count = is_spin_output_tree($output, $expected, 'spin');
is($stdout, $EXPECTED_OUTPUT, 'Expected spin output');
# Create a bogus file in the output tree.
-my $bogus = File::Spec->catfile($output->dirname, 'bogus');
-my $bogus_file = File::Spec->catfile($bogus, 'some-file');
-mkdir($bogus);
-open($fh, '>', $bogus_file);
-print {$fh} "Some stuff\n" or die "Cannot write to $bogus_file: $!\n";
-close($fh);
+my $bogus = $output->child('bogus');
+$bogus->mkpath();
+$bogus->child('some-file')->spew_utf8("Some stuff\n");
# Spinning the same tree of files again should do nothing because of the
# modification timestamps.
-$stdout = capture_stdout {
- $spin->spin($tmpdir->dirname, $output->dirname);
-};
+$stdout = capture_stdout { $spin->spin($tmpdir, $output) };
is($stdout, q{}, 'Spinning again does nothing');
# The extra file shouldn't be deleted.
-ok(-d $bogus, 'Stray file and directory not deleted');
+ok($bogus->is_dir(), 'Stray file and directory not deleted');
# Reconfigure spin to enable deletion, and run it again. The only action
# taken should be to delete the stray file.
$spin
= App::DocKnot::Spin->new({ delete => 1, 'style-url' => '/~eagle/styles/' });
-$stdout = capture_stdout {
- $spin->spin($tmpdir->dirname, $output->dirname);
-};
+$stdout = capture_stdout { $spin->spin($tmpdir, $output) };
is(
$stdout,
"Deleting .../bogus/some-file\nDeleting .../bogus\n",
'Spinning with delete option cleans up',
);
-ok(!-e $bogus, 'Stray file and directory was deleted');
+ok(!$bogus->exists(), 'Stray file and directory was deleted');
# Override the title of the POD document and request a contents section. Set
# the modification timestamp in the future to force a repsin.
-open($fh, '>>', $pointer_path);
-print_fh($fh, $pointer_path, "format: pod\n");
-print_fh($fh, $pointer_path, "path: $pod_source\n");
-print_fh($fh, $pointer_path, "options:\n contents: true\n navbar: false\n");
-print_fh($fh, $pointer_path, "title: 'New Title'\n");
-close($fh);
+$pointer_path->spew_utf8(
+ "format: pod\n",
+ "path: $pod_source\n",
+ "options:\n",
+ " contents: true\n",
+ " navbar: false\n",
+ "title: 'New Title'\n",
+);
utime(time() + 5, time() + 5, $pointer_path)
or die "Cannot reset timestamps of $pointer_path: $!\n";
-$stdout = capture_stdout {
- $spin->spin($tmpdir->dirname, $output->dirname);
-};
+$stdout = capture_stdout { $spin->spin($tmpdir, $output) };
is(
$stdout,
"Converting .../software/docknot/api/app-docknot.html\n",
'Spinning again regenerates the App::DocKnot page',
);
-my $output_path = File::Spec->catfile(
- $output->dirname, 'software', 'docknot', 'api', 'app-docknot.html',
+my $output_path = $output->child(
+ 'software', 'docknot', 'api', 'app-docknot.html',
);
-my $page = slurp($output_path);
+my $page = $output_path->slurp_utf8();
like(
$page,
qr{ <title> New [ ] Title </title> }xms,
@@ -170,17 +152,13 @@ utime(time() - 5, time() - 5, $pointer_path)
# Now, update the .versions file at the top of the input tree to change the
# timestamp to ten seconds into the future. This should force regeneration of
# only the software/docknot/index.html file.
-my $versions_path = File::Spec->catfile($tmpdir->dirname, '.versions');
-my $versions = slurp($versions_path);
+my $versions_path = $tmpdir->child('.versions');
+my $versions = $versions_path->slurp_utf8();
my $new_date = strftime('%Y-%m-%d %T', localtime(time() + 10));
$versions =~ s{ \d{4}-\d\d-\d\d [ ] [\d:]+ }{$new_date}xms;
-chmod(0644, $versions_path);
-open(my $versions_fh, '>', $versions_path);
-print {$versions_fh} $versions or die "Cannot write to $versions_path: $!\n";
-close($versions_fh);
-$stdout = capture_stdout {
- $spin->spin($tmpdir->dirname, $output->dirname);
-};
+$versions_path->chmod(0644);
+$versions_path->spew_utf8($versions);
+$stdout = capture_stdout { $spin->spin($tmpdir, $output) };
is(
$stdout,
"Spinning .../software/docknot/index.html\n",
diff --git a/t/spin/versions.t b/t/spin/versions.t
index 7f1e62b..ba508bb 100755
--- a/t/spin/versions.t
+++ b/t/spin/versions.t
@@ -2,7 +2,7 @@
#
# Tests for App::DocKnot::Spin::Versions (.versions file handling).
#
-# Copyright 2021 Russ Allbery <rra@cpan.org>
+# Copyright 2021-2022 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT
@@ -12,7 +12,7 @@ use warnings;
use lib 't/lib';
-use File::Spec;
+use Path::Tiny qw(path);
use POSIX qw(tzset);
use Test::More tests => 20;
@@ -26,7 +26,7 @@ local $ENV{TZ} = 'PST8PDT,M3.2.0,M11.1.0';
tzset();
# Parse the file.
-my $path = File::Spec->catfile('t', 'data', 'spin', 'input', '.versions');
+my $path = path('t', 'data', 'spin', 'input', '.versions');
my $versions = App::DocKnot::Spin::Versions->new($path);
isa_ok($versions, 'App::DocKnot::Spin::Versions');
@@ -44,8 +44,8 @@ is($versions->release_date('unknown'), undef, 'unknown release date');
is($versions->latest_release('index.th'), 0, 'unknown file index.th');
# Check continuation handling and a line without dependencies.
-my $inputdir = File::Spec->catfile('t', 'data', 'spin', 'versions');
-$path = File::Spec->catfile($inputdir, 'continuation');
+my $inputdir = path('t', 'data', 'spin', 'versions');
+$path = $inputdir->child('continuation');
$versions = App::DocKnot::Spin::Versions->new($path);
is($versions->version('docknot'), '4.01', 'docknot version');
is($versions->release_date('docknot'), '2021-02-27', 'docknot release date');
@@ -72,26 +72,18 @@ is(
);
# Check error handling.
-eval {
- $path = File::Spec->catfile($inputdir, 'invalid-continuation');
- App::DocKnot::Spin::Versions->new($path);
-};
+$path = $inputdir->child('invalid-continuation');
+eval { App::DocKnot::Spin::Versions->new($path) };
is(
$@, "continuation without previous entry in $path\n",
'invalid continuation',
);
-eval {
- $path = File::Spec->catfile($inputdir, 'invalid-date');
- App::DocKnot::Spin::Versions->new($path);
-};
+$path = $inputdir->child('invalid-date');
+eval { App::DocKnot::Spin::Versions->new($path) };
is($@, qq(invalid date "20-02-27" in $path\n), 'invalid date');
-eval {
- $path = File::Spec->catfile($inputdir, 'invalid-time');
- App::DocKnot::Spin::Versions->new($path);
-};
+$path = $inputdir->child('invalid-time');
+eval { App::DocKnot::Spin::Versions->new($path) };
is($@, qq(invalid time "13:08" in $path\n), 'invalid time');
-eval {
- $path = File::Spec->catfile($inputdir, 'invalid-line');
- App::DocKnot::Spin::Versions->new($path);
-};
+$path = $inputdir->child('invalid-line');
+eval { App::DocKnot::Spin::Versions->new($path) };
is($@, "invalid line 2 in $path\n", 'invalid line');
diff --git a/t/update/basic.t b/t/update/basic.t
index 5dc2be1..30049bf 100755
--- a/t/update/basic.t
+++ b/t/update/basic.t
@@ -2,7 +2,7 @@
#
# Tests for the App::DocKnot::Update module API.
#
-# Copyright 2020-2021 Russ Allbery <rra@cpan.org>
+# Copyright 2020-2022 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT
@@ -12,9 +12,7 @@ use warnings;
use lib 't/lib';
-use File::Temp;
-use File::Spec;
-use Perl6::Slurp qw(slurp);
+use Path::Tiny qw(path);
use Test::RRA qw(is_file_contents);
use Test::More;
@@ -28,27 +26,22 @@ BEGIN { use_ok('App::DocKnot::Update') }
# We have a set of test cases in the data directory. Each of them contains
# an old directory for the old files and a docknot.yaml file for the results.
-my $dataroot = File::Spec->catfile('t', 'data', 'update');
-opendir(my $tests, $dataroot);
-my @tests = File::Spec->no_upwards(readdir($tests));
-closedir($tests);
+my $dataroot = path('t', 'data', 'update');
+my @tests = map { $_->basename() } $dataroot->children();
# For each of those cases, initialize an object, generate the updated
# configuration, and compare it with the test output file.
-my $tempdir = File::Temp->newdir();
+my $tempdir = Path::Tiny->tempdir();
for my $test (@tests) {
- my $metadata_path = File::Spec->catfile($dataroot, $test, 'old');
- my $expected_path = File::Spec->catfile($dataroot, $test, 'docknot.yaml');
- my $output_path = File::Spec->catfile($tempdir, "$test.yaml");
+ my $metadata_path = $dataroot->child($test, 'old');
+ my $expected_path = $dataroot->child($test, 'docknot.yaml');
+ my $output_path = $tempdir->child("$test.yaml");
my $docknot = App::DocKnot::Update->new(
- {
- metadata => $metadata_path,
- output => $output_path,
- },
+ { metadata => $metadata_path, output => $output_path },
);
isa_ok($docknot, 'App::DocKnot::Update', "for $test");
$docknot->update();
- my $got = slurp($output_path);
+ my $got = $output_path->slurp();
is_file_contents($got, $expected_path, "output for $test");
}