Skip to content

Commit

Permalink
✨ Improved license check (#2179)
Browse files Browse the repository at this point in the history
* Add GPL-2.0 to the license check. Restructure tests to avoid duplication

* expand GPL test to be version agnostic
  • Loading branch information
spencerschrock authored Aug 19, 2022
1 parent 25fd14d commit 2920b32
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 43 deletions.
2 changes: 2 additions & 0 deletions checks/raw/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
anyExt = ".[^./]"
ofl = "ofl"
patents = "patents"
gpl = "gpl(v|-)\\d"
)

// Regex converted from
Expand All @@ -59,6 +60,7 @@ var (
{rstr: "\\w+[-_]" + license + "[^.]*", f: extensionMatch, p: extensions},
{rstr: "\\w+[-_]" + copying + "[^.]*", f: extensionMatch, p: extensions},
{rstr: ofl, f: extensionMatch, p: extensions},
{rstr: gpl, f: nil},
}
)

Expand Down
106 changes: 63 additions & 43 deletions checks/raw/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,78 +22,98 @@ func TestLicenseFileCheck(t *testing.T) {
t.Parallel()

tests := []struct {
name string
filename string
name string
filename string
extensions []string
}{
{
name: "LICENSE.md",
filename: "LICENSE.md",
},
{
name: "LICENSE",
filename: "LICENSE",
extensions: []string{
"",
".textile",
".txt",
".rst",
".PSF",
".APACHE",
".BSD",
".md",
"-MIT",
},
},
{
name: "COPYING",
filename: "COPYING",
},
{
name: "COPYING.md",
filename: "COPYING.md",
},
{
name: "LICENSE.textile",
filename: "LICENSE.textile",
},
{
name: "COPYING.textile",
filename: "COPYING.textile",
name: "LICENCE",
filename: "LICENCE",
extensions: []string{
"",
},
},
{
name: "LICENSE-MIT",
filename: "LICENSE-MIT",
},
{
name: "COPYING-MIT",
filename: "COPYING-MIT",
name: "COPYING",
filename: "COPYING",
extensions: []string{
"",
".md",
".textile",
"-MIT",
},
},
{
name: "MIT-LICENSE-MIT",
filename: "MIT-LICENSE-MIT",
extensions: []string{
"",
},
},
{
name: "MIT-COPYING",
filename: "MIT-COPYING",
},
{
name: "OFL.md",
filename: "OFL.md",
},
{
name: "OFL.textile",
filename: "OFL.textile",
extensions: []string{
"",
},
},
{
name: "OFL",
filename: "OFL",
extensions: []string{
"",
".md",
".textile",
},
},
{
name: "PATENTS",
filename: "PATENTS",
extensions: []string{
"",
".txt",
},
},
{
name: "PATENTS.txt",
filename: "PATENTS.txt",
name: "GPL",
filename: "GPL",
extensions: []string{
"v1",
"-1.0",
"v2",
"-2.0",
"v3",
"-3.0",
},
},
}

for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
s := TestLicense(tt.filename)
if !s {
t.Fail()
}
})
for _, ext := range tt.extensions {
name := tt.name + ext
t.Run(name, func(t *testing.T) {
t.Parallel()
s := TestLicense(name)
if !s {
t.Fail()
}
})
}
}
}

0 comments on commit 2920b32

Please sign in to comment.