3 # Check for obsolete strings in source files.
5 # Examine all source files in a distribution for obsolete strings and report
6 # on files that fail this check. This catches various transitions I want to
7 # do globally in all my packages, like changing my personal URLs to 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, 2018-2019 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.
32 # SPDX-License-Identifier: MIT
38 use lib "$ENV{C_TAP_SOURCE}/tap/perl";
40 use Test::RRA qw(skip_unless_author);
41 use Test::RRA::Automake qw(all_files automake_setup);
43 use File::Basename qw(basename);
46 # Bad patterns to search for.
47 my @BAD_REGEXES = (qr{ http:// \S+ [.]eyrie[.]org }xms);
48 my @BAD_STRINGS = qw(rra@stanford.edu RRA_MAINTAINER_TESTS);
50 # File names to exclude from this check.
51 my %EXCLUDE = map { $_ => 1 } qw(NEWS obsolete-strings.t obsolete-strings-t);
53 # Only run this test for the package author, since it doesn't indicate any
54 # user-noticable flaw in the package itself.
55 skip_unless_author('Obsolete strings tests');
57 # Set up Automake testing.
60 # Check a single file for one of the bad patterns.
62 # $path - Path to the file
67 my $filename = basename($path);
69 # Ignore excluded and binary files.
70 return if $EXCLUDE{$filename};
74 open(my $fh, '<', $path) or BAIL_OUT("Cannot open $path");
75 while (defined(my $line = <$fh>)) {
76 for my $regex (@BAD_REGEXES) {
77 if ($line =~ $regex) {
78 ok(0, "$path contains $regex");
79 close($fh) or BAIL_OUT("Cannot close $path");
83 for my $string (@BAD_STRINGS) {
84 if (index($line, $string) != -1) {
85 ok(0, "$path contains $string");
86 close($fh) or BAIL_OUT("Cannot close $path");
91 close($fh) or BAIL_OUT("Cannot close $path");
96 # Scan every file for any of the bad patterns or strings. We don't declare a
97 # plan since we skip a lot of files and don't want to precalculate the file
99 my @paths = all_files();
100 for my $path (@paths) {