xref: /openbsd-src/gnu/usr.bin/perl/cpan/podlators/t/docs/synopsis.t (revision e068048151d29f2562a32185e21a8ba885482260)
1b8851fccSafresh1#!/usr/bin/perl
2b8851fccSafresh1#
3b8851fccSafresh1# Check the SYNOPSIS section of the documentation for syntax errors.
4b8851fccSafresh1#
5b8851fccSafresh1# The canonical version of this file is maintained in the rra-c-util package,
65759b3d2Safresh1# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
7b8851fccSafresh1#
8b8851fccSafresh1# Written by Russ Allbery <eagle@eyrie.org>
9*e0680481Safresh1# Copyright 2019, 2021 Russ Allbery <eagle@eyrie.org>
10b46d8ef2Safresh1# Copyright 2013-2014
11b8851fccSafresh1#     The Board of Trustees of the Leland Stanford Junior University
12b8851fccSafresh1#
13b8851fccSafresh1# Permission is hereby granted, free of charge, to any person obtaining a
14b8851fccSafresh1# copy of this software and associated documentation files (the "Software"),
15b8851fccSafresh1# to deal in the Software without restriction, including without limitation
16b8851fccSafresh1# the rights to use, copy, modify, merge, publish, distribute, sublicense,
17b8851fccSafresh1# and/or sell copies of the Software, and to permit persons to whom the
18b8851fccSafresh1# Software is furnished to do so, subject to the following conditions:
19b8851fccSafresh1#
20b8851fccSafresh1# The above copyright notice and this permission notice shall be included in
21b8851fccSafresh1# all copies or substantial portions of the Software.
22b8851fccSafresh1#
23b8851fccSafresh1# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24b8851fccSafresh1# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25b8851fccSafresh1# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
26b8851fccSafresh1# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27b8851fccSafresh1# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28b8851fccSafresh1# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29b8851fccSafresh1# DEALINGS IN THE SOFTWARE.
30b46d8ef2Safresh1#
31b46d8ef2Safresh1# SPDX-License-Identifier: MIT
32b8851fccSafresh1
33*e0680481Safresh1use 5.010;
34b8851fccSafresh1use strict;
35b8851fccSafresh1use warnings;
36b8851fccSafresh1
37b8851fccSafresh1use lib 't/lib';
38b8851fccSafresh1
3956d68f1eSafresh1use Test::RRA qw(skip_unless_automated use_prereq);
4056d68f1eSafresh1
41b8851fccSafresh1use File::Spec;
42b8851fccSafresh1use Test::More;
43b8851fccSafresh1
44b8851fccSafresh1# Skip for normal user installs since this doesn't affect functionality.
45b8851fccSafresh1skip_unless_automated('Synopsis syntax tests');
46b8851fccSafresh1
47b8851fccSafresh1# Load prerequisite modules.
48b8851fccSafresh1use_prereq('Perl::Critic::Utils');
49b8851fccSafresh1use_prereq('Test::Synopsis');
50b8851fccSafresh1
51b8851fccSafresh1# Helper function that checks to see if a given path starts with blib/script.
52b8851fccSafresh1# This is written a bit weirdly so that it's portable to Windows and VMS.
53b8851fccSafresh1#
54b8851fccSafresh1# $path - Path to a file
55b8851fccSafresh1#
56b8851fccSafresh1# Returns: True if the file doesn't start with blib/script, false otherwise.
57b8851fccSafresh1sub in_blib_script {
58b8851fccSafresh1    my ($path) = @_;
59b8851fccSafresh1    my ($volume, $dir, $file) = File::Spec->splitpath($path);
60b8851fccSafresh1    my @dir = File::Spec->splitdir($dir);
61b8851fccSafresh1    return (scalar(@dir) < 2 || $dir[0] ne 'blib' || $dir[1] ne 'script');
62b8851fccSafresh1}
63b8851fccSafresh1
64b8851fccSafresh1# The default Test::Synopsis all_synopsis_ok() function requires that the
65b8851fccSafresh1# module be in a lib directory.  Use Perl::Critic::Utils to find the modules
66b8851fccSafresh1# in blib, or lib if it doesn't exist.  However, strip out anything in
67b8851fccSafresh1# blib/script, since scripts use a different SYNOPSIS syntax.
68b8851fccSafresh1my @files = Perl::Critic::Utils::all_perl_files('blib');
69b8851fccSafresh1@files = grep { in_blib_script($_) } @files;
70b8851fccSafresh1if (!@files) {
71b8851fccSafresh1    @files = Perl::Critic::Utils::all_perl_files('lib');
72b8851fccSafresh1}
73b8851fccSafresh1plan tests => scalar @files;
74b8851fccSafresh1
75b8851fccSafresh1# Run the actual tests.
76b8851fccSafresh1for my $file (@files) {
77b8851fccSafresh1    synopsis_ok($file);
78b8851fccSafresh1}
79