diff options
Diffstat (limited to 't/spin')
-rwxr-xr-x | t/spin/errors.t | 2 | ||||
-rwxr-xr-x | t/spin/file.t | 8 | ||||
-rwxr-xr-x | t/spin/markdown.t | 56 | ||||
-rwxr-xr-x | t/spin/sitemap.t | 9 | ||||
-rwxr-xr-x | t/spin/thread.t | 12 | ||||
-rwxr-xr-x | t/spin/tree.t | 65 | ||||
-rwxr-xr-x | t/spin/versions.t | 18 |
7 files changed, 118 insertions, 52 deletions
diff --git a/t/spin/errors.t b/t/spin/errors.t index ae1c308..d4cc565 100755 --- a/t/spin/errors.t +++ b/t/spin/errors.t @@ -36,7 +36,7 @@ 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 $spin = App::DocKnot::Spin::Thread->new(); +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 354ec77..2f645e5 100755 --- a/t/spin/file.t +++ b/t/spin/file.t @@ -26,10 +26,10 @@ 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 $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 $spin = App::DocKnot::Spin::Thread->new({ 'style-url' => '/~eagle/styles/' }); $spin->spin_thread_file($input, $tempfile->filename); diff --git a/t/spin/markdown.t b/t/spin/markdown.t new file mode 100755 index 0000000..bf8de61 --- /dev/null +++ b/t/spin/markdown.t @@ -0,0 +1,56 @@ +#!/usr/bin/perl +# +# Test Markdown conversion. +# +# Copyright 2021 Russ Allbery <rra@cpan.org> +# +# SPDX-License-Identifier: MIT + +use 5.024; +use autodie; +use warnings; + +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 Test::DocKnot::Spin qw(is_spin_output_tree); +use Template (); + +use Test::More; + +# This test can only be run if pandoc is available. +if (!can_run('pandoc')) { + plan(skip_all => 'pandoc required for test'); +} + +# Isolate from the environment. +local $ENV{XDG_CONFIG_HOME} = '/nonexistent'; +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 }) 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 $spin = App::DocKnot::Spin->new({ 'style-url' => '/~eagle/styles/' }); +my $stdout = capture_stdout { $spin->spin($input, $output->dirname) }; +my $count = is_spin_output_tree($output, $expected, 'spin'); + +# Report the end of testing. +done_testing($count + 2); diff --git a/t/spin/sitemap.t b/t/spin/sitemap.t index 1cac856..59f8fe3 100755 --- a/t/spin/sitemap.t +++ b/t/spin/sitemap.t @@ -21,12 +21,12 @@ require_ok('App::DocKnot::Spin::Sitemap'); # Parse a complex .sitemap file. my $datadir = File::Spec->catfile('t', 'data', 'spin', 'sitemap'); -my $path = File::Spec->catfile($datadir, 'complex'); +my $path = File::Spec->catfile($datadir, 'complex'); my $sitemap = App::DocKnot::Spin::Sitemap->new($path); isa_ok($sitemap, 'App::DocKnot::Spin::Sitemap'); # Check the generated sitemap. -my $output = join(q{}, $sitemap->sitemap()); +my $output = join(q{}, $sitemap->sitemap()); my $expected = File::Spec->catfile($datadir, 'complex.html'); is_file_contents($output, $expected, 'sitemap output'); @@ -46,7 +46,7 @@ my @expected = ( qq{ <link rel="top" href="../" />\n}, ); is_deeply(\@links, \@expected, 'links output'); -@navbar = $sitemap->navbar('/faqs/soundness-inn.html'); +@navbar = $sitemap->navbar('/faqs/soundness-inn.html'); @expected = ( qq{<table class="navbar"><tr>\n}, qq{ <td class="navleft"></td>\n}, @@ -57,12 +57,11 @@ is_deeply(\@links, \@expected, 'links output'); q{ <td class="navright"><a href="soundness-cnews.html">} . qq{Soundness for C News</a> ></td>\n}, qq{</tr></table>\n}, - qq{\n}, ); is_deeply(\@navbar, \@expected, 'navbar output'); # Check links for a page with long adjacent titles to test the wrapping. -@links = $sitemap->links('/notes/cvs/basic-usage.html'); +@links = $sitemap->links('/notes/cvs/basic-usage.html'); @expected = ( qq{ <link rel="previous" href="why.html"\n}, qq{ title="Why put a set of files into CVS?" />\n}, diff --git a/t/spin/thread.t b/t/spin/thread.t index 8373eba..c18a743 100755 --- a/t/spin/thread.t +++ b/t/spin/thread.t @@ -23,16 +23,16 @@ 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 = 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'); # 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 $output = slurp($expected); $output =~ s{ from [ ] index[.]th [ ] }{}xms; $output =~ s{ <address> .* </address> \n }{}xms; print {$tempfile} $output or die "Cannot write to $tempfile: $!\n"; @@ -43,7 +43,7 @@ $tempfile->flush(); my $spin = App::DocKnot::Spin::Thread->new({ 'style-url' => '/~eagle/styles/' }); my $thread = slurp($input); -my $cwd = getcwd(); +my $cwd = getcwd(); chdir($inputdir); my $html = $spin->spin_thread($thread); chdir($cwd); diff --git a/t/spin/tree.t b/t/spin/tree.t index a88d0d0..d2daab1 100755 --- a/t/spin/tree.t +++ b/t/spin/tree.t @@ -18,11 +18,16 @@ use File::Copy::Recursive qw(dircopy); use File::Spec (); use File::Temp (); use Perl6::Slurp qw(slurp); -use POSIX qw(strftime); +use POSIX qw(LC_ALL setlocale strftime); use Test::DocKnot::Spin qw(is_spin_output_tree); use Test::More; +# Force the C locale because some of the output intentionally uses localized +# month names and we have to force those to English for comparison of test +# results. +setlocale(LC_ALL, 'C'); + # Expected output when spinning our tree of input files. my $EXPECTED_OUTPUT = <<'OUTPUT'; Generating thread file .../changes.th @@ -51,7 +56,7 @@ Spinning .../software/index.html Creating .../software/docknot Spinning .../software/docknot/index.html Creating .../software/docknot/api -Running pod2thread for .../software/docknot/api/app-docknot.html +Converting .../software/docknot/api/app-docknot.html Creating .../usefor Spinning .../usefor/index.html Creating .../usefor/drafts @@ -61,41 +66,44 @@ Updating .../usefor/drafts/draft-ietf-usefor-useage-01.txt Updating .../usefor/drafts/draft-lindsey-usefor-signed-01.txt OUTPUT +BEGIN { use_ok('App::DocKnot::Util', qw(print_fh)) } + require_ok('App::DocKnot::Spin'); # Copy the input tree to a new temporary directory since .rss files generate -# additional thread files. Replace the rpod pointer since it points to a +# 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 $tmpdir = File::Temp->newdir(); my $datadir = File::Spec->catfile('t', 'data', 'spin'); -my $input = File::Spec->catfile($datadir, 'input'); +my $input = File::Spec->catfile($datadir, 'input'); dircopy($input, $tmpdir->dirname) or die "Cannot copy $input to $tmpdir: $!\n"; -my $rpod_source = File::Spec->catfile(getcwd(), 'lib', 'App', 'DocKnot.pm'); -my $rpod_path = File::Spec->catfile( +my $pod_source = File::Spec->catfile(getcwd(), 'lib', 'App', 'DocKnot.pm'); +my $pointer_path = File::Spec->catfile( $tmpdir->dirname, 'software', 'docknot', 'api', - 'app-docknot.rpod', + 'app-docknot.spin', ); -chmod(0644, $rpod_path); -open(my $fh, '>', $rpod_path); -print {$fh} "$rpod_source\n" or die "Cannot write to $rpod_path: $!\n"; +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); my $old_timestamp = time() - 10; # Spin a tree of files. -my $output = File::Temp->newdir(); +my $output = File::Temp->newdir(); my $expected = File::Spec->catfile($datadir, 'output'); -my $spin = App::DocKnot::Spin->new({ 'style-url' => '/~eagle/styles/' }); -my $stdout = capture_stdout { +my $spin = App::DocKnot::Spin->new({ 'style-url' => '/~eagle/styles/' }); +my $stdout = capture_stdout { $spin->spin($tmpdir->dirname, $output->dirname); }; 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'); +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"; @@ -127,17 +135,20 @@ ok(!-e $bogus, '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, '>>', $rpod_path); -print {$fh} "-c -t 'New Title'\n" or die "Cannot write to $rpod_path: $!\n"; +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); -utime(time() + 5, time() + 5, $rpod_path) - or die "Cannot reset timestamps of $rpod_path: $!\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); }; is( $stdout, - "Running pod2thread for .../software/docknot/api/app-docknot.html\n", + "Converting .../software/docknot/api/app-docknot.html\n", 'Spinning again regenerates the App::DocKnot page', ); my $output_path = File::Spec->catfile( @@ -149,19 +160,19 @@ like( qr{ <title> New [ ] Title </title> }xms, 'POD title override worked', ); -like($page, qr{ <h1> New [ ] Title </h1> }xms, 'POD h1 override worked'); +like($page, qr{ <h1> New [ ] Title </h1> }xms, 'POD h1 override worked'); like($page, qr{ Table [ ] of [ ] Contents }xms, 'POD table of contents'); # Set the time back so that it won't be generated again. -utime(time() - 5, time() - 5, $rpod_path) - or die "Cannot reset timestamps of $rpod_path: $!\n"; +utime(time() - 5, time() - 5, $pointer_path) + or die "Cannot reset timestamps of $pointer_path: $!\n"; # 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 $new_date = strftime('%Y-%m-%d %T', localtime(time() + 10)); +my $versions = slurp($versions_path); +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); @@ -177,4 +188,4 @@ is( ); # Report the end of testing. -done_testing($count + 11); +done_testing($count + 12); diff --git a/t/spin/versions.t b/t/spin/versions.t index 03230c8..640e143 100755 --- a/t/spin/versions.t +++ b/t/spin/versions.t @@ -24,12 +24,12 @@ local $ENV{TZ} = 'America/Los_Angeles'; tzset(); # Parse the file. -my $path = File::Spec->catfile('t', 'data', 'spin', 'input', '.versions'); +my $path = File::Spec->catfile('t', 'data', 'spin', 'input', '.versions'); my $versions = App::DocKnot::Spin::Versions->new($path); isa_ok($versions, 'App::DocKnot::Spin::Versions'); # Check the resulting information. -is($versions->version('docknot'), '4.01', 'docknot version'); +is($versions->version('docknot'), '4.01', 'docknot version'); is($versions->release_date('docknot'), '2021-02-27', 'docknot release date'); is( $versions->latest_release('software/docknot/index.th'), 1614460092, @@ -37,17 +37,17 @@ is( ); # Unknown products or files. -is($versions->version('unknown'), undef, 'unknown version'); -is($versions->release_date('unknown'), undef, 'unknown release date'); -is($versions->latest_release('index.th'), 0, 'unknown file index.th'); +is($versions->version('unknown'), undef, 'unknown version'); +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'); +$path = File::Spec->catfile($inputdir, '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'); -is($versions->version('other-package'), '1.00', 'other-package version'); +is($versions->version('docknot'), '4.01', 'docknot version'); +is($versions->release_date('docknot'), '2021-02-27', 'docknot release date'); +is($versions->version('other-package'), '1.00', 'other-package version'); is( $versions->release_date('other-package'), '2021-09-07', 'other-package release date', |