aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRuss Allbery <eagle@eyrie.org>2018-05-27 22:05:31 -0700
committerRuss Allbery <eagle@eyrie.org>2018-05-27 22:05:31 -0700
commit769217510b97e23101a01d228e2b8510fd43a725 (patch)
tree8ac16d985a45b1fa3bfb19a6d3ce17bc61c46fbd /tests
parent3c5a45223de1e5a1d39afe78c3a323c68050d466 (diff)
Add obsolete-strings test and fix problems it finds
Mostly changing http eyrie.org URLs to https, but also remove my old email address in one place and switch some tests away from my old RRA_MAINTAINER_TESTS environment variable to use the Lancaster Consensus variables properly. This uncovered a bug in skipping one test unless Stanford Kerberos credentials existed.
Diffstat (limited to 'tests')
-rw-r--r--tests/TESTS1
-rwxr-xr-xtests/style/obsolete-strings-t102
-rw-r--r--tests/tap/perl/Test/RRA/Automake.pm2
3 files changed, 104 insertions, 1 deletions
diff --git a/tests/TESTS b/tests/TESTS
index 76bd4ae..a2c672e 100644
--- a/tests/TESTS
+++ b/tests/TESTS
@@ -14,6 +14,7 @@ portable/snprintf
server/admin
server/backend
server/keytab
+style/obsolete-strings
util/messages
util/messages-krb5
util/xmalloc
diff --git a/tests/style/obsolete-strings-t b/tests/style/obsolete-strings-t
new file mode 100755
index 0000000..b3d8fd4
--- /dev/null
+++ b/tests/style/obsolete-strings-t
@@ -0,0 +1,102 @@
+#!/usr/bin/perl
+#
+# Check for obsolete strings in source files.
+#
+# Examine all source files in a distribution for obsolete strings and report
+# on files that fail this check. This catches various transitions I want to
+# do globally in all my packages, like changing my personal URLs to https.
+#
+# The canonical version of this file is maintained in the rra-c-util package,
+# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
+#
+# Copyright 2016, 2018 Russ Allbery <eagle@eyrie.org>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+#
+# SPDX-License-Identifier: MIT
+
+use 5.006;
+use strict;
+use warnings;
+
+use lib "$ENV{C_TAP_SOURCE}/tap/perl";
+
+use File::Basename qw(basename);
+use Test::More;
+use Test::RRA qw(skip_unless_author);
+use Test::RRA::Automake qw(all_files automake_setup);
+
+# Bad patterns to search for.
+my @BAD_REGEXES = (qr{ http:// \S+ [.]eyrie[.]org }xms);
+my @BAD_STRINGS = qw(rra@stanford.edu RRA_MAINTAINER_TESTS);
+
+# File names to exclude from this check.
+my %EXCLUDE = map { $_ => 1 } qw(NEWS obsolete-strings.t obsolete-strings-t);
+
+# Only run this test for the package author, since it doesn't indicate any
+# user-noticable flaw in the package itself.
+skip_unless_author('Obsolete strings tests');
+
+# Set up Automake testing.
+automake_setup();
+
+# Check a single file for one of the bad patterns.
+#
+# $path - Path to the file
+#
+# Returns: undef
+sub check_file {
+ my ($path) = @_;
+ my $filename = basename($path);
+
+ # Ignore excluded and binary files.
+ return if $EXCLUDE{$filename};
+ return if !-T $path;
+
+ # Scan the file.
+ open(my $fh, '<', $path) or BAIL_OUT("Cannot open $path");
+ while (defined(my $line = <$fh>)) {
+ for my $regex (@BAD_REGEXES) {
+ if ($line =~ $regex) {
+ ok(0, "$path contains $regex");
+ close($fh) or BAIL_OUT("Cannot close $path");
+ return;
+ }
+ }
+ for my $string (@BAD_STRINGS) {
+ if (index($line, $string) != -1) {
+ ok(0, "$path contains $string");
+ close($fh) or BAIL_OUT("Cannot close $path");
+ return;
+ }
+ }
+ }
+ close($fh) or BAIL_OUT("Cannot close $path");
+ ok(1, $path);
+ return;
+}
+
+# Scan every file for any of the bad patterns or strings. We don't declare a
+# plan since we skip a lot of files and don't want to precalculate the file
+# list.
+my @paths = all_files();
+for my $path (@paths) {
+ check_file($path);
+}
+done_testing();
diff --git a/tests/tap/perl/Test/RRA/Automake.pm b/tests/tap/perl/Test/RRA/Automake.pm
index 804c193..3ba5bcb 100644
--- a/tests/tap/perl/Test/RRA/Automake.pm
+++ b/tests/tap/perl/Test/RRA/Automake.pm
@@ -73,7 +73,7 @@ BEGIN {
# Directories to skip globally when looking for all files, or for directories
# that could contain Perl files.
-my @GLOBAL_SKIP = qw(.git _build autom4te.cache build-aux);
+my @GLOBAL_SKIP = qw(.git autom4te.cache build-aux perl/_build perl/blib);
# Additional paths to skip when building a list of all files in the
# distribution. This primarily skips build artifacts that aren't interesting