This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update podlators to CPAN version 4.13
[perl5.git] / cpan / podlators / t / docs / spdx-license.t
index 100adf1..5b34cab 100644 (file)
@@ -9,7 +9,7 @@
 # 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 2018 Russ Allbery <eagle@eyrie.org>
+# Copyright 2018-2019 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"),
 #
 # SPDX-License-Identifier: MIT
 
-use 5.006;
+use 5.008;
 use strict;
 use warnings;
 
 use lib 't/lib';
 
+use Test::RRA qw(skip_unless_automated);
+
 use File::Find qw(find);
 use Test::More;
-use Test::RRA qw(skip_unless_automated);
 
 # File name (the file without any directory component) and path patterns to
 # skip for this check.
 ## no critic (RegularExpressions::ProhibitFixedStringMatches)
 my @IGNORE = (
-    qr{ \A Build ( [.] .* )? \z }ixms,      # Generated file from Build.PL
+    qr{ \A Build ( [.] (?!PL) .* )? \z }ixms,    # Generated file from Build.PL
     qr{ \A LICENSE \z }xms,                 # Generated file, no license itself
     qr{ \A (Changes|NEWS|THANKS) \z }xms,   # Package license should be fine
     qr{ \A TODO \z }xms,                    # Package license should be fine
@@ -60,11 +61,13 @@ my @IGNORE_PATHS = (
     qr{ \A [.] /_build/ }xms,                 # Module::Build metadata
     qr{ \A [.] /blib/ }xms,                   # Perl build system artifacts
     qr{ \A [.] /cover_db/ }xms,               # Artifacts from coverage testing
+    qr{ \A [.] /debian/ }xms,                 # Found in debian/* branches
     qr{ \A [.] /docs/metadata/ }xms,          # Package license should be fine
     qr{ \A [.] /README ( [.] .* )? \z }xms,   # Package license should be fine
     qr{ \A [.] /share/ }xms,                  # Package license should be fine
     qr{ \A [.] /t/data .* /metadata/ }xms,    # Test metadata
     qr{ \A [.] /t/data .* /output/ }xms,      # Test output
+    qr{ \A [.] /t/data .* [.] json \z }xms,   # Test metadata
 );
 ## use critic
 
@@ -81,9 +84,7 @@ sub check_file {
     my $filename = $_;
     my $path     = $File::Find::name;
 
-    # Ignore files in the whitelist, binary files, and files under 1KB.  The
-    # latter can be rolled up into the overall project license and the license
-    # notice may be a substantial portion of the file size.
+    # Ignore files in the whitelist and binary files.
     for my $pattern (@IGNORE) {
         return if $filename =~ $pattern;
     }
@@ -95,12 +96,14 @@ sub check_file {
     }
     return if -d $filename;
     return if !-T $filename;
-    return if -s $filename < 1024;
 
     # Scan the file.
-    my ($saw_spdx, $skip_spdx);
+    my ($saw_legacy_notice, $saw_spdx, $skip_spdx);
     open(my $file, '<', $filename) or BAIL_OUT("Cannot open $path");
     while (defined(my $line = <$file>)) {
+        if ($line =~ m{ \b See \s+ LICENSE \s+ for \s+ licensing }xms) {
+            $saw_legacy_notice = 1;
+        }
         if ($line =~ m{ \b SPDX-License-Identifier: \s+ \S+ }xms) {
             $saw_spdx = 1;
             last;
@@ -111,7 +114,16 @@ sub check_file {
         }
     }
     close($file) or BAIL_OUT("Cannot close $path");
-    ok($saw_spdx || $skip_spdx, $path);
+
+    # If there is a legacy license notice, report a failure regardless of file
+    # size.  Otherwise, skip files under 1KB.  They can be rolled up into the
+    # overall project license and the license notice may be a substantial
+    # portion of the file size.
+    if ($saw_legacy_notice) {
+        ok(!$saw_legacy_notice, "$path has legacy license notice");
+    } else {
+        ok($saw_spdx || $skip_spdx || -s $filename < 1024, $path);
+    }
     return;
 }