App-FuguWeb

 view release on metacpan or  search on metacpan

t/fuguweb/check.t  view on Meta::CPAN

	like(
		join( "\n", @problems ),
		qr{Thing::Depot\.3p\.html reads as a URL scheme},
		'the missing ./ is named'
	);
};

subtest 'a cross-reference that dangles' => sub {
	# A local .Xr link is a reference like any other, and the
	# reference check catches it.
	my @problems = built( 'other.html' => <<'HTML' )->run;
<title>Other &#8212; Example</title>
<a href="index.html">Home</a>
<a href="https://example.org/">Elsewhere</a>
<a class="Xr" href="./gone.1.html">gone(1)</a>
<h2 id="here">Here</h2>
HTML
	my $joined = join "\n", @problems;
	like( $joined, qr{other\.html: \./gone\.1\.html leads nowhere},
		'a local .Xr that leads nowhere' );
};

subtest 'a page that nothing links to' => sub {
	# index.html no longer links to other.html. 404.html is
	# unlinked on purpose, so it must not be reported.
	my @problems = built( 'index.html' => <<'HTML' )->run;
<title>Home &#8212; Example</title>
<a href="index.html">Home</a>
<a href="https://example.org/">Elsewhere</a>
HTML
	my $joined = join "\n", @problems;

	like( $joined, qr{other\.html: no page links to it},
		'the unreachable page' );
	unlike( $joined, qr{404\.html: no page links to it},
		'a page marked unlinked is not reported' );
};

subtest 'what is not a problem stays not a problem' => sub {
	# The two skip rules. Without a case that exercises each of
	# them, a check that lost one would report a false positive and
	# only the real site would notice.
	my @problems = built( 'other.html' => <<'HTML' )->run;
<title>Other &#8212; Example</title>
<a href="index.html">Home</a>
<a href="https://example.org/">Elsewhere</a>
<a href="mailto:hi@example.org">Mail</a>
<a class="Xr" href="https://man.openbsd.org/rc.8">rc(8)</a>
<h2 id="here">Here</h2>
HTML
	my $joined = join "\n", @problems;

	is( scalar @problems, 0, 'no problem' ) or diag $joined;
	unlike( $joined, qr/mailto/,
		'a mailto: link is not a dead local link' );
	unlike( $joined, qr/man\.openbsd\.org/,
		'a cross-reference that left for the host does not dangle' );
};

subtest 'a stray file in the output' => sub {
	my @problems = built( 'index.html~' => "an editor backup\n" )->run;
	like( join( "\n", @problems ),
		qr{index\.html~: in the output but not in the site},
		'the stray file is named' );
};

done_testing();



( run in 0.405 second using v1.01-cache-2.11-cpan-4ef0a570458 )