File: guess_license_from_pod.t

package info (click to toggle)
libsoftware-license-perl 0.104007-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 732 kB
  • sloc: perl: 6,931; makefile: 2
file content (131 lines) | stat: -rw-r--r-- 3,798 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!perl

use strict;
use warnings;

use Test::More;
use Software::LicenseUtils;

{
  # excerpt from BSD License
  my $license = <<'LICENSE';
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

  * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.

  * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.

  * Neither the name of {{$self->holder}} nor the names of its
    contributors may be used to endorse or promote products derived from
    this software without specific prior written permission.
LICENSE

  is_deeply(
    [ Software::LicenseUtils->guess_license_from_pod(build_pod($license)) ],
    [ ], # should eventually be [ 'Software::License::BSD' ],
  );
}

{
  # excerpt from Software::License::None
  my $license = <<'LICENSE';
This software is copyright (c) 2020 by Holder.  No
license is granted to other entities.
LICENSE

  is_deeply(
    [ Software::LicenseUtils->guess_license_from_pod(build_pod($license)) ],
    [ 'Software::License::None' ],
  );
}

subtest 'apache_1_1' => sub {
  my $license = << 'LICENSE';
Apache Software License
Version 1.1

Copyright (c) 2000 The Apache Software Foundation.  All rights reserved.
LICENSE

  # https://www.apache.org/licenses/LICENSE-1.1
  # "An example Apache Software License 1.1 file"
  my $license_as_example = <<'LICENSE_AS_EXAMPLE';
The Apache Software License, Version 1.1

Copyright (c) 2000 The Apache Software Foundation.  All rights
reserved.
LICENSE_AS_EXAMPLE

  my @license_strings = (
    $license,
    $license_as_example,
    "apache 1.1", "Apache 1.1", "APACHE 1.1",
    "apache-1.1", "Apache-1.1", "APACHE-1.1",
  );

  foreach my $license_text (@license_strings) {
    my $pod = "=head1 LICENSE\n\n" . $license_text . "\n=cut\n";

    is_deeply(
      [ Software::LicenseUtils->guess_license_from_pod($pod) ],
      [ 'Software::License::Apache_1_1' ],
      $license_text
    );
  }
};

subtest 'apache_2_0' => sub {
  my $license = << 'LICENSE';
                                 Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
LICENSE

  # https://www.apache.org/licenses/LICENSE-2.0 suggests:
  #
  #    To apply the Apache License to specific files in your work, attach
  #    the following boilerplate declaration, ...
  my $boilerplate = << 'BOILERPLATE';
Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
BOILERPLATE

  my @license_strings = (
    $license,
    $boilerplate,
    "apache 2.0", "Apache 2.0", "APACHE 2.0",
    "apache-2.0", "Apache-2.0", "APACHE-2.0",
  );

  foreach my $license_text (@license_strings) {
    my $pod = "=head1 LICENSE\n\n" . $license_text . "\n=cut\n";

    is_deeply(
      [ Software::LicenseUtils->guess_license_from_pod($pod) ],
      [ 'Software::License::Apache_2_0' ],
      $license_text
    );
  }
};

done_testing;

sub build_pod { "=head1 LICENSE\n\n" . shift . "\n=cut\n" }