|
Packit |
e6c7a3 |
#!/usr/bin/perl
|
|
Packit |
e6c7a3 |
#
|
|
Packit |
e6c7a3 |
# Check the SYNOPSIS section of the documentation for syntax errors.
|
|
Packit |
e6c7a3 |
#
|
|
Packit |
e6c7a3 |
# The canonical version of this file is maintained in the rra-c-util package,
|
|
Packit |
e6c7a3 |
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
|
|
Packit |
e6c7a3 |
#
|
|
Packit |
e6c7a3 |
# Written by Russ Allbery <eagle@eyrie.org>
|
|
Packit |
e6c7a3 |
# Copyright 2013, 2014
|
|
Packit |
e6c7a3 |
# The Board of Trustees of the Leland Stanford Junior University
|
|
Packit |
e6c7a3 |
#
|
|
Packit |
e6c7a3 |
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
Packit |
e6c7a3 |
# copy of this software and associated documentation files (the "Software"),
|
|
Packit |
e6c7a3 |
# to deal in the Software without restriction, including without limitation
|
|
Packit |
e6c7a3 |
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
Packit |
e6c7a3 |
# and/or sell copies of the Software, and to permit persons to whom the
|
|
Packit |
e6c7a3 |
# Software is furnished to do so, subject to the following conditions:
|
|
Packit |
e6c7a3 |
#
|
|
Packit |
e6c7a3 |
# The above copyright notice and this permission notice shall be included in
|
|
Packit |
e6c7a3 |
# all copies or substantial portions of the Software.
|
|
Packit |
e6c7a3 |
#
|
|
Packit |
e6c7a3 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
Packit |
e6c7a3 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
Packit |
e6c7a3 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
Packit |
e6c7a3 |
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
Packit |
e6c7a3 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
Packit |
e6c7a3 |
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
Packit |
e6c7a3 |
# DEALINGS IN THE SOFTWARE.
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
use 5.006;
|
|
Packit |
e6c7a3 |
use strict;
|
|
Packit |
e6c7a3 |
use warnings;
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
use lib 't/lib';
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
use File::Spec;
|
|
Packit |
e6c7a3 |
use Test::More;
|
|
Packit |
e6c7a3 |
use Test::RRA qw(skip_unless_automated use_prereq);
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Skip for normal user installs since this doesn't affect functionality.
|
|
Packit |
e6c7a3 |
skip_unless_automated('Synopsis syntax tests');
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Load prerequisite modules.
|
|
Packit |
e6c7a3 |
use_prereq('Perl::Critic::Utils');
|
|
Packit |
e6c7a3 |
use_prereq('Test::Synopsis');
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Helper function that checks to see if a given path starts with blib/script.
|
|
Packit |
e6c7a3 |
# This is written a bit weirdly so that it's portable to Windows and VMS.
|
|
Packit |
e6c7a3 |
#
|
|
Packit |
e6c7a3 |
# $path - Path to a file
|
|
Packit |
e6c7a3 |
#
|
|
Packit |
e6c7a3 |
# Returns: True if the file doesn't start with blib/script, false otherwise.
|
|
Packit |
e6c7a3 |
sub in_blib_script {
|
|
Packit |
e6c7a3 |
my ($path) = @_;
|
|
Packit |
e6c7a3 |
my ($volume, $dir, $file) = File::Spec->splitpath($path);
|
|
Packit |
e6c7a3 |
my @dir = File::Spec->splitdir($dir);
|
|
Packit |
e6c7a3 |
return (scalar(@dir) < 2 || $dir[0] ne 'blib' || $dir[1] ne 'script');
|
|
Packit |
e6c7a3 |
}
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# The default Test::Synopsis all_synopsis_ok() function requires that the
|
|
Packit |
e6c7a3 |
# module be in a lib directory. Use Perl::Critic::Utils to find the modules
|
|
Packit |
e6c7a3 |
# in blib, or lib if it doesn't exist. However, strip out anything in
|
|
Packit |
e6c7a3 |
# blib/script, since scripts use a different SYNOPSIS syntax.
|
|
Packit |
e6c7a3 |
my @files = Perl::Critic::Utils::all_perl_files('blib');
|
|
Packit |
e6c7a3 |
@files = grep { in_blib_script($_) } @files;
|
|
Packit |
e6c7a3 |
if (!@files) {
|
|
Packit |
e6c7a3 |
@files = Perl::Critic::Utils::all_perl_files('lib');
|
|
Packit |
e6c7a3 |
}
|
|
Packit |
e6c7a3 |
plan tests => scalar @files;
|
|
Packit |
e6c7a3 |
|
|
Packit |
e6c7a3 |
# Run the actual tests.
|
|
Packit |
e6c7a3 |
for my $file (@files) {
|
|
Packit |
e6c7a3 |
synopsis_ok($file);
|
|
Packit |
e6c7a3 |
}
|