Skip to content

Commit

Permalink
add support for UNLICENSE file matching (#40)
Browse files Browse the repository at this point in the history
* add support for UNLICENSE file matching

* test

* Update find.go

* gofmt

* fix unit test

Co-authored-by: Yuan (Bob) Gong <[email protected]>
Co-authored-by: Yuan Gong <[email protected]>
  • Loading branch information
3 people authored May 20, 2022
1 parent 5db6697 commit 94bf8c3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion licenses/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

var (
licenseRegexp = regexp.MustCompile(`^(?i)(LICEN(S|C)E|COPYING|README|NOTICE).*$`)
licenseRegexp = regexp.MustCompile(`^(?i)((UN)?LICEN(S|C)E|COPYING|README|NOTICE).*$`)
)

// Find returns the file path of the license for this package.
Expand Down
7 changes: 7 additions & 0 deletions licenses/find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestFind(t *testing.T) {
"testdata/readme/README.md": "foo",
"testdata/lowercase/license": "foo",
"testdata/license-apache-2.0/LICENSE-APACHE-2.0.txt": "foo",
"testdata/unlicense/UNLICENSE": "unlicense",
},
licenseTypes: map[string]Type{
"testdata/LICENSE": Notice,
Expand All @@ -47,6 +48,7 @@ func TestFind(t *testing.T) {
"testdata/readme/README.md": Notice,
"testdata/lowercase/license": Notice,
"testdata/license-apache-2.0/LICENSE-APACHE-2.0.txt": Notice,
"testdata/unlicense/UNLICENSE": Unencumbered,
},
}

Expand Down Expand Up @@ -108,6 +110,11 @@ func TestFind(t *testing.T) {
rootDir: "testdata/proprietary-license",
wantErr: regexp.MustCompile(`cannot find a known open source license for.*testdata/proprietary-license.*whose name matches regexp.*and locates up until.*testdata/proprietary-license`),
},
{
desc: "UNLICENSE",
dir: "testdata/unlicense",
wantLicensePath: filepath.Join(wd, "testdata/unlicense/UNLICENSE"),
},
} {
t.Run(test.desc, func(t *testing.T) {
if test.rootDir == "" {
Expand Down
24 changes: 24 additions & 0 deletions licenses/testdata/unlicense/UNLICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>

0 comments on commit 94bf8c3

Please sign in to comment.