File: Software-License.t

package info (click to toggle)
libstring-license-perl 0.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,892 kB
  • sloc: perl: 1,519; cpp: 360; ansic: 210; python: 27; ruby: 21; xml: 16; sh: 8; makefile: 3
file content (99 lines) | stat: -rw-r--r-- 3,268 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
use Test2::V0;
use Test2::Require::Module 'Regexp::Pattern::License' => '3.9.0';
use Test2::Require::Module 'Software::LicenseUtils'   => '0.103014';

use Software::LicenseUtils;
use Path::Tiny 0.053;

use lib 't/lib';
use Uncruft;

use String::License;
use String::License::Naming::SPDX;

plan 28;

my %crufty = (
	'Apache-1.1'                              => 'UNKNOWN',
	'Artistic-1.0'                            => 'UNKNOWN',
	'Artistic-1.0 and/or GPL-1.0 and/or Perl' => 'GPL',
	'BSD-3-Clause'                            => 'UNKNOWN',
	'BSD-2-Clause'                            => 'UNKNOWN',
	'GFDL-1.2-or-later and/or GFDL-1.3'       => 'GFDL-1.2-or-later',
	'GPL-1.0'                                 => 'GPL',
	'GPL-2'                                   => 'GPL',
	'LGPL-3'                                  => 'UNKNOWN',
	'MIT'                                     => 'UNKNOWN',
	'MPL-1.0'                                 => 'UNKNOWN',
	'MPL-1.1'                                 => 'UNKNOWN',
	'MPL-2.0'                                 => 'UNKNOWN',
	'OpenSSL and/or SSLeay'                   => 'SSLeay',
	'QPL-1.0'                                 => 'QPL',
	'SISSL'                                   => 'UNKNOWN',
	'Zlib'                                    => 'UNKNOWN',
);

my %LICENSES = (
	'AGPL-3.0'             => 'AGPLv3',
	'Apache-1.1'           => '',
	'Apache-2.0'           => '',
	'Artistic-1.0'         => '',
	'Artistic-2.0'         => '',
	'BSD'                  => 'BSD-3-Clause',
	'CC0-1.0'              => '',
	'EUPL-1.1'             => '',
	'EUPL-1.2'             => '',
	'BSD-2-Clause-FreeBSD' => 'BSD-2-Clause',
	'GFDL-1.2-or-later'    => 'GFDL-1.2-or-later and/or GFDL-1.3',
	'GFDL-1.3-or-later'    => '',
	'GPL-1.0-only'         => 'GPL-1.0',
	'GPL-2.0-only'         => 'GPL-2',
	'GPL-3.0-only'         => 'GPL-3',
	'LGPL-2.1'             => '',
	'LGPL-3.0'             => 'LGPL-3',
	'MIT'                  => '',
	'MPL-1.0'              => '',
	'MPL-1.1'              => '',
	'MPL-2.0'              => '',
	'OpenSSL'              => 'OpenSSL and/or SSLeay',
	'Artistic-1.0-Perl OR GPL-1.0-or-later' =>
		'Artistic-1.0 and/or GPL-1.0 and/or Perl',
	'PostgreSQL' => '',
	'QPL-1.0'    => '',
	'SSLeay'     => '',
	'SISSL'      => '',
	'Zlib'       => '',
);

my $naming = String::License::Naming::SPDX->new;

my $workdir = Path::Tiny->tempdir( CLEANUP => ( not $ENV{PRESERVE} ) );
diag("Detect PRESERVE in environment, so will keep workdir: $workdir")
	if $ENV{PRESERVE};
foreach my $id ( sort keys %LICENSES ) {
	my ( $string, $license, $file, $expected, $resolved );
	eval {
		$license = Software::LicenseUtils->new_from_spdx_expression(
			{   spdx_expression => $id,
				holder => 'Testophilus Testownik <tester@testity.org>',
				year   => 2000,
			}
		);
	};
	skip_all "Software::License failed to create license $id" if $@;
	$file = $workdir->child($id);
	$file->spew_utf8( $license->notice, $license->license );
	$expected = $LICENSES{$id} || $id;
	$string   = $file->slurp_utf8;
	$string   = uncruft($string)
		if exists $crufty{$expected};
	$resolved = String::License->new(
		string => $string,
		naming => $naming,
	)->as_text;
	my $todo;
	like $resolved, $expected,
		"matches expected license for SPDX id $id";
}

done_testing;