From 5531742d10fbd51c07b4488125f32f05815e6b33 Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Wed, 20 Jan 2016 10:20:04 -0500 Subject: [PATCH 1/3] better error output --- spec/license_category_spec.rb | 42 +++++++++++++++++---------------- spec/license_fields_spec.rb | 14 ++++++----- spec/license_meta_spec.rb | 44 ++++++++++++++++++----------------- spec/license_rules_spec.rb | 26 +++++++++++---------- spec/license_spec.rb | 32 +++++++++++++------------ 5 files changed, 84 insertions(+), 74 deletions(-) diff --git a/spec/license_category_spec.rb b/spec/license_category_spec.rb index 423bb14..e90f6f4 100644 --- a/spec/license_category_spec.rb +++ b/spec/license_category_spec.rb @@ -1,29 +1,31 @@ require 'spec_helper' -families.each do |family| - describe "the #{family} family" do - family_licenses = licenses.select { |l| l["family"] == family } - primary = family_licenses.select { |l| l["variant"] == false } - variants = family_licenses.select { |l| l["variant"] == true } +describe "license categories" do + families.each do |family| + context "the #{family} family" do + family_licenses = licenses.select { |l| l["family"] == family } + primary = family_licenses.select { |l| l["variant"] == false } + variants = family_licenses.select { |l| l["variant"] == true } - it "should only have one primary license" do - expect(primary.count).to eql(1) - end + it "should only have one primary license" do + expect(primary.count).to eql(1) + end - it "all other licenses should be variants" do - expected = family_licenses.count - 1 - expect(variants.count).to eql(expected) - end + it "all other licenses should be variants" do + expected = family_licenses.count - 1 + expect(variants.count).to eql(expected) + end - family_licenses.each do |license| - describe "the #{license["title"]} license" do - it "should have a unique slug" do - dupes = family_licenses.select { |l| l["tab-slug"] == license["tab-slug"] }.count - expect(dupes).to eql(1) - end + family_licenses.each do |license| + context "the #{license["title"]} license" do + it "should have a unique slug" do + dupes = family_licenses.select { |l| l["tab-slug"] == license["tab-slug"] }.count + expect(dupes).to eql(1) + end - it "should have a valid tab-slug" do - expect(license["tab-slug"]).to match(/[a-z0-9_]/) + it "should have a valid tab-slug" do + expect(license["tab-slug"]).to match(/[a-z0-9_]/) + end end end end diff --git a/spec/license_fields_spec.rb b/spec/license_fields_spec.rb index 5ea79d6..ef2ae6b 100644 --- a/spec/license_fields_spec.rb +++ b/spec/license_fields_spec.rb @@ -1,11 +1,13 @@ require 'spec_helper' -licenses.each do |license| - describe "The #{license["title"]} license" do - it "should only contain supported fields" do - matches = license["content"].scan /\[([a-z]+)\]/ - extra_fields = matches.flatten - fields.map { |f| f["name"] } - expect(extra_fields).to be_empty +describe "license fillable fields" do + licenses.each do |license| + context "The #{license["title"]} license" do + it "should only contain supported fillable fields" do + matches = license["content"].scan(/\[([a-z]+)\]/) + extra_fields = matches.flatten - fields.map { |f| f["name"] } + expect(extra_fields).to be_empty + end end end end diff --git a/spec/license_meta_spec.rb b/spec/license_meta_spec.rb index 3649cc8..e0f2b8e 100644 --- a/spec/license_meta_spec.rb +++ b/spec/license_meta_spec.rb @@ -1,31 +1,33 @@ require 'spec_helper' -licenses.each do |license| +describe "license meta" do + licenses.each do |license| - # Manually load the raw license so we don't get thed defaults - raw_fields = SafeYAML.load_file("_licenses/#{license["id"]}.txt") + # Manually load the raw license so we don't get thed defaults + raw_fields = SafeYAML.load_file("_licenses/#{license["id"]}.txt") - describe "The #{license["title"]} license" do - it "should only contain supported meta fields" do - extra_fields = raw_fields.keys - meta.map { |m| m["name"] } - expect(extra_fields).to be_empty - end + context "The #{license["title"]} license" do + it "should only contain supported meta fields" do + extra_fields = raw_fields.keys - meta.map { |m| m["name"] } + expect(extra_fields).to be_empty + end - it "should contain all required meta fields" do - required = meta.select { |m| m["required"] }.map { |m| m["name"] } - missing = required - raw_fields.keys - expect(missing).to be_empty - end - - if license["family"] - it "should contain the required license variant fields" do - missing = ["family", "tab-slug"] - license.keys + it "should contain all required meta fields" do + required = meta.select { |m| m["required"] }.map { |m| m["name"] } + missing = required - raw_fields.keys expect(missing).to be_empty end - else - it "should not contain license family specific fields" do - extra = ["variant", "family", "tab-slug"].select{ |f| raw_fields.keys.include?(f) } - expect(extra).to be_empty + + if license["family"] + it "should contain the required license variant fields" do + missing = ["family", "tab-slug"] - license.keys + expect(missing).to be_empty + end + else + it "should not contain license family specific fields" do + extra = ["variant", "family", "tab-slug"].select{ |f| raw_fields.keys.include?(f) } + expect(extra).to be_empty + end end end end diff --git a/spec/license_rules_spec.rb b/spec/license_rules_spec.rb index 5049bea..c3093da 100644 --- a/spec/license_rules_spec.rb +++ b/spec/license_rules_spec.rb @@ -1,22 +1,24 @@ require 'spec_helper' -licenses.each do |license| +describe "license rules" do + licenses.each do |license| - groups = rules.keys + groups = rules.keys - describe "The #{license["title"]} license" do - groups.each do |group| + context "The #{license["title"]} license" do + groups.each do |group| - valid_tags = rules[group].map { |r| r["tag"] } + valid_tags = rules[group].map { |r| r["tag"] } - describe "the #{group} group" do - it "should exist" do - expect(license[group]).to_not be_nil - end + context "the #{group} group" do + it "should exist" do + expect(license[group]).to_not be_nil + end - it "should only contain valid tags" do - extra = license[group] - valid_tags - expect(extra).to be_empty + it "should only contain valid tags" do + extra = license[group] - valid_tags + expect(extra).to be_empty + end end end end diff --git a/spec/license_spec.rb b/spec/license_spec.rb index 6bf43b0..e60cb64 100644 --- a/spec/license_spec.rb +++ b/spec/license_spec.rb @@ -1,26 +1,28 @@ require 'spec_helper' -licenses.each do |license| +describe "licenses" do + licenses.each do |license| - # "No license" isn't really a license, so no need to test - next if license["id"] == "no-license" + # "No license" isn't really a license, so no need to test + next if license["id"] == "no-license" - describe "The #{license["title"]} license" do + context "The #{license["title"]} license" do - let(:id) { license["id"] } + let(:id) { license["id"] } - it "has an SPDX ID" do - expect(spdx_ids).to include(id) - end + it "has an SPDX ID" do + expect(spdx_ids).to include(id) + end - it "uses its SPDX name" do - spdx = find_spdx(id) - expect(spdx[1]["name"].gsub(/ only$/,"")).to eql(license["title"]) - end + it "uses its SPDX name" do + spdx = find_spdx(id) + expect(spdx[1]["name"].gsub(/ only$/,"")).to eql(license["title"]) + end - context "industry approval" do - it "should be approved by OSI or FSF or OD" do - expect(approved_licenses).to include(id), "See https://git.io/vzCTV." + context "industry approval" do + it "should be approved by OSI or FSF or OD" do + expect(approved_licenses).to include(id), "See https://git.io/vzCTV." + end end end end From ed908356e7b9b53625b7bcb063242fb7958fefa6 Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Wed, 20 Jan 2016 10:37:44 -0500 Subject: [PATCH 2/3] make licenses hidden by default --- _config.yml | 4 ++-- _licenses/afl-3.0.txt | 2 -- _licenses/agpl-3.0.txt | 1 + _licenses/apache-2.0.txt | 1 + _licenses/artistic-2.0.txt | 1 + _licenses/bsd-2-clause.txt | 1 + _licenses/bsd-3-clause-clear.txt | 1 - _licenses/bsd-3-clause.txt | 1 + _licenses/cc0-1.0.txt | 1 + _licenses/epl-1.0.txt | 1 + _licenses/gpl-2.0.txt | 1 + _licenses/gpl-3.0.txt | 1 + _licenses/isc.txt | 1 + _licenses/lgpl-2.1.txt | 1 + _licenses/lgpl-3.0.txt | 1 + _licenses/mit.txt | 1 + _licenses/mpl-2.0.txt | 1 + _licenses/ms-pl.txt | 1 - _licenses/ms-rl.txt | 1 - _licenses/no-license.txt | 1 + _licenses/ofl-1.1.txt | 1 - _licenses/osl-3.0.txt | 1 - _licenses/unlicense.txt | 1 + _licenses/wtfpl.txt | 1 - spec/license_shown_spec.rb | 37 ++++++++++++++++++++++++++++++++ spec/license_spec.rb | 1 + spec/spec_helper.rb | 16 +++++++++++--- 27 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 spec/license_shown_spec.rb diff --git a/_config.yml b/_config.yml index 8a739c5..e96f3da 100644 --- a/_config.yml +++ b/_config.yml @@ -18,7 +18,7 @@ defaults: values: layout: license featured: false - hidden: false + hidden: true variant: false exclude: @@ -41,7 +41,7 @@ gems: - jekyll-sitemap - jekyll-redirect-from - jekyll-seo-tag - + sass: sass_dir: _sass style: :compressed diff --git a/_licenses/afl-3.0.txt b/_licenses/afl-3.0.txt index 811a42c..ee027d7 100644 --- a/_licenses/afl-3.0.txt +++ b/_licenses/afl-3.0.txt @@ -4,8 +4,6 @@ source: http://opensource.org/licenses/afl-3.0 description: The Academic Free License is a variant of the Open Source License that does not require that the source code of derivative works be disclosed. It contains explicit copyright and patent grants and reserves trademark rights in the author. -hidden: true - how: Create a text file (typically named LICENSE or LICENSE.txt) in the root of your source code and copy the text of the license into the file. Files licensed under OSL 3.0 must also include the notice "Licensed under the Academic Free License version 3.0" adjacent to the copyright notice. required: diff --git a/_licenses/agpl-3.0.txt b/_licenses/agpl-3.0.txt index 7555289..fceb4f7 100644 --- a/_licenses/agpl-3.0.txt +++ b/_licenses/agpl-3.0.txt @@ -30,6 +30,7 @@ forbidden: - no-liability - no-sublicense +hidden: false --- GNU AFFERO GENERAL PUBLIC LICENSE diff --git a/_licenses/apache-2.0.txt b/_licenses/apache-2.0.txt index c95d2ec..8a99d45 100644 --- a/_licenses/apache-2.0.txt +++ b/_licenses/apache-2.0.txt @@ -27,6 +27,7 @@ forbidden: - trademark-use - no-liability +hidden: false --- Apache License diff --git a/_licenses/artistic-2.0.txt b/_licenses/artistic-2.0.txt index 033d9dc..52d40f1 100644 --- a/_licenses/artistic-2.0.txt +++ b/_licenses/artistic-2.0.txt @@ -22,6 +22,7 @@ forbidden: - no-liability - trademark-use +hidden: false --- The Artistic License 2.0 diff --git a/_licenses/bsd-2-clause.txt b/_licenses/bsd-2-clause.txt index 184b146..781972b 100644 --- a/_licenses/bsd-2-clause.txt +++ b/_licenses/bsd-2-clause.txt @@ -24,6 +24,7 @@ permitted: forbidden: - no-liability +hidden: false --- Copyright (c) [year], [fullname] diff --git a/_licenses/bsd-3-clause-clear.txt b/_licenses/bsd-3-clause-clear.txt index cf7916a..a597f9d 100644 --- a/_licenses/bsd-3-clause-clear.txt +++ b/_licenses/bsd-3-clause-clear.txt @@ -1,7 +1,6 @@ --- title: BSD 3-clause Clear License nickname: Clear BSD -hidden: true family: BSD tab-slug: bsd-3-clear diff --git a/_licenses/bsd-3-clause.txt b/_licenses/bsd-3-clause.txt index c33c270..6c60074 100644 --- a/_licenses/bsd-3-clause.txt +++ b/_licenses/bsd-3-clause.txt @@ -23,6 +23,7 @@ permitted: forbidden: - no-liability +hidden: false --- Copyright (c) [year], [fullname] diff --git a/_licenses/cc0-1.0.txt b/_licenses/cc0-1.0.txt index bd99028..bdf7fd9 100644 --- a/_licenses/cc0-1.0.txt +++ b/_licenses/cc0-1.0.txt @@ -25,6 +25,7 @@ forbidden: required: [] +hidden: false --- CC0 1.0 Universal diff --git a/_licenses/epl-1.0.txt b/_licenses/epl-1.0.txt index b486187..b76591f 100644 --- a/_licenses/epl-1.0.txt +++ b/_licenses/epl-1.0.txt @@ -30,6 +30,7 @@ permitted: forbidden: - no-liability +hidden: false --- Eclipse Public License - v 1.0 diff --git a/_licenses/gpl-2.0.txt b/_licenses/gpl-2.0.txt index eaac12e..83f1069 100644 --- a/_licenses/gpl-2.0.txt +++ b/_licenses/gpl-2.0.txt @@ -29,6 +29,7 @@ forbidden: - no-liability - no-sublicense +hidden: false --- GNU GENERAL PUBLIC LICENSE diff --git a/_licenses/gpl-3.0.txt b/_licenses/gpl-3.0.txt index 6734952..eb5d3bb 100644 --- a/_licenses/gpl-3.0.txt +++ b/_licenses/gpl-3.0.txt @@ -28,6 +28,7 @@ permitted: forbidden: - no-liability +hidden: false --- GNU GENERAL PUBLIC LICENSE diff --git a/_licenses/isc.txt b/_licenses/isc.txt index ad1d497..cdcbae7 100644 --- a/_licenses/isc.txt +++ b/_licenses/isc.txt @@ -21,6 +21,7 @@ permitted: forbidden: - no-liability +hidden: false --- Copyright (c) [year], [fullname] diff --git a/_licenses/lgpl-2.1.txt b/_licenses/lgpl-2.1.txt index c2759c4..88ee117 100644 --- a/_licenses/lgpl-2.1.txt +++ b/_licenses/lgpl-2.1.txt @@ -29,6 +29,7 @@ permitted: forbidden: - no-liability +hidden: false --- GNU LESSER GENERAL PUBLIC LICENSE diff --git a/_licenses/lgpl-3.0.txt b/_licenses/lgpl-3.0.txt index ca29187..2b528a5 100644 --- a/_licenses/lgpl-3.0.txt +++ b/_licenses/lgpl-3.0.txt @@ -28,6 +28,7 @@ permitted: forbidden: - no-liability +hidden: false --- GNU LESSER GENERAL PUBLIC LICENSE diff --git a/_licenses/mit.txt b/_licenses/mit.txt index e478942..b1c79d6 100644 --- a/_licenses/mit.txt +++ b/_licenses/mit.txt @@ -20,6 +20,7 @@ permitted: forbidden: - no-liability +hidden: false --- The MIT License (MIT) diff --git a/_licenses/mpl-2.0.txt b/_licenses/mpl-2.0.txt index 0398907..ae6ac56 100644 --- a/_licenses/mpl-2.0.txt +++ b/_licenses/mpl-2.0.txt @@ -23,6 +23,7 @@ forbidden: - no-liability - trademark-use +hidden: false --- Mozilla Public License Version 2.0 diff --git a/_licenses/ms-pl.txt b/_licenses/ms-pl.txt index e47b8e7..622baa3 100644 --- a/_licenses/ms-pl.txt +++ b/_licenses/ms-pl.txt @@ -1,6 +1,5 @@ --- title: Microsoft Public License -hidden: true source: http://opensource.org/licenses/ms-pl diff --git a/_licenses/ms-rl.txt b/_licenses/ms-rl.txt index ee6fb8f..5abb149 100644 --- a/_licenses/ms-rl.txt +++ b/_licenses/ms-rl.txt @@ -1,6 +1,5 @@ --- title: Microsoft Reciprocal License -hidden: true source: http://opensource.org/licenses/ms-pl diff --git a/_licenses/no-license.txt b/_licenses/no-license.txt index b6bbe9c..5a0d35b 100644 --- a/_licenses/no-license.txt +++ b/_licenses/no-license.txt @@ -20,6 +20,7 @@ forbidden: - distribution - sublicense +hidden: false --- Copyright [year] [fullname] diff --git a/_licenses/ofl-1.1.txt b/_licenses/ofl-1.1.txt index 4d353ec..fb406c6 100644 --- a/_licenses/ofl-1.1.txt +++ b/_licenses/ofl-1.1.txt @@ -1,7 +1,6 @@ --- title: SIL Open Font License 1.1 redirect_from: /licenses/ofl/ -hidden: true source: http://scripts.sil.org/OFL_web description: The Open Font License (OFL) is maintained by SIL International. It attempts to be a compromise between the values of the free software and typeface design communities. It is used for almost all open source font projects, including those by Adobe, Google and Mozilla. diff --git a/_licenses/osl-3.0.txt b/_licenses/osl-3.0.txt index 85aaba4..bedf3e2 100644 --- a/_licenses/osl-3.0.txt +++ b/_licenses/osl-3.0.txt @@ -1,6 +1,5 @@ --- title: Open Software License 3.0 -hidden: true source: http://opensource.org/licenses/OSL-3.0 description: OSL 3.0 is a copyleft license that does not require reciprocal licensing on linked works. It also provides an express grant of patent rights from contributors to users, with a termination clause triggered if a user files a patent infringement lawsuit. diff --git a/_licenses/unlicense.txt b/_licenses/unlicense.txt index 633ae68..199cdc7 100644 --- a/_licenses/unlicense.txt +++ b/_licenses/unlicense.txt @@ -22,6 +22,7 @@ forbidden: required: [] +hidden: false --- This is free and unencumbered software released into the public domain. diff --git a/_licenses/wtfpl.txt b/_licenses/wtfpl.txt index 6d258ef..3e9c79a 100644 --- a/_licenses/wtfpl.txt +++ b/_licenses/wtfpl.txt @@ -1,6 +1,5 @@ --- title: "Do What The F*ck You Want To Public License" -hidden: true source: http://www.wtfpl.net/ description: The easiest licence out there. It gives the user permissions to do whatever they want with your code. diff --git a/spec/license_shown_spec.rb b/spec/license_shown_spec.rb new file mode 100644 index 0000000..1a9cde3 --- /dev/null +++ b/spec/license_shown_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe "shown licenses" do + + # Whitelist of popular licenses that are shown (non-hidden) + # Note: most new licenses that are added should be hidden by default + SHOWN_LICENSES = %w[ + agpl-3.0 + apache-2.0 + artistic-2.0 + bsd-2-clause + bsd-3-clause + cc0-1.0 + epl-1.0 + gpl-2.0 + gpl-3.0 + isc + lgpl-2.1 + lgpl-3.0 + mit + mpl-2.0 + no-license + unlicense + ] + + it "has the expected number of shown licenses" do + expect(shown_licenses.count).to eql(16) + end + + shown_licenses.each do |license| + context "the #{license["title"]} license" do + it "is whitelisted to be shown" do + expect(SHOWN_LICENSES).to include(license["id"]) + end + end + end +end diff --git a/spec/license_spec.rb b/spec/license_spec.rb index e60cb64..a8f59e1 100644 --- a/spec/license_spec.rb +++ b/spec/license_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe "licenses" do + licenses.each do |license| # "No license" isn't really a license, so no need to test diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 55e7673..6341223 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,12 +19,22 @@ def config end def licenses - site.collections["licenses"].docs.map do |license| - id = File.basename(license.basename, ".txt") - license.to_liquid.merge("id" => id) + $licenses ||= begin + site.collections["licenses"].docs.map do |license| + id = File.basename(license.basename, ".txt") + license.to_liquid.merge("id" => id) + end end end +def hidden_licenses + licenses.select { |l| l["hidden"] } +end + +def shown_licenses + licenses.select { |l| !l["hidden"] } +end + def license_ids licenses.map { |l| l["id"] } end From ad1c2d9684c87ff6797755d7aaad338377b4e6b4 Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Wed, 20 Jan 2016 10:42:36 -0500 Subject: [PATCH 3/3] Catch invalid SPDX IDs when looking for the SPPX name, fixes #322 --- spec/license_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/license_spec.rb b/spec/license_spec.rb index e60cb64..aedd109 100644 --- a/spec/license_spec.rb +++ b/spec/license_spec.rb @@ -16,6 +16,7 @@ describe "licenses" do it "uses its SPDX name" do spdx = find_spdx(id) + expect(spdx).to_not be_nil expect(spdx[1]["name"].gsub(/ only$/,"")).to eql(license["title"]) end