licensee 8.5.0 → 8.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -104
- data/bin/licensee +26 -12
- data/lib/licensee.rb +1 -0
- data/lib/licensee/license.rb +6 -2
- data/lib/licensee/matchers/copyright_matcher.rb +2 -0
- data/lib/licensee/matchers/cran_matcher.rb +20 -0
- data/lib/licensee/matchers/exact_matcher.rb +2 -0
- data/lib/licensee/project.rb +2 -1
- data/lib/licensee/project_file.rb +8 -2
- data/lib/licensee/project_files/license_file.rb +27 -6
- data/lib/licensee/project_files/package_info.rb +6 -1
- data/lib/licensee/project_files/readme.rb +2 -2
- data/lib/licensee/projects/fs_project.rb +0 -1
- data/lib/licensee/version.rb +1 -1
- data/spec/bin_spec.rb +56 -0
- data/spec/fixtures/case-sensitive/LiCeNsE.TxT +0 -0
- data/spec/fixtures/gemspec/project.gemspec +1 -0
- data/spec/fixtures/lgpl/COPYING.lesser +165 -0
- data/spec/fixtures/lgpl/LICENSE +674 -0
- data/spec/fixtures/license-folder/README.md +0 -0
- data/{test/fixtures/mit-without-title/mit.txt → spec/fixtures/mit/LICENSE.txt} +3 -1
- data/{test/fixtures/mit-with-redundant-title/mit.txt → spec/fixtures/mit/README.md} +4 -2
- data/spec/fixtures/mpl-without-hrs/LICENSE +362 -0
- data/spec/fixtures/readme/README.md +23 -0
- data/spec/integration_spec.rb +121 -0
- data/spec/licensee/content_helper_spec.rb +77 -0
- data/spec/licensee/license_spec.rb +224 -0
- data/spec/licensee/matchers/copyright_matcher_spec.rb +47 -0
- data/spec/licensee/matchers/cran_matcher_spec.rb +18 -0
- data/spec/licensee/matchers/dice_matcher_spec.rb +43 -0
- data/spec/licensee/matchers/exact_matcher_spec.rb +26 -0
- data/spec/licensee/matchers/gemspec_matcher_spec.rb +29 -0
- data/spec/licensee/matchers/npm_bower_matcher_spec.rb +31 -0
- data/spec/licensee/matchers/package_matcher_spec.rb +15 -0
- data/spec/licensee/project_files/license_file_spec.rb +122 -0
- data/spec/licensee/project_files/package_info_spec.rb +51 -0
- data/spec/licensee/project_files/readme_spec.rb +77 -0
- data/spec/licensee/project_spec.rb +91 -0
- data/spec/licensee_spec.rb +41 -0
- data/spec/project_file_spec.rb +33 -0
- data/spec/spec_helper.rb +78 -0
- data/spec/vendored_license_spec.rb +75 -0
- data/vendor/choosealicense.com/_licenses/bsl-1.0.txt +48 -0
- data/vendor/choosealicense.com/_licenses/lgpl-3.0.txt +1 -1
- metadata +39 -111
- data/Rakefile +0 -12
- data/test/fixtures/apache-2.0/LICENSE +0 -201
- data/test/fixtures/bower-with-readme/README.md +0 -1
- data/test/fixtures/bower-with-readme/bower.json +0 -3
- data/test/fixtures/bower/bower.json +0 -3
- data/test/fixtures/bsd-2-clause-without-title/bsd-2-clause.txt +0 -23
- data/test/fixtures/bsd-3-clause-without-title/bsd-3-clause.txt +0 -27
- data/test/fixtures/case-sensitive.git/HEAD +0 -1
- data/test/fixtures/case-sensitive.git/config +0 -6
- data/test/fixtures/case-sensitive.git/objects/01/7b4f1eebd1dcb735e950b1d01093e3e2bf85e9 +0 -0
- data/test/fixtures/case-sensitive.git/objects/2c/b878e0851c5cf53d7455d9018baa6755a38bd7 +0 -0
- data/test/fixtures/case-sensitive.git/objects/fb/ddf40ba5f30225af7cd9841afe374ca5800cb9 +0 -0
- data/test/fixtures/case-sensitive.git/refs/heads/master +0 -1
- data/test/fixtures/isc-without-title/isc.txt +0 -13
- data/test/fixtures/lgpl.git/HEAD +0 -1
- data/test/fixtures/lgpl.git/config +0 -5
- data/test/fixtures/lgpl.git/objects/1a/cd060ebbbeac294200008657d9502130f93465 +0 -2
- data/test/fixtures/lgpl.git/objects/4b/1f98c1e95b6d4dae0b0a160f554be97e5afece +0 -2
- data/test/fixtures/lgpl.git/objects/a4/cfa42bc8e1d432fa851c5c4e3f294f01e05fd3 +0 -0
- data/test/fixtures/lgpl.git/objects/b7/de6e186bd02935030f5d42867ea7043fb1c27c +0 -0
- data/test/fixtures/lgpl.git/objects/dd/d0e017b1bf39218a6ea4f2fadd29a7ea8ebe03 +0 -0
- data/test/fixtures/lgpl.git/objects/eb/d853e83a2d317422c52f3922f4c9c5bb4a10b7 +0 -0
- data/test/fixtures/lgpl.git/refs/heads/master +0 -1
- data/test/fixtures/licence.git/HEAD +0 -1
- data/test/fixtures/licence.git/config +0 -6
- data/test/fixtures/licence.git/objects/66/0c086dc25f9f3b96e7afd9dee8a11b4e614543 +0 -0
- data/test/fixtures/licence.git/objects/68/804815597f79aa323de3257a8fd7b76449943c +0 -0
- data/test/fixtures/licence.git/objects/dd/59aed84c5aa4dff7ceda11a1c045f831194067 +0 -0
- data/test/fixtures/licence.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
- data/test/fixtures/licence.git/refs/heads/master +0 -1
- data/test/fixtures/license-folder.git/HEAD +0 -1
- data/test/fixtures/license-folder.git/config +0 -6
- data/test/fixtures/license-folder.git/objects/32/6d0761f0c54d54327ea9e127e02d9bae14d2c8 +0 -2
- data/test/fixtures/license-folder.git/objects/93/109217bbe2937fc3a8d8933fddd80ed6292481 +0 -0
- data/test/fixtures/license-folder.git/objects/c6/6e45436e4f3fda934dc7268bccbc59c37a67b4 +0 -0
- data/test/fixtures/license-folder.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
- data/test/fixtures/license-folder.git/refs/heads/master +0 -1
- data/test/fixtures/licenses.git/HEAD +0 -1
- data/test/fixtures/licenses.git/config +0 -4
- data/test/fixtures/licenses.git/objects/51/a11d50f29a14774ded8f7b90ba9938dce78a92 +0 -3
- data/test/fixtures/licenses.git/objects/5e/df454e6517673d5e64a33cf284308b9c6b1075 +0 -0
- data/test/fixtures/licenses.git/objects/e1/b4dc13f4bf683ce8f2943e051c3e91e778d043 +0 -0
- data/test/fixtures/licenses.git/objects/info/packs +0 -2
- data/test/fixtures/licenses.git/objects/pack/pack-4a7088171ae3ca900f010a4be6f1c2c96490c338.idx +0 -0
- data/test/fixtures/licenses.git/objects/pack/pack-4a7088171ae3ca900f010a4be6f1c2c96490c338.pack +0 -0
- data/test/fixtures/licenses.git/packed-refs +0 -4
- data/test/fixtures/licenses.git/refs/heads/master +0 -1
- data/test/fixtures/mit-without-title-rewrapped/mit.txt +0 -19
- data/test/fixtures/mpl-without-hrs.git/HEAD +0 -1
- data/test/fixtures/mpl-without-hrs.git/config +0 -5
- data/test/fixtures/mpl-without-hrs.git/objects/45/26aa2d1d78ea20fb0faf59f2360a68fa897774 +0 -0
- data/test/fixtures/mpl-without-hrs.git/objects/ba/f5649b61fac4ed64ec2949fe5cd616b85a8298 +0 -0
- data/test/fixtures/mpl-without-hrs.git/objects/be/2cc4dfb609fb6c38f6365ec345bded3350dd63 +0 -0
- data/test/fixtures/mpl-without-hrs.git/refs/heads/master +0 -1
- data/test/fixtures/named-license-file-prefix.git/HEAD +0 -1
- data/test/fixtures/named-license-file-prefix.git/config +0 -6
- data/test/fixtures/named-license-file-prefix.git/objects/64/3983d3f82ecc2a7d8e4227946220ebffd477d2 +0 -4
- data/test/fixtures/named-license-file-prefix.git/objects/c9/b229e500e529fdbd4f50746ba207e91d0677b6 +0 -7
- data/test/fixtures/named-license-file-prefix.git/objects/d1/9223f355283b3ce0c51a2c527f685d0f403157 +0 -0
- data/test/fixtures/named-license-file-prefix.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
- data/test/fixtures/named-license-file-prefix.git/refs/heads/master +0 -1
- data/test/fixtures/named-license-file-suffix.git/HEAD +0 -1
- data/test/fixtures/named-license-file-suffix.git/config +0 -6
- data/test/fixtures/named-license-file-suffix.git/objects/36/465372136f81a2089f486298ca77ef41611198 +0 -0
- data/test/fixtures/named-license-file-suffix.git/objects/4a/2a139e7fbd24eef5c5ef3d22f490e89405f6a3 +0 -3
- data/test/fixtures/named-license-file-suffix.git/objects/c9/b229e500e529fdbd4f50746ba207e91d0677b6 +0 -7
- data/test/fixtures/named-license-file-suffix.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
- data/test/fixtures/named-license-file-suffix.git/refs/heads/master +0 -1
- data/test/fixtures/no-license.git/HEAD +0 -1
- data/test/fixtures/no-license.git/config +0 -6
- data/test/fixtures/no-license.git/objects/82/0c999cf27a6f71431646c404274c578f7a2869 +0 -0
- data/test/fixtures/no-license.git/objects/e1/d9b2a3d41c2ea74a520e66da2b5c63b2f6202f +0 -0
- data/test/fixtures/no-license.git/objects/ff/1592f44259635df9feda5e02853964b26f9e4d +0 -0
- data/test/fixtures/no-license.git/refs/heads/master +0 -1
- data/test/fixtures/npm-non-spdx/package.json +0 -3
- data/test/fixtures/npm.git/HEAD +0 -1
- data/test/fixtures/npm.git/config +0 -4
- data/test/fixtures/npm.git/objects/info/packs +0 -2
- data/test/fixtures/npm.git/objects/pack/pack-03c0879445cabcc37f91d97c7955465adef26f4a.idx +0 -0
- data/test/fixtures/npm.git/objects/pack/pack-03c0879445cabcc37f91d97c7955465adef26f4a.pack +0 -0
- data/test/fixtures/npm.git/packed-refs +0 -2
- data/test/fixtures/npm/package.json +0 -3
- data/test/functions.rb +0 -73
- data/test/helper.rb +0 -16
- data/test/licensee/matchers/test_copyright_matcher.rb +0 -59
- data/test/licensee/matchers/test_dice_matcher.rb +0 -60
- data/test/licensee/matchers/test_exact_matcher.rb +0 -25
- data/test/licensee/matchers/test_gemspec_matcher.rb +0 -11
- data/test/licensee/matchers/test_npm_bower_matcher.rb +0 -27
- data/test/licensee/matchers/test_package_matcher.rb +0 -27
- data/test/licensee/project_files/test_license_file.rb +0 -73
- data/test/licensee/project_files/test_package_info.rb +0 -19
- data/test/licensee/project_files/test_readme.rb +0 -47
- data/test/licensee/test_content_helper.rb +0 -81
- data/test/licensee/test_license.rb +0 -182
- data/test/licensee/test_project.rb +0 -134
- data/test/licensee/test_project_file.rb +0 -24
- data/test/test_licensee.rb +0 -40
- data/test/test_licensee_bin.rb +0 -37
- data/test/test_licensee_vendor.rb +0 -33
@@ -1,59 +0,0 @@
|
|
1
|
-
# encoding=utf-8
|
2
|
-
require 'helper'
|
3
|
-
|
4
|
-
class TestLicenseeCopyrightMatchers < Minitest::Test
|
5
|
-
should 'match the license' do
|
6
|
-
text = 'Copyright 2015 Ben Balter'
|
7
|
-
file = Licensee::Project::LicenseFile.new(text)
|
8
|
-
assert_equal 'no-license', Licensee::Matchers::Copyright.new(file).match.key
|
9
|
-
end
|
10
|
-
|
11
|
-
should 'know the match confidence' do
|
12
|
-
text = 'Copyright 2015 Ben Balter'
|
13
|
-
file = Licensee::Project::LicenseFile.new(text)
|
14
|
-
assert_equal 100, Licensee::Matchers::Copyright.new(file).confidence
|
15
|
-
end
|
16
|
-
|
17
|
-
should 'match Copyright (C) copyright notices' do
|
18
|
-
text = 'Copyright (C) 2015 Ben Balter'
|
19
|
-
file = Licensee::Project::LicenseFile.new(text)
|
20
|
-
assert_equal 'no-license', Licensee::Matchers::Copyright.new(file).match.key
|
21
|
-
end
|
22
|
-
|
23
|
-
should 'match Copyright © copyright notices' do
|
24
|
-
text = 'copyright © 2015 Ben Balter'
|
25
|
-
file = Licensee::Project::LicenseFile.new(text)
|
26
|
-
assert_equal 'no-license', Licensee::Matchers::Copyright.new(file).match.key
|
27
|
-
end
|
28
|
-
|
29
|
-
should 'match (c) copyright notices' do
|
30
|
-
text = '(C) 2015 Ben Balter'
|
31
|
-
file = Licensee::Project::LicenseFile.new(text)
|
32
|
-
assert_equal 'no-license', Licensee::Matchers::Copyright.new(file).match.key
|
33
|
-
end
|
34
|
-
|
35
|
-
should 'not false positive' do
|
36
|
-
path = Licensee::License.find('mit').path
|
37
|
-
text = File.read(path, encoding: 'utf-8').split('---').last
|
38
|
-
file = Licensee::Project::LicenseFile.new(text)
|
39
|
-
assert_equal nil, Licensee::Matchers::Copyright.new(file).match
|
40
|
-
end
|
41
|
-
|
42
|
-
should 'handle UTF-8 encoded copyright notices' do
|
43
|
-
text = 'Copyright (c) 2010-2014 Simon Hürlimann'
|
44
|
-
file = Licensee::Project::LicenseFile.new(text)
|
45
|
-
assert_equal 'no-license', Licensee::Matchers::Copyright.new(file).match.key
|
46
|
-
end
|
47
|
-
|
48
|
-
should 'handle ASCII-8BIT encoded copyright notices' do
|
49
|
-
text = "Copyright \xC2\xA92015 Ben Balter`".force_encoding('ASCII-8BIT')
|
50
|
-
file = Licensee::Project::LicenseFile.new(text)
|
51
|
-
assert_equal 'no-license', Licensee::Matchers::Copyright.new(file).match.key
|
52
|
-
end
|
53
|
-
|
54
|
-
should 'match comma, separated dates' do
|
55
|
-
text = 'Copyright (c) 2003, 2004 Ben Balter'
|
56
|
-
file = Licensee::Project::LicenseFile.new(text)
|
57
|
-
assert_equal 'no-license', Licensee::Matchers::Copyright.new(file).match.key
|
58
|
-
end
|
59
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestLicenseeDiceMatchers < Minitest::Test
|
4
|
-
def setup
|
5
|
-
text = license_from_path(Licensee::License.find('mit').path)
|
6
|
-
@mit = Licensee::Project::LicenseFile.new(text)
|
7
|
-
|
8
|
-
text = license_from_path(Licensee::License.find('gpl-2.0').path)
|
9
|
-
@gpl = Licensee::Project::LicenseFile.new(text)
|
10
|
-
end
|
11
|
-
|
12
|
-
def concat_licenses(*args)
|
13
|
-
args.map do |license|
|
14
|
-
license_from_path(Licensee::License.find(license).path)
|
15
|
-
end.join("\n")
|
16
|
-
end
|
17
|
-
|
18
|
-
should 'match the license' do
|
19
|
-
assert_equal 'mit', Licensee::Matchers::Dice.new(@mit).match.key
|
20
|
-
end
|
21
|
-
|
22
|
-
should 'know the match confidence' do
|
23
|
-
matcher = Licensee::Matchers::Dice.new(@mit)
|
24
|
-
assert matcher.confidence > 95, "#{matcher.confidence} < 95"
|
25
|
-
end
|
26
|
-
|
27
|
-
should 'know when two licenses have be concatenated' do
|
28
|
-
text = concat_licenses('mit', 'gpl-2.0')
|
29
|
-
license = Licensee::Project::LicenseFile.new(text)
|
30
|
-
matcher = Licensee::Matchers::Dice.new(license)
|
31
|
-
if matcher.match
|
32
|
-
msg = "Expected no-license, got #{matcher.match.key}"
|
33
|
-
msg << " (#{matcher.match.similarity(license).round(2)}% similar)"
|
34
|
-
end
|
35
|
-
refute matcher.match, msg
|
36
|
-
end
|
37
|
-
|
38
|
-
should 'build the list of licenses by similarity' do
|
39
|
-
matcher = Licensee::Matchers::Dice.new(@gpl)
|
40
|
-
|
41
|
-
match = matcher.licenses_by_similiarity.first
|
42
|
-
assert_equal Licensee::License, match[0].class
|
43
|
-
assert_equal 'gpl-2.0', match[0].key
|
44
|
-
assert_equal 100.0, match[1]
|
45
|
-
|
46
|
-
match = matcher.licenses_by_similiarity[1]
|
47
|
-
assert_equal 'lppl-1.3c', match[0].key
|
48
|
-
assert_equal 49.52, match[1].round(2)
|
49
|
-
end
|
50
|
-
|
51
|
-
should 'build the list of matches' do
|
52
|
-
matcher = Licensee::Matchers::Dice.new(@gpl)
|
53
|
-
|
54
|
-
assert_equal 1, matcher.matches.count
|
55
|
-
match = matcher.matches.first
|
56
|
-
assert_equal Licensee::License, match[0].class
|
57
|
-
assert_equal 'gpl-2.0', match[0].key
|
58
|
-
assert_equal 100.0, match[1]
|
59
|
-
end
|
60
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestLicenseeExactMatchers < Minitest::Test
|
4
|
-
def setup
|
5
|
-
path = Licensee::License.find('mit').path
|
6
|
-
text = File.read(path, encoding: 'utf-8').split('---').last
|
7
|
-
@mit = Licensee::Project::LicenseFile.new(text)
|
8
|
-
end
|
9
|
-
|
10
|
-
should 'match the license' do
|
11
|
-
assert_equal 'mit', Licensee::Matchers::Exact.new(@mit).match.key
|
12
|
-
end
|
13
|
-
|
14
|
-
should 'know the match confidence' do
|
15
|
-
assert_equal 100, Licensee::Matchers::Exact.new(@mit).confidence
|
16
|
-
end
|
17
|
-
|
18
|
-
should 'require the file to be the same length' do
|
19
|
-
path = Licensee::License.find('mit').path
|
20
|
-
text = File.read(path, encoding: 'utf-8').split('---').last
|
21
|
-
text << ' MIT'
|
22
|
-
license = Licensee::Project::LicenseFile.new(text)
|
23
|
-
refute Licensee::Matchers::Exact.new(license).match
|
24
|
-
end
|
25
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestLicenseeGemspecMatchers < Minitest::Test
|
4
|
-
should 'detect its own license' do
|
5
|
-
root = File.expand_path '../../../', File.dirname(__FILE__)
|
6
|
-
project = Licensee::GitProject.new(root, detect_packages: true)
|
7
|
-
matcher = Licensee::Matchers::Gemspec.new(project.package_file)
|
8
|
-
assert_equal 'mit', matcher.send(:license_property)
|
9
|
-
assert_equal 'mit', matcher.match.key
|
10
|
-
end
|
11
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestLicenseeNpmBowerMatchers < Minitest::Test
|
4
|
-
should 'detect NPM files' do
|
5
|
-
pkg = File.read fixture_path('npm/package.json')
|
6
|
-
pkgfile = Licensee::Project::PackageInfo.new(pkg)
|
7
|
-
matcher = Licensee::Matchers::NpmBower.new(pkgfile)
|
8
|
-
assert_equal 'mit', matcher.send(:license_property)
|
9
|
-
assert_equal 'mit', matcher.match.key
|
10
|
-
end
|
11
|
-
|
12
|
-
should 'detect Bower files' do
|
13
|
-
pkg = File.read fixture_path('bower/bower.json')
|
14
|
-
pkgfile = Licensee::Project::PackageInfo.new(pkg)
|
15
|
-
matcher = Licensee::Matchers::NpmBower.new(pkgfile)
|
16
|
-
assert_equal 'mit', matcher.send(:license_property)
|
17
|
-
assert_equal 'mit', matcher.match.key
|
18
|
-
end
|
19
|
-
|
20
|
-
should 'not err on non-spdx licenses' do
|
21
|
-
pkg = File.read fixture_path('npm-non-spdx/package.json')
|
22
|
-
pkgfile = Licensee::Project::PackageInfo.new(pkg)
|
23
|
-
matcher = Licensee::Matchers::NpmBower.new(pkgfile)
|
24
|
-
assert_equal 'mit-1.0', matcher.send(:license_property)
|
25
|
-
assert_equal nil, matcher.match
|
26
|
-
end
|
27
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class PackageMatcherTestHelper < Licensee::Matchers::Package
|
4
|
-
attr_accessor :license_property, :file
|
5
|
-
end
|
6
|
-
|
7
|
-
class TestLicenseePackageMatcher < Minitest::Test
|
8
|
-
def setup
|
9
|
-
pkg = File.read fixture_path('npm/package.json')
|
10
|
-
@file = Licensee::Project::PackageInfo.new(pkg)
|
11
|
-
@matcher = PackageMatcherTestHelper.new(@file)
|
12
|
-
@matcher.license_property = 'mit'
|
13
|
-
end
|
14
|
-
|
15
|
-
should 'store the file' do
|
16
|
-
assert_equal @matcher.file, @file
|
17
|
-
end
|
18
|
-
|
19
|
-
should 'match' do
|
20
|
-
assert @matcher.match
|
21
|
-
assert_equal 'mit', @matcher.match.key
|
22
|
-
end
|
23
|
-
|
24
|
-
should 'return the confidence' do
|
25
|
-
assert_equal 90, @matcher.confidence
|
26
|
-
end
|
27
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestLicenseeLicenseFile < Minitest::Test
|
4
|
-
def setup
|
5
|
-
@repo = Rugged::Repository.new(fixture_path('licenses.git'))
|
6
|
-
ref = 'bcb552d06d9cf1cd4c048a6d3bf716849c2216cc'
|
7
|
-
blob, = Rugged::Blob.to_buffer(@repo, ref)
|
8
|
-
@file = Licensee::Project::LicenseFile.new(blob)
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'content' do
|
12
|
-
should 'parse the attribution' do
|
13
|
-
assert_equal 'Copyright (c) 2014 Ben Balter', @file.attribution
|
14
|
-
end
|
15
|
-
|
16
|
-
should 'not choke on non-UTF-8 licenses' do
|
17
|
-
text = "\x91License\x93".force_encoding('windows-1251')
|
18
|
-
file = Licensee::Project::LicenseFile.new(text)
|
19
|
-
assert_equal nil, file.attribution
|
20
|
-
end
|
21
|
-
|
22
|
-
should 'create the wordset' do
|
23
|
-
assert_equal 93, @file.wordset.count
|
24
|
-
assert_equal 'the', @file.wordset.first
|
25
|
-
end
|
26
|
-
|
27
|
-
should 'create the hash' do
|
28
|
-
assert_equal 'fb278496ea4663dfcf41ed672eb7e56eb70de798', @file.hash
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'license filename scoring' do
|
33
|
-
EXPECTATIONS = {
|
34
|
-
'license' => 1.0,
|
35
|
-
'LICENCE' => 1.0,
|
36
|
-
'unLICENSE' => 1.0,
|
37
|
-
'unlicence' => 1.0,
|
38
|
-
'license.md' => 0.9,
|
39
|
-
'LICENSE.md' => 0.9,
|
40
|
-
'license.txt' => 0.9,
|
41
|
-
'COPYING' => 0.8,
|
42
|
-
'copyRIGHT' => 0.8,
|
43
|
-
'COPYRIGHT.txt' => 0.8,
|
44
|
-
'LICENSE.php' => 0.7,
|
45
|
-
'LICENSE-MIT' => 0.5,
|
46
|
-
'MIT-LICENSE.txt' => 0.5,
|
47
|
-
'mit-license-foo.md' => 0.5,
|
48
|
-
'README.txt' => 0.0
|
49
|
-
}.freeze
|
50
|
-
|
51
|
-
EXPECTATIONS.each do |filename, expected|
|
52
|
-
should "score a license named `#{filename}` as `#{expected}`" do
|
53
|
-
score = Licensee::Project::LicenseFile.name_score(filename)
|
54
|
-
assert_equal expected, score
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'LGPL scoring' do
|
60
|
-
{
|
61
|
-
'COPYING.lesser' => 1,
|
62
|
-
'copying.lesser' => 1,
|
63
|
-
'license.lesser' => 0,
|
64
|
-
'LICENSE.md' => 0,
|
65
|
-
'FOO.md' => 0
|
66
|
-
}.each do |filename, expected|
|
67
|
-
should "score a license named `#{filename}` as `#{expected}`" do
|
68
|
-
score = Licensee::Project::LicenseFile.lesser_gpl_score(filename)
|
69
|
-
assert_equal expected, score
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestLicenseePackageInfo < Minitest::Test
|
4
|
-
context 'license filename scoring' do
|
5
|
-
EXPECTATIONS = {
|
6
|
-
'licensee.gemspec' => 1.0,
|
7
|
-
'package.json' => 1.0,
|
8
|
-
'bower.json' => 0.75,
|
9
|
-
'README.md' => 0.0
|
10
|
-
}.freeze
|
11
|
-
|
12
|
-
EXPECTATIONS.each do |filename, expected|
|
13
|
-
should "score a license named `#{filename}` as `#{expected}`" do
|
14
|
-
score = Licensee::Project::PackageInfo.name_score(filename)
|
15
|
-
assert_equal expected, score
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestLicenseeReadme < Minitest::Test
|
4
|
-
context 'readme filename scoring' do
|
5
|
-
EXPECTATIONS = {
|
6
|
-
'readme' => 1.0,
|
7
|
-
'README' => 1.0,
|
8
|
-
'readme.md' => 0.9,
|
9
|
-
'README.md' => 0.9,
|
10
|
-
'readme.txt' => 0.9,
|
11
|
-
'LICENSE' => 0.0
|
12
|
-
}.freeze
|
13
|
-
|
14
|
-
EXPECTATIONS.each do |filename, expected|
|
15
|
-
should "score a readme named `#{filename}` as `#{expected}`" do
|
16
|
-
assert_equal expected, Licensee::Project::Readme.name_score(filename)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'readme content' do
|
22
|
-
should 'be blank if not license text' do
|
23
|
-
assert_license_content nil, 'There is no License in this README'
|
24
|
-
end
|
25
|
-
|
26
|
-
should 'get content after h1' do
|
27
|
-
assert_license_content 'hello world', "# License\n\nhello world"
|
28
|
-
end
|
29
|
-
|
30
|
-
should 'get content after h2' do
|
31
|
-
assert_license_content 'hello world', "## License\n\nhello world"
|
32
|
-
end
|
33
|
-
|
34
|
-
should 'be case-insensitive' do
|
35
|
-
assert_license_content 'hello world', "## LICENSE\n\nhello world"
|
36
|
-
end
|
37
|
-
|
38
|
-
should 'be british' do
|
39
|
-
assert_license_content 'hello world', "## Licence\n\nhello world"
|
40
|
-
end
|
41
|
-
|
42
|
-
should 'not include trailing content' do
|
43
|
-
readme = "## License\n\nhello world\n\n# Contributing"
|
44
|
-
assert_license_content 'hello world', readme
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class ContentHelperTestHelper
|
4
|
-
include Licensee::ContentHelper
|
5
|
-
attr_accessor :content
|
6
|
-
|
7
|
-
DEFAULT_CONTENT = <<-EOS.freeze
|
8
|
-
Copyright 2016 Ben Balter
|
9
|
-
|
10
|
-
The made
|
11
|
-
up license.
|
12
|
-
-----------
|
13
|
-
EOS
|
14
|
-
|
15
|
-
def initialize(content = nil)
|
16
|
-
@content = content || DEFAULT_CONTENT
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class TestLicenseeContentHelper < Minitest::Test
|
21
|
-
def setup
|
22
|
-
@helper = ContentHelperTestHelper.new
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'normalizing' do
|
26
|
-
should 'strips copyright' do
|
27
|
-
refute_match('Copyright', @helper.content_normalized)
|
28
|
-
refute_match('Ben Balter', @helper.content_normalized)
|
29
|
-
end
|
30
|
-
|
31
|
-
should 'downcases' do
|
32
|
-
refute_match('The', @helper.content_normalized)
|
33
|
-
assert_match('the', @helper.content_normalized)
|
34
|
-
end
|
35
|
-
|
36
|
-
should 'strips HRs' do
|
37
|
-
refute_match('---', @helper.content_normalized)
|
38
|
-
end
|
39
|
-
|
40
|
-
should 'squeeze whitespace' do
|
41
|
-
refute_match(' ', @helper.content_normalized)
|
42
|
-
end
|
43
|
-
|
44
|
-
should 'strips whitespace' do
|
45
|
-
refute_match(/\n/i, @helper.content_normalized)
|
46
|
-
end
|
47
|
-
|
48
|
-
should 'normalize the content' do
|
49
|
-
assert_equal 'the made up license.', @helper.content_normalized
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
should 'generate the hash' do
|
54
|
-
assert_equal '3c59634b9fae4396a76a978f3f6aa718ed790a9a', @helper.hash
|
55
|
-
end
|
56
|
-
|
57
|
-
should 'calculate the length' do
|
58
|
-
assert_equal 20, @helper.length
|
59
|
-
end
|
60
|
-
|
61
|
-
should 'know the max delta' do
|
62
|
-
assert_equal 1, @helper.max_delta
|
63
|
-
end
|
64
|
-
|
65
|
-
should 'build the wordset' do
|
66
|
-
assert_equal %w(the made up license).to_set, @helper.wordset
|
67
|
-
end
|
68
|
-
|
69
|
-
should 'calculate the length delta' do
|
70
|
-
other = ContentHelperTestHelper.new 'asdf'
|
71
|
-
assert_equal 16, @helper.length_delta(other)
|
72
|
-
end
|
73
|
-
|
74
|
-
should 'calculate the similarity' do
|
75
|
-
other = ContentHelperTestHelper.new 'asdf'
|
76
|
-
assert_equal 0, @helper.similarity(other)
|
77
|
-
|
78
|
-
other = ContentHelperTestHelper.new 'Not really the made up license'
|
79
|
-
assert_equal 80.0, @helper.similarity(other)
|
80
|
-
end
|
81
|
-
end
|
@@ -1,182 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestLicenseeLicense < Minitest::Test
|
4
|
-
def setup
|
5
|
-
@license = Licensee::License.new 'MIT'
|
6
|
-
end
|
7
|
-
|
8
|
-
should 'read the license body' do
|
9
|
-
assert @license.body
|
10
|
-
msg = "Expected the following to contain MIT:\n#{@license.body}"
|
11
|
-
assert @license.text =~ /MIT/, msg
|
12
|
-
end
|
13
|
-
|
14
|
-
should 'read the license body if it contains `---`' do
|
15
|
-
license = Licensee::License.new 'MIT'
|
16
|
-
content = "---\nfoo: bar\n---\nSome license\n---------\nsome text\n"
|
17
|
-
license.instance_variable_set(:@raw_content, content)
|
18
|
-
assert_equal "Some license\n---------\nsome text\n", license.body
|
19
|
-
end
|
20
|
-
|
21
|
-
should 'read the license meta' do
|
22
|
-
assert_equal 'MIT License', @license.meta['title']
|
23
|
-
end
|
24
|
-
|
25
|
-
should 'know the license path' do
|
26
|
-
path = File.expand_path('./vendor/choosealicense.com/_licenses/mit.txt')
|
27
|
-
assert_equal path, @license.path
|
28
|
-
end
|
29
|
-
|
30
|
-
should 'know the license name' do
|
31
|
-
assert_equal 'MIT License', @license.name
|
32
|
-
end
|
33
|
-
|
34
|
-
should 'know the license properties' do
|
35
|
-
assert_equal 4, @license.meta['permissions'].length
|
36
|
-
assert_equal 1, @license.meta['conditions'].length
|
37
|
-
assert_equal 1, @license.meta['limitations'].length
|
38
|
-
end
|
39
|
-
|
40
|
-
should 'know the license nickname' do
|
41
|
-
expected = 'GNU AGPLv3'
|
42
|
-
assert_equal expected, Licensee::License.find('agpl-3.0').nickname
|
43
|
-
end
|
44
|
-
|
45
|
-
should 'know the license ID' do
|
46
|
-
assert_equal 'mit', @license.key
|
47
|
-
end
|
48
|
-
|
49
|
-
should 'know the other license' do
|
50
|
-
assert_equal 'other', Licensee::License.find_by_key('other').key
|
51
|
-
end
|
52
|
-
|
53
|
-
should 'know license equality' do
|
54
|
-
assert @license == Licensee::License.new('MIT')
|
55
|
-
refute @license == Licensee::License.new('ISC')
|
56
|
-
refute @license.nil?
|
57
|
-
end
|
58
|
-
|
59
|
-
should 'know if the license is featured' do
|
60
|
-
assert @license.featured?
|
61
|
-
assert_equal TrueClass, @license.featured?.class
|
62
|
-
refute Licensee::License.new('cc0-1.0').featured?
|
63
|
-
assert_equal FalseClass, Licensee::License.new('cc0-1.0').featured?.class
|
64
|
-
end
|
65
|
-
|
66
|
-
should 'inject default meta without overriding' do
|
67
|
-
license = Licensee::License.new('agpl-3.0')
|
68
|
-
|
69
|
-
assert license.meta.key? 'featured'
|
70
|
-
assert_equal false, license.meta['featured']
|
71
|
-
|
72
|
-
assert license.meta.key? 'hidden'
|
73
|
-
assert_equal false, license.meta['hidden']
|
74
|
-
end
|
75
|
-
|
76
|
-
should 'know when the license is hidden' do
|
77
|
-
refute @license.hidden?
|
78
|
-
assert Licensee::License.new('ofl-1.1').hidden?
|
79
|
-
assert Licensee::License.new('no-license').hidden?
|
80
|
-
end
|
81
|
-
|
82
|
-
should 'parse the license parts' do
|
83
|
-
assert_equal 3, @license.send(:parts).size
|
84
|
-
end
|
85
|
-
|
86
|
-
should 'build the license URL' do
|
87
|
-
assert_equal 'http://choosealicense.com/licenses/mit/', @license.url
|
88
|
-
end
|
89
|
-
|
90
|
-
should 'return all licenses' do
|
91
|
-
assert_equal Array, Licensee::License.all.class
|
92
|
-
assert Licensee::License.all.size > 3
|
93
|
-
end
|
94
|
-
|
95
|
-
should 'strip leading newlines from the license' do
|
96
|
-
assert_equal 'M', @license.body[0]
|
97
|
-
end
|
98
|
-
|
99
|
-
should 'fail loudly for invalid licenses' do
|
100
|
-
assert_raises(Licensee::InvalidLicense) do
|
101
|
-
Licensee::License.new('foo').name
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
should "support 'other' licenses" do
|
106
|
-
license = Licensee::License.new('other')
|
107
|
-
assert_equal nil, license.content
|
108
|
-
assert_equal 'Other', license.name
|
109
|
-
assert license.hidden?
|
110
|
-
refute license.featured?
|
111
|
-
Licensee::License::YAML_DEFAULTS.each do |key, value|
|
112
|
-
assert_equal value, license.meta[key]
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
should 'know the license hash' do
|
117
|
-
assert_equal '750260c322080bab4c19fd55eb78bc73e1ae8f11', @license.hash
|
118
|
-
end
|
119
|
-
|
120
|
-
should "recognize GPL'd licenses" do
|
121
|
-
license = Licensee::License.new 'gpl-2.0'
|
122
|
-
assert license.gpl?
|
123
|
-
|
124
|
-
license = Licensee::License.new 'gpl-3.0'
|
125
|
-
assert license.gpl?
|
126
|
-
|
127
|
-
license = Licensee::License.new 'mit'
|
128
|
-
refute license.gpl?
|
129
|
-
end
|
130
|
-
|
131
|
-
describe 'name without version' do
|
132
|
-
should 'strip the version from the license name' do
|
133
|
-
expected = 'GNU Affero General Public License'
|
134
|
-
name = Licensee::License.find('agpl-3.0').name_without_version
|
135
|
-
assert_equal expected, name
|
136
|
-
|
137
|
-
expected = 'GNU General Public License'
|
138
|
-
name = Licensee::License.find('gpl-2.0').name_without_version
|
139
|
-
assert_equal expected, name
|
140
|
-
|
141
|
-
name = Licensee::License.find('gpl-3.0').name_without_version
|
142
|
-
assert_equal expected, name
|
143
|
-
end
|
144
|
-
|
145
|
-
Licensee.licenses.each do |license|
|
146
|
-
should "strip the version number from the #{license.name} license" do
|
147
|
-
assert license.name_without_version
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe 'class methods' do
|
153
|
-
should 'know license names' do
|
154
|
-
assert_equal Array, Licensee::License.keys.class
|
155
|
-
assert_equal 29, Licensee::License.keys.size
|
156
|
-
end
|
157
|
-
|
158
|
-
should 'load the licenses' do
|
159
|
-
assert_equal Array, Licensee::License.all.class
|
160
|
-
assert_equal 7, Licensee::License.all.size
|
161
|
-
assert_equal Licensee::License, Licensee::License.all.first.class
|
162
|
-
end
|
163
|
-
|
164
|
-
should 'find a license' do
|
165
|
-
assert_equal 'mit', Licensee::License.find('mit').key
|
166
|
-
assert_equal 'mit', Licensee::License.find('MIT').key
|
167
|
-
assert_equal 'mit', Licensee::License['mit'].key
|
168
|
-
end
|
169
|
-
|
170
|
-
should 'filter the licenses' do
|
171
|
-
assert_equal 29, Licensee::License.all(hidden: true).size
|
172
|
-
assert_equal 3, Licensee::License.all(featured: true).size
|
173
|
-
assert_equal 4, Licensee::License.all(featured: false).size
|
174
|
-
|
175
|
-
licenses = Licensee::License.all(featured: false, hidden: true)
|
176
|
-
assert_equal 26, licenses.size
|
177
|
-
|
178
|
-
licenses = Licensee::License.all(featured: false, hidden: false)
|
179
|
-
assert_equal 4, licenses.size
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|