From 242371ea4a884cde6dfa7b0582287c8b0057f4e8 Mon Sep 17 00:00:00 2001 From: James E Keenan Date: Mon, 10 May 2021 15:23:03 +0000 Subject: [PATCH 1/2] ext/Pod-Html/t/*.t: Have each file run in tempdir Until now, the tests for this library ran inside the ext/Pod-Html directory in the core distribution. Since the tests necessarily create files while the harness runs, there was a possibility for race conditions, which meant that we had to have a workaround in t/harness to have the tests in this directory not run in parallel. This commit restructures the testing process so that each test program gets its own tempdir in which to create files and directories. The test architecture is now found in t/lib/Testing.pm. This module will export two functions on demand that are used in the individual test files. They guarantee that all files created when running a test program will be created in a temporary directory rather than underneath the core distribution. t/pod2html-lib.pl is now superseded by t/lib/Testing.pm and can be removed. The workaround has been removed from t/harness. Change directory name from testdir/ to corpus/. So as to more precisely describe what the directory's purpose is. Keep porting tests happy. Update MANIFEST and known_pod_issues database. Acknowledge Craig Berry's recommendation in earlier branch This should help in the resolution of https://github.com/Perl/perl5/issues/12271. --- MANIFEST | 6 +- .../{testdir => corpus}/perlpodspec-copy.pod | 0 .../{testdir => corpus}/perlvar-copy.pod | 0 ext/Pod-Html/t/cache.t | 29 +- ext/Pod-Html/t/crossref.t | 57 +- ext/Pod-Html/t/crossref2.t | 60 +- ext/Pod-Html/t/crossref3.t | 58 +- ext/Pod-Html/t/feature.t | 50 +- ext/Pod-Html/t/feature2.t | 47 +- ext/Pod-Html/t/htmldir1.t | 77 ++- ext/Pod-Html/t/htmldir2.t | 76 ++- ext/Pod-Html/t/htmldir3.t | 90 +-- ext/Pod-Html/t/htmldir4.t | 62 +- ext/Pod-Html/t/htmldir5.t | 56 +- ext/Pod-Html/t/htmlescp.t | 30 +- ext/Pod-Html/t/htmllink.t | 30 +- ext/Pod-Html/t/htmlview.t | 30 +- ext/Pod-Html/t/lib/Testing.pm | 598 ++++++++++++++++++ ext/Pod-Html/t/pod2html-lib.pl | 134 ---- ext/Pod-Html/t/poderr.t | 29 +- ext/Pod-Html/t/podnoerr.t | 30 +- t/harness | 2 +- t/porting/known_pod_issues.dat | 4 +- 23 files changed, 1150 insertions(+), 405 deletions(-) rename ext/Pod-Html/{testdir => corpus}/perlpodspec-copy.pod (100%) rename ext/Pod-Html/{testdir => corpus}/perlvar-copy.pod (100%) create mode 100644 ext/Pod-Html/t/lib/Testing.pm delete mode 100644 ext/Pod-Html/t/pod2html-lib.pl diff --git a/MANIFEST b/MANIFEST index ab1dc3d5acae..4073dd4a06fd 100644 --- a/MANIFEST +++ b/MANIFEST @@ -4321,6 +4321,8 @@ ext/Pod-Functions/Functions_pm.PL Writes Functions.pm ext/Pod-Functions/Makefile.PL Makefile writer ext/Pod-Functions/t/Functions.t See if Pod::Functions works ext/Pod-Html/bin/pod2html Translator to turn pod into HTML +ext/Pod-Html/corpus/perlpodspec-copy.pod +ext/Pod-Html/corpus/perlvar-copy.pod ext/Pod-Html/lib/Pod/Html.pm Convert POD data to HTML ext/Pod-Html/t/anchorify.t ext/Pod-Html/t/cache.pod @@ -4350,13 +4352,11 @@ ext/Pod-Html/t/htmllink.pod pod2html link test input data ext/Pod-Html/t/htmllink.t pod2html link test ext/Pod-Html/t/htmlview.pod pod2html render test input data ext/Pod-Html/t/htmlview.t pod2html render test -ext/Pod-Html/t/pod2html-lib.pl pod2html testing library +ext/Pod-Html/t/lib/Testing.pm Testing functions for Pod-Html ext/Pod-Html/t/poderr.pod ext/Pod-Html/t/poderr.t ext/Pod-Html/t/podnoerr.pod ext/Pod-Html/t/podnoerr.t -ext/Pod-Html/testdir/perlpodspec-copy.pod -ext/Pod-Html/testdir/perlvar-copy.pod ext/POSIX/hints/bsdos.pl Hint for POSIX for named architecture ext/POSIX/hints/dynixptx.pl Hint for POSIX for named architecture ext/POSIX/hints/freebsd.pl Hint for POSIX for named architecture diff --git a/ext/Pod-Html/testdir/perlpodspec-copy.pod b/ext/Pod-Html/corpus/perlpodspec-copy.pod similarity index 100% rename from ext/Pod-Html/testdir/perlpodspec-copy.pod rename to ext/Pod-Html/corpus/perlpodspec-copy.pod diff --git a/ext/Pod-Html/testdir/perlvar-copy.pod b/ext/Pod-Html/corpus/perlvar-copy.pod similarity index 100% rename from ext/Pod-Html/testdir/perlvar-copy.pod rename to ext/Pod-Html/corpus/perlvar-copy.pod diff --git a/ext/Pod-Html/t/cache.t b/ext/Pod-Html/t/cache.t index 3a48a3cb2321..425a7b7b00ec 100644 --- a/ext/Pod-Html/t/cache.t +++ b/ext/Pod-Html/t/cache.t @@ -1,23 +1,31 @@ -#!/usr/bin/perl -w # -*- perl -*- +# -*- perl -*- BEGIN { - die "Run me from outside the t/ directory, please" unless -d 't'; + use File::Spec::Functions ':ALL'; + @INC = map { rel2abs($_) } + (qw| ./lib ./t/lib ../../lib |); } -# test the directory cache -# XXX test --flush and %Pages being loaded/used for cross references - use strict; -use Cwd; -use Pod::Html; -use Data::Dumper; +use warnings; use Test::More tests => 10; +use Testing qw( setup_testing_dir xconvert ); +use Cwd; + +my $debug = 0; +my $startdir = cwd(); +END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } +my $args; + +my $tdir = setup_testing_dir( { + debug => $debug, +} ); my $cwd = Pod::Html::_unixify(Cwd::cwd()); -my $infile = "t/cache.pod"; +my $infile = catfile('t', 'cache.pod'); my $outfile = "cacheout.html"; my $cachefile = "pod2htmd.tmp"; -my $tcachefile = "t/pod2htmd.tmp"; +my $tcachefile = catfile('t', 'pod2htmd.tmp'); unlink $cachefile, $tcachefile; is(-f $cachefile, undef, "No cache file to start"); @@ -70,3 +78,4 @@ close $cache; 1 while unlink $tcachefile; is(-f $cachefile, undef, "No cache file to end"); is(-f $tcachefile, undef, "No cache file to end"); + diff --git a/ext/Pod-Html/t/crossref.t b/ext/Pod-Html/t/crossref.t index 2505c9dd9e2b..5ba28de9e35e 100644 --- a/ext/Pod-Html/t/crossref.t +++ b/ext/Pod-Html/t/crossref.t @@ -1,33 +1,44 @@ -#!/usr/bin/perl -w # -*- perl -*- +# -*- perl -*- BEGIN { - require "./t/pod2html-lib.pl"; -} - -END { - rem_test_dir(); + use File::Spec::Functions ':ALL'; + @INC = map { rel2abs($_) } + (qw| ./lib ./t/lib ../../lib |); } use strict; -use Cwd; -use File::Spec::Functions; +use warnings; use Test::More tests => 1; +use Testing qw( setup_testing_dir xconvert ); +use Cwd; -SKIP: { - my $output = make_test_dir(); - skip "$output", 1 if $output; +my $debug = 0; +my $startdir = cwd(); +END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } +my ($expect_raw, $args); +{ local $/; $expect_raw = ; } + +my $tdir = setup_testing_dir( { + debug => $debug, +} ); + +my ($v, $d) = splitpath(cwd(), 1); +my @dirs = splitdir($d); +shift @dirs if $dirs[0] eq ''; +my $relcwd = join '/', @dirs; - my ($v, $d) = splitpath(cwd(), 1); - my @dirs = splitdir($d); - shift @dirs if $dirs[0] eq ''; - my $relcwd = join '/', @dirs; - - convert_n_test("crossref", "cross references", { - podpath => File::Spec::Unix->catdir($relcwd, 't') . ":" . File::Spec::Unix->catdir($relcwd, 'testdir/test.lib'), +$args = { + podstub => "crossref", + description => "cross references", + expect => $expect_raw, + p2h => { + podpath => File::Spec::Unix->catdir($relcwd, 't') . ":" . File::Spec::Unix->catdir($relcwd, 'corpus/test.lib'), podroot => catpath($v, '/', ''), quiet => 1, - } ); -} + }, + debug => $debug, +}; +xconvert($args); __DATA__ @@ -67,15 +78,15 @@ __DATA__

"non existent section"

-

var-copy

+

var-copy

-

"$"" in var-copy

+

"$"" in var-copy

var-copy

var-copy/$"

-

"First:" in podspec-copy

+

"First:" in podspec-copy

podspec-copy/First:

diff --git a/ext/Pod-Html/t/crossref2.t b/ext/Pod-Html/t/crossref2.t index a2bdfb7df4ef..5843330f2202 100644 --- a/ext/Pod-Html/t/crossref2.t +++ b/ext/Pod-Html/t/crossref2.t @@ -1,32 +1,42 @@ -#!/usr/bin/perl -w # -*- perl -*- +# -*- perl -*- BEGIN { - require "./t/pod2html-lib.pl"; -} - -END { - rem_test_dir(); + use File::Spec::Functions ':ALL'; + @INC = map { rel2abs($_) } + (qw| ./lib ./t/lib ../../lib |); } use strict; -use Cwd; +use warnings; use Test::More tests => 1; +use Testing qw( setup_testing_dir xconvert ); +use Cwd; -SKIP: { - my $output = make_test_dir(); - skip "$output", 1 if $output; - - my $cwd = Pod::Html::_unixify(cwd()); - - convert_n_test("crossref", "cross references", - { - podpath => 't:testdir/test.lib', - podroot => $cwd, - htmldir => $cwd, - quiet => 1, - } - ); -} +my $debug = 0; +my $startdir = cwd(); +END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } +my ($expect_raw, $args); +{ local $/; $expect_raw = ; } + +my $tdir = setup_testing_dir( { + debug => $debug, +} ); + +my $cwd = Pod::Html::_unixify(cwd()); + +$args = { + podstub => "crossref", + description => "cross references", + expect => $expect_raw, + p2h => { + podpath => 't:corpus/test.lib', + podroot => $cwd, + htmldir => $cwd, + quiet => 1, + }, + debug => $debug, +}; +xconvert($args); __DATA__ @@ -66,15 +76,15 @@ __DATA__

"non existent section"

-

var-copy

+

var-copy

-

"$"" in var-copy

+

"$"" in var-copy

var-copy

var-copy/$"

-

"First:" in podspec-copy

+

"First:" in podspec-copy

podspec-copy/First:

diff --git a/ext/Pod-Html/t/crossref3.t b/ext/Pod-Html/t/crossref3.t index 50bf0f23e282..919cfdfd70ae 100644 --- a/ext/Pod-Html/t/crossref3.t +++ b/ext/Pod-Html/t/crossref3.t @@ -1,30 +1,42 @@ -#!/usr/bin/perl -w # -*- perl -*- +# -*- perl -*- BEGIN { - require "./t/pod2html-lib.pl"; -} - -END { - rem_test_dir(); + use File::Spec::Functions ':ALL'; + @INC = map { rel2abs($_) } + (qw| ./lib ./t/lib ../../lib |); } use strict; -use Cwd; +use warnings; use Test::More tests => 1; +use Testing qw( setup_testing_dir xconvert ); +use Cwd; -SKIP: { - my $output = make_test_dir(); - skip "$output", 1 if $output; - - my $cwd = cwd(); - - convert_n_test("crossref", "cross references", { - podpath => 't:testdir/test.lib', - podroot => $cwd, - htmlroot => $cwd, - quiet => 1, - } ); -} +my $debug = 0; +my $startdir = cwd(); +END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } +my ($expect_raw, $args); +{ local $/; $expect_raw = ; } + +my $tdir = setup_testing_dir( { + debug => $debug, +} ); + +my $cwd = cwd(); + +$args = { + podstub => "crossref", + description => "cross references", + expect => $expect_raw, + p2h => { + podpath => 't:corpus/test.lib', + podroot => $cwd, + htmlroot => $cwd, + quiet => 1, + }, + debug => $debug, +}; +xconvert($args); __DATA__ @@ -64,15 +76,15 @@ __DATA__

"non existent section"

-

var-copy

+

var-copy

-

"$"" in var-copy

+

"$"" in var-copy

var-copy

var-copy/$"

-

"First:" in podspec-copy

+

"First:" in podspec-copy

podspec-copy/First:

diff --git a/ext/Pod-Html/t/feature.t b/ext/Pod-Html/t/feature.t index 134768b20219..f44cadea141d 100644 --- a/ext/Pod-Html/t/feature.t +++ b/ext/Pod-Html/t/feature.t @@ -1,28 +1,48 @@ -#!/usr/bin/perl -w # -*- perl -*- +# -*- perl -*- BEGIN { - require "./t/pod2html-lib.pl"; + use File::Spec::Functions ':ALL'; + @INC = map { rel2abs($_) } + (qw| ./lib ./t/lib ../../lib |); } use strict; -use Cwd; -use File::Spec::Functions; +use warnings; use Test::More tests => 1; +use Testing qw( setup_testing_dir xconvert ); +use Cwd; -my $cwd = cwd(); +my $debug = 0; +my $startdir = cwd(); +END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } +my ($expect_raw, $args); +{ local $/; $expect_raw = ; } -convert_n_test("feature", "misc pod-html features", { - backlink => 1, - css => 'style.css', - header => 1, # no styling b/c of --ccs - htmldir => catdir($cwd, 't'), - noindex => 1, - podpath => 't', - podroot => $cwd, - title => 'a title', - quiet => 1, +my $tdir = setup_testing_dir( { + debug => $debug, } ); +my $cwd = cwd(); + +$args = { + podstub => "feature", + description => "misc pod-html features", + expect => $expect_raw, + p2h => { + backlink => 1, + css => 'style.css', + header => 1, # no styling b/c of --ccs + htmldir => catdir($cwd, 't'), + noindex => 1, + podpath => 't', + podroot => $cwd, + title => 'a title', + quiet => 1, + }, + debug => $debug, +}; +xconvert($args); + __DATA__ diff --git a/ext/Pod-Html/t/feature2.t b/ext/Pod-Html/t/feature2.t index 6e345441f21c..2a0ba32c2787 100644 --- a/ext/Pod-Html/t/feature2.t +++ b/ext/Pod-Html/t/feature2.t @@ -1,28 +1,49 @@ -#!/usr/bin/perl -w # -*- perl -*- - +# -*- perl -*- BEGIN { - require "./t/pod2html-lib.pl"; + use File::Spec::Functions ':ALL'; + @INC = map { rel2abs($_) } + (qw| ./lib ./t/lib ../../lib |); } use strict; -use Cwd; +use warnings; use Test::More tests => 2; +use Testing qw( setup_testing_dir xconvert ); +use Cwd; + +my $debug = 0; +my $startdir = cwd(); +END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } +my ($expect_raw, $args); +{ local $/; $expect_raw = ; } + +my $tdir = setup_testing_dir( { + debug => $debug, +} ); my $cwd = cwd(); my $warn; $SIG{__WARN__} = sub { $warn .= $_[0] }; -convert_n_test("feature2", "misc pod-html features 2", { - backlink => 1, - header => 1, - podpath => '.', - podroot => $cwd, - norecurse => 1, - verbose => 1, - quiet => 1, -} ); +$args = { + podstub => "feature2", + description => "misc pod-html features 2", + expect => $expect_raw, + p2h => { + backlink => 1, + header => 1, + podpath => '.', + podroot => $cwd, + norecurse => 1, + verbose => 1, + quiet => 1, + }, + debug => $debug, +}; +xconvert($args); + like($warn, qr( \Acaching\ directories\ for\ later\ use\n diff --git a/ext/Pod-Html/t/htmldir1.t b/ext/Pod-Html/t/htmldir1.t index 8ceea7f22af0..c705f81a3f86 100644 --- a/ext/Pod-Html/t/htmldir1.t +++ b/ext/Pod-Html/t/htmldir1.t @@ -1,51 +1,62 @@ -#!/usr/bin/perl -w # -*- perl -*- +# -*- perl -*- BEGIN { - require "./t/pod2html-lib.pl"; -} - -END { - rem_test_dir(); + use File::Spec::Functions ':ALL'; + @INC = map { rel2abs($_) } + (qw| ./lib ./t/lib ../../lib |); } use strict; -use Cwd; -use File::Spec::Functions; +use warnings; use Test::More tests => 2; +use Testing qw( setup_testing_dir xconvert ); +use Cwd; -# XXX Separate tests that rely on test.lib from the others so they are the only -# ones skipped (instead of all of them). This applies to htmldir{1,3,5}.t, and -# crossref.t (as of 10/29/11). -SKIP: { - my $output = make_test_dir(); - skip "$output", 2 if $output; - - my ($v, $d) = splitpath(cwd(), 1); - my @dirs = splitdir($d); - shift @dirs if $dirs[0] eq ''; - my $relcwd = join '/', @dirs; - - my $data_pos = tell DATA; # to read twice - - - convert_n_test("htmldir1", "test --htmldir and --htmlroot 1a", { +my $debug = 0; +my $startdir = cwd(); +END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } +my ($expect_raw, $args); +{ local $/; $expect_raw = ; } + +my $tdir = setup_testing_dir( { + debug => $debug, +} ); + +my ($v, $d) = splitpath(cwd(), 1); +my @dirs = splitdir($d); +shift @dirs if $dirs[0] eq ''; +my $relcwd = join '/', @dirs; + +$args = { + podstub => "htmldir1", + description => "test --htmldir and --htmlroot 1a", + expect => $expect_raw, + p2h => { podpath => File::Spec::Unix->catdir($relcwd, 't') . ":" . - File::Spec::Unix->catdir($relcwd, 'testdir/test.lib'), + File::Spec::Unix->catdir($relcwd, 'corpus/test.lib'), podroot => catpath($v, '/', ''), htmldir => 't', quiet => 1, - } ); - - seek DATA, $data_pos, 0; # to read twice (expected output is the same) - - convert_n_test("htmldir1", "test --htmldir and --htmlroot 1b", { + }, + debug => $debug, +}; +xconvert($args); + +$args = { + podstub => "htmldir1", + description => "test --htmldir and --htmlroot 1b", + expect => $expect_raw, + p2h => { podpath => $relcwd, podroot => catpath($v, '/', ''), htmldir => catdir($relcwd, 't'), htmlroot => '/', quiet => 1, - } ); -} + }, + debug => $debug, +}; +xconvert($args); + __DATA__ @@ -76,7 +87,7 @@ __DATA__

Normal text, a link to nowhere,

-

a link to var-copy,

+

a link to var-copy,

htmlescp,

diff --git a/ext/Pod-Html/t/htmldir2.t b/ext/Pod-Html/t/htmldir2.t index cad50a403b8d..95b40facea24 100644 --- a/ext/Pod-Html/t/htmldir2.t +++ b/ext/Pod-Html/t/htmldir2.t @@ -1,38 +1,66 @@ -#!/usr/bin/perl -w # -*- perl -*- +# -*- perl -*- BEGIN { - require "./t/pod2html-lib.pl"; + use File::Spec::Functions ':ALL'; + @INC = map { rel2abs($_) } + (qw| ./lib ./t/lib ../../lib |); } use strict; -use Cwd; +use warnings; use Test::More tests => 3; +use Testing qw( setup_testing_dir xconvert ); +use Cwd; -my $cwd = cwd(); -my $data_pos = tell DATA; # to read twice - -convert_n_test("htmldir2", "test --htmldir and --htmlroot 2a", { - podpath => 't', - htmldir => 't', - quiet => 1, -} ); - -seek DATA, $data_pos, 0; # to read twice (expected output is the same) +my $debug = 0; +my $startdir = cwd(); +END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } +my ($expect_raw, $args); +{ local $/; $expect_raw = ; } -convert_n_test("htmldir2", "test --htmldir and --htmlroot 2b", { - podpath => 't', - quiet => 1, +my $tdir = setup_testing_dir( { + debug => $debug, } ); -seek DATA, $data_pos, 0; # to read thrice (expected output is the same) +$args = { + podstub => "htmldir2", + description => "test --htmldir and --htmlroot 2a", + expect => $expect_raw, + p2h => { + podpath => 't', + htmldir => 't', + quiet => 1, + }, + debug => $debug, +}; +xconvert($args); + +$args = { + podstub => "htmldir2", + description => "test --htmldir and --htmlroot 2b", + expect => $expect_raw, + p2h => { + podpath => 't', + quiet => 1, + }, + debug => $debug, +}; +xconvert($args); -# this test makes sure paths are absolute unless --htmldir is specified -convert_n_test("htmldir2", "test --htmldir and --htmlroot 2c", { - podpath => 't', - podroot => $cwd, - norecurse => 1, # testing --norecurse, too - quiet => 1, -} ); +my $cwd = cwd(); +$args = { + podstub => "htmldir2", + description => "test --htmldir and --htmlroot 2c", + expect => $expect_raw, + p2h => { + podpath => 't', + podroot => $cwd, + norecurse => 1, # testing --norecurse, too + quiet => 1, + }, + debug => $debug, +}; +xconvert($args); __DATA__ diff --git a/ext/Pod-Html/t/htmldir3.t b/ext/Pod-Html/t/htmldir3.t index 4998f90db523..a586babd03a1 100644 --- a/ext/Pod-Html/t/htmldir3.t +++ b/ext/Pod-Html/t/htmldir3.t @@ -1,47 +1,61 @@ -#!/usr/bin/perl -w # -*- perl -*- +# -*- perl -*- BEGIN { - require "./t/pod2html-lib.pl"; -} - -END { - rem_test_dir(); + use File::Spec::Functions ':ALL'; + @INC = map { rel2abs($_) } + (qw| ./lib ./t/lib ../../lib |); } use strict; -use Cwd; -use File::Spec::Functions; +use warnings; use Test::More tests => 2; +use Testing qw( setup_testing_dir xconvert ); +use Cwd; -SKIP: { - my $output = make_test_dir(); - skip "$output", 2 if $output; - - my $cwd = cwd(); - my ($v, $d) = splitpath($cwd, 1); - my @dirs = splitdir($d); - shift @dirs if $dirs[0] eq ''; - my $relcwd = join '/', @dirs; - - my $data_pos = tell DATA; # to read twice - - convert_n_test("htmldir3", "test --htmldir and --htmlroot 3a", { - podpath => $relcwd, - podroot => catpath($v, '/', ''), - htmldir => catdir($cwd, 't', ''), # test removal trailing slash, - quiet => 1, - } ); - - seek DATA, $data_pos, 0; # to read twice (expected output is the same) - - convert_n_test("htmldir3", "test --htmldir and --htmlroot 3b", { - podpath => catdir($relcwd, 't'), - podroot => catpath($v, '/', ''), - htmldir => 't', - outfile => 't/htmldir3.html', - quiet => 1, - } ); -} +my $debug = 0; +my $startdir = cwd(); +END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } +my ($expect_raw, $args); +{ local $/; $expect_raw = ; } + +my $tdir = setup_testing_dir( { + debug => $debug, +} ); + +my $cwd = cwd(); +my ($v, $d) = splitpath($cwd, 1); +my @dirs = splitdir($d); +shift @dirs if $dirs[0] eq ''; +my $relcwd = join '/', @dirs; + +$args = { + podstub => "htmldir3", + description => "test --htmldir and --htmlroot 3a", + expect => $expect_raw, + p2h => { + podpath => $relcwd, + podroot => catpath($v, '/', ''), + htmldir => catdir($cwd, 't', ''), # test removal trailing slash, + quiet => 1, + }, + debug => $debug, +}; +xconvert($args); + +$args = { + podstub => "htmldir3", + description => "test --htmldir and --htmlroot 3b", + expect => $expect_raw, + p2h => { + podpath => catdir($relcwd, 't'), + podroot => catpath($v, '/', ''), + htmldir => 't', + outfile => 't/htmldir3.html', + quiet => 1, + }, + debug => $debug, +}; +xconvert($args); __DATA__ @@ -70,7 +84,7 @@ __DATA__

Normal text, a link to nowhere,

-

a link to var-copy,

+

a link to var-copy,

htmlescp,

diff --git a/ext/Pod-Html/t/htmldir4.t b/ext/Pod-Html/t/htmldir4.t index e63eef2c2d71..8157167c3fb7 100644 --- a/ext/Pod-Html/t/htmldir4.t +++ b/ext/Pod-Html/t/htmldir4.t @@ -1,33 +1,57 @@ -#!/usr/bin/perl -w # -*- perl -*- +# -*- perl -*- BEGIN { - require "./t/pod2html-lib.pl"; + use File::Spec::Functions ':ALL'; + @INC = map { rel2abs($_) } + (qw| ./lib ./t/lib ../../lib |); } use strict; -use Cwd; -use File::Spec::Functions ':ALL'; +use warnings; use Test::More tests => 2; +use Testing qw( setup_testing_dir xconvert ); +use Cwd; -my $cwd = cwd(); -my $data_pos = tell DATA; # to read twice +my $debug = 0; +my $startdir = cwd(); +END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } +my ($expect_raw, $args); +{ local $/; $expect_raw = ; } -convert_n_test("htmldir4", "test --htmldir and --htmlroot 4a", { - podpath => 't', - htmldir => 't', - outfile => catfile('t', 'htmldir4.html'), - quiet => 1, +my $tdir = setup_testing_dir( { + debug => $debug, } ); -seek DATA, $data_pos, 0; # to read twice (expected output is the same) +my $cwd = cwd(); -convert_n_test("htmldir4", "test --htmldir and --htmlroot 4b", { - podpath => 't', - podroot => $cwd, - htmldir => catdir($cwd, 't'), - norecurse => 1, - quiet => 1, -} ); +$args = { + podstub => "htmldir4", + description => "test --htmldir and --htmlroot 4a", + expect => $expect_raw, + p2h => { + podpath => 't', + htmldir => 't', + outfile => catfile('t', 'htmldir4.html'), + quiet => 1, + }, + debug => $debug, +}; +xconvert($args); + +$args = { + podstub => "htmldir4", + description => "test --htmldir and --htmlroot 4b", + expect => $expect_raw, + p2h => { + podpath => 't', + podroot => $cwd, + htmldir => catdir($cwd, 't'), + norecurse => 1, + quiet => 1, + }, + debug => $debug, +}; +xconvert($args); __DATA__ diff --git a/ext/Pod-Html/t/htmldir5.t b/ext/Pod-Html/t/htmldir5.t index 7b4d650c45d7..566176108b0b 100644 --- a/ext/Pod-Html/t/htmldir5.t +++ b/ext/Pod-Html/t/htmldir5.t @@ -1,36 +1,46 @@ -#!/usr/bin/perl -w # -*- perl -*- +# -*- perl -*- BEGIN { - require "./t/pod2html-lib.pl"; -} - -END { - rem_test_dir(); + use File::Spec::Functions ':ALL'; + @INC = map { rel2abs($_) } + (qw| ./lib ./t/lib ../../lib |); } use strict; -use Cwd; -use File::Spec::Functions; +use warnings; use Test::More tests => 1; +use Testing qw( setup_testing_dir xconvert ); +use Cwd; -SKIP: { - my $output = make_test_dir(); - skip "$output", 1 if $output; - - - my $cwd = catdir cwd(); # catdir converts path separators to that of the OS - # running the test - # XXX but why don't the other tests complain about - # this? - - convert_n_test("htmldir5", "test --htmldir and --htmlroot 5", { - podpath => 't:testdir/test.lib', +my $debug = 0; +my $startdir = cwd(); +END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } +my ($expect_raw, $args); +{ local $/; $expect_raw = ; } + +my $tdir = setup_testing_dir( { + debug => $debug, +} ); + +my $cwd = catdir cwd(); # catdir converts path separators to that of the OS + # running the test + # XXX but why don't the other tests complain about + # this? + +$args = { + podstub => "htmldir5", + description => "test --htmldir and --htmlroot 5", + expect => $expect_raw, + p2h => { + podpath => 't:corpus/test.lib', podroot => $cwd, htmldir => $cwd, htmlroot => '/', quiet => 1, - } ); -} + }, + debug => $debug, +}; +xconvert($args); __DATA__ @@ -59,7 +69,7 @@ __DATA__

Normal text, a link to nowhere,

-

a link to var-copy,

+

a link to var-copy,

htmlescp,

diff --git a/ext/Pod-Html/t/htmlescp.t b/ext/Pod-Html/t/htmlescp.t index fd5207ab2237..bae0e1a0de21 100644 --- a/ext/Pod-Html/t/htmlescp.t +++ b/ext/Pod-Html/t/htmlescp.t @@ -1,13 +1,35 @@ -#!/usr/bin/perl -w # -*- perl -*- +# -*- perl -*- BEGIN { - require "./t/pod2html-lib.pl"; + use File::Spec::Functions ':ALL'; + @INC = map { rel2abs($_) } + (qw| ./lib ./t/lib ../../lib |); } use strict; +use warnings; use Test::More tests => 1; - -convert_n_test("htmlescp", "html escape"); +use Testing qw( setup_testing_dir xconvert ); +use Cwd; + +my $debug = 0; +my $startdir = cwd(); +END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } +my ($expect_raw, $args); +{ local $/; $expect_raw = ; } + +my $tdir = setup_testing_dir( { + debug => $debug, +} ); + +$args = { + podstub => "htmlescp", + description => "html escape", + expect => $expect_raw, + debug => $debug, +}; + +xconvert($args); __DATA__ diff --git a/ext/Pod-Html/t/htmllink.t b/ext/Pod-Html/t/htmllink.t index 033c93f16f9b..01787555e2df 100644 --- a/ext/Pod-Html/t/htmllink.t +++ b/ext/Pod-Html/t/htmllink.t @@ -1,13 +1,35 @@ -#!/usr/bin/perl -w # -*- perl -*- +# -*- perl -*- BEGIN { - require "./t/pod2html-lib.pl"; + use File::Spec::Functions ':ALL'; + @INC = map { rel2abs($_) } + (qw| ./lib ./t/lib ../../lib |); } use strict; +use warnings; use Test::More tests => 1; - -convert_n_test("htmllink", "html links"); +use Testing qw( setup_testing_dir xconvert ); +use Cwd; + +my $debug = 0; +my $startdir = cwd(); +END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } +my ($expect_raw, $args); +{ local $/; $expect_raw = ; } + +my $tdir = setup_testing_dir( { + debug => $debug, +} ); + +$args = { + podstub => "htmllink", + description => "html links", + expect => $expect_raw, + debug => 1, +}; + +xconvert($args); __DATA__ diff --git a/ext/Pod-Html/t/htmlview.t b/ext/Pod-Html/t/htmlview.t index 00d9e7b01f8a..56dcaa8f2713 100644 --- a/ext/Pod-Html/t/htmlview.t +++ b/ext/Pod-Html/t/htmlview.t @@ -1,16 +1,38 @@ -#!/usr/bin/perl -w # -*- perl -*- +# -*- perl -*- BEGIN { - require "./t/pod2html-lib.pl"; + use File::Spec::Functions ':ALL'; + @INC = map { rel2abs($_) } + (qw| ./lib ./t/lib ../../lib |); } use strict; +use warnings; use Test::More tests => 1; +use Testing qw( setup_testing_dir xconvert ); +use Cwd; -convert_n_test("htmlview", "html rendering", { - quiet => 1, +my $debug = 0; +my $startdir = cwd(); +END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } +my ($expect_raw, $args); +{ local $/; $expect_raw = ; } + +my $tdir = setup_testing_dir( { + debug => $debug, } ); +$args = { + podstub => "htmlview", + description => "html rendering", + expect => $expect_raw, + p2h => { + quiet => 1, + }, +}; + +xconvert($args); + __DATA__ diff --git a/ext/Pod-Html/t/lib/Testing.pm b/ext/Pod-Html/t/lib/Testing.pm new file mode 100644 index 000000000000..94649ec94c90 --- /dev/null +++ b/ext/Pod-Html/t/lib/Testing.pm @@ -0,0 +1,598 @@ +package Testing; +use 5.10.0; +use warnings; +require Exporter; +our $VERSION = 1.26; # Let's keep this same as lib/Pod/Html.pm +our @ISA = qw(Exporter); +our @EXPORT_OK = qw( + setup_testing_dir + xconvert +); +use Cwd; +use Pod::Html; +use Config; +use File::Basename; +use File::Copy; +use File::Path ( qw| make_path | ); +use File::Spec::Functions ':ALL'; +use File::Temp ( qw| tempdir | ); +use Data::Dumper;$Data::Dumper::Sortkeys=1; + +*ok = \&Test::More::ok; +*is = \&Test::More::is; + +our @no_arg_switches = ( qw| + flush recurse norecurse + quiet noquiet verbose noverbose + index noindex backlink nobacklink + header noheader poderrors nopoderrors +| ); + +=head1 NAME + +Testing - Helper functions for testing Pod-Html + +=head1 SYNOPSIS + + use Testing qw( setup_testing_dir xconvert ); + + my $tdir = setup_testing_dir( { + debug => $debug, + } ); + + $args = { + podstub => "htmldir1", + description => "test --htmldir and --htmlroot 1a", + expect => $expect_raw, + p2h => { + podpath => File::Spec::Unix->catdir($relcwd, 't') . ":" . + File::Spec::Unix->catdir($relcwd, 'corpus/test.lib'), + podroot => catpath($v, '/', ''), + htmldir => 't', + quiet => 1, + }, + debug => $debug, + }; + xconvert($args); + +=head1 DESCRIPTION + +This module exports, upon request only, 2 subroutines which are used in most +of the files in the core distribution test suite for Pod-HTML +(F). In the future we may add additional subroutines, +particularly to better diagnose problems with Pod-Html. + +=head2 Pod-Html's Testing Structure + +As of version 1.26 of this module (early 2021), the testing structure consists +of 16 F<.pod> files and 18 F<.t> files located in two subdirectories, +F and F. Let's analyze these by directory. + +=head3 Files in F + +There are currently 2 F<.pod> files in F both of which are old +versions of F files selected to give some complexity to the test +suite. Since we don't actually attempt to make HTML out of their POD, we +don't need to discuss them further. + +=head3 Files in F + +There are currently 14 F<.pod> files and 18 F<.t> files in F. Both of +these numbers may change in the future. + +Currently there are 2 F files (F and F) which +exercise certain functionality of F but which do not require +F files as data input. These files do not make use of the +subroutines exported by this module. We may add more test files like this in +the future to ensure high test coverage, but don't need to discuss them +further here. + +The remaining 16 F test programs make use of the testing subroutines +exported by this module. Most, but not all, of these test programs make use +of the F files. Each such test program makes use of only 1 +F file at a time, though there are several cases where several, +similarly named, test programs make use of the same F file for data +input. For example, + + t/crossref.t + t/crossref2.t + t/crossref3.t + +all make use of + + t/crossref.pod + +Each F file consists solely of simple documentation in POD format. + +=head3 High-level description of programs which use F<.pod> files as input + +Each of the F programs which makes use of a given F file +slurps the text of a single such F file into memory. The test +program holds text in a C handle which serves as a B