3 # Check URLs in source files.
5 # Examine all source files in a distribution for bad URL patterns and report
6 # on files that fail this check. Currently, this just checks that all the
7 # links to www.eyrie.org are https.
9 # The canonical version of this file is maintained in the rra-c-util package,
10 # which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
12 # Copyright 2016 Russ Allbery <eagle@eyrie.org>
14 # Permission is hereby granted, free of charge, to any person obtaining a
15 # copy of this software and associated documentation files (the "Software"),
16 # to deal in the Software without restriction, including without limitation
17 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 # and/or sell copies of the Software, and to permit persons to whom the
19 # Software is furnished to do so, subject to the following conditions:
21 # The above copyright notice and this permission notice shall be included in
22 # all copies or substantial portions of the Software.
24 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 # DEALINGS IN THE SOFTWARE.
36 use lib "$ENV{C_TAP_SOURCE}/tap/perl";
38 use File::Basename qw(basename);
40 use Test::RRA qw(skip_unless_author);
41 use Test::RRA::Automake qw(all_files automake_setup);
43 # Bad patterns to search for.
44 my @BAD_REGEXES = (qr{ http:// \S+ [.]eyrie[.]org }xms);
45 my @BAD_STRINGS = qw(rra@stanford.edu);
47 # Only run this test for the package author, since it doesn't indicate any
48 # user-noticable flaw in the package itself.
49 skip_unless_author('Documentation URL tests');
51 # Set up Automake testing.
54 # Check a single file for one of the bad patterns.
56 # $path - Path to the file
61 my $filename = basename($path);
63 # Ignore this check itself (or the Perl version of it) and binary files.
64 return if ($filename eq 'urls.t' || $filename eq 'urls-t');
68 open(my $fh, '<', $path) or BAIL_OUT("Cannot open $path");
69 while (defined(my $line = <$fh>)) {
70 for my $regex (@BAD_REGEXES) {
71 if ($line =~ $regex) {
72 ok(0, "$path contains $regex");
73 close($fh) or BAIL_OUT("Cannot close $path");
77 for my $string (@BAD_STRINGS) {
78 if (index($line, $string) != -1) {
79 ok(0, "$path contains $string");
80 close($fh) or BAIL_OUT("Cannot close $path");
85 close($fh) or BAIL_OUT("Cannot close $path");
90 # Scan every file for any of the bad patterns or strings. We don't declare a
91 # plan since we skip a lot of files and don't want to precalculate the file
93 my @paths = all_files();
94 for my $path (@paths) {