-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more SPDX unit tests to illustrate matching behavior
- Loading branch information
1 parent
bbed6f3
commit ed624db
Showing
5 changed files
with
303 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
fail_on_severity: critical | ||
allow_licenses: | ||
- 'BSD' | ||
- 'GPL 2' | ||
- 'BSD-3-Clause' | ||
- 'GPL-2.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,267 @@ | ||
import {expect, jest, test} from '@jest/globals' | ||
import {expect, test} from '@jest/globals' | ||
import * as spdx from '../src/spdx' | ||
|
||
test('satisfiesAny', () => { | ||
const units = [ | ||
{ | ||
candidate: 'MIT', | ||
licenses: ['MIT'], | ||
expected: true | ||
}, | ||
{ | ||
candidate: 'MIT OR Apache-2.0', | ||
licenses: ['MIT', 'Apache-2.0'], | ||
expected: true | ||
}, | ||
{ | ||
candidate: '(MIT AND ISC) OR Apache-2.0', | ||
licenses: ['MIT', 'Apache-2.0'], | ||
expected: true | ||
}, | ||
{ | ||
candidate: 'MIT AND Apache-2.0', | ||
licenses: ['MIT', 'Apache-2.0'], | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'MIT AND BSD-3-Clause', | ||
licenses: ['MIT', 'Apache-2.0'], | ||
expected: false | ||
}, | ||
|
||
// missing params, case sensitivity, syntax problems, | ||
// or unknown licenses will return 'false' | ||
{ | ||
candidate: 'MIT OR', | ||
licenses: ['MIT', 'Apache-2.0'], | ||
expected: false | ||
}, | ||
{ | ||
candidate: '', | ||
licenses: ['MIT', 'Apache-2.0'], | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'MIT OR (Apache-2.0 AND ISC)', | ||
licenses: [], | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'MIT AND (ISC', | ||
licenses: ['MIT', 'Apache-2.0'], | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'MIT OR ISC', | ||
licenses: ['MiT'], | ||
expected: false | ||
} | ||
] | ||
|
||
for (const unit of units) { | ||
let got: boolean = spdx.satisfiesAny(unit.candidate, unit.licenses) | ||
if (got != unit.expected) { | ||
console.log( | ||
`failing unit test inputs: candidate(${unit.candidate}) licenses(${unit.licenses})` | ||
) | ||
} | ||
expect(got).toBe(unit.expected) | ||
} | ||
}) | ||
|
||
test('satisfiesAll', () => { | ||
const units = [ | ||
{ | ||
candidate: 'MIT', | ||
licenses: ['MIT'], | ||
expected: true | ||
}, | ||
{ | ||
candidate: 'Apache-2.0', | ||
licenses: ['MIT', 'ISC', 'Apache-2.0'], | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'MIT AND Apache-2.0', | ||
licenses: ['MIT', 'Apache-2.0'], | ||
expected: true | ||
}, | ||
{ | ||
candidate: '(MIT OR ISC) AND Apache-2.0', | ||
licenses: ['MIT', 'Apache-2.0'], | ||
expected: true | ||
}, | ||
{ | ||
candidate: 'MIT OR BSD-3-Clause', | ||
licenses: ['MIT', 'Apache-2.0'], | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'BSD-3-Clause OR ISC', | ||
licenses: ['MIT', 'Apache-2.0'], | ||
expected: false | ||
}, | ||
{ | ||
candidate: '(MIT AND ISC) OR Apache-2.0', | ||
licenses: ['MIT', 'ISC'], | ||
expected: true | ||
}, | ||
|
||
// missing params, case sensitivity, syntax problems, | ||
// or unknown licenses will return 'false' | ||
{ | ||
candidate: 'MIT OR', | ||
licenses: ['MIT', 'Apache-2.0'], | ||
expected: false | ||
}, | ||
{ | ||
candidate: '', | ||
licenses: ['MIT', 'Apache-2.0'], | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'MIT OR (Apache-2.0 AND ISC)', | ||
licenses: [], | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'MIT AND (ISC', | ||
licenses: ['MIT', 'Apache-2.0'], | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'MIT OR ISC', | ||
licenses: ['MiT'], | ||
expected: false | ||
} | ||
] | ||
|
||
for (const unit of units) { | ||
let got: boolean = spdx.satisfiesAll(unit.candidate, unit.licenses) | ||
if (got != unit.expected) { | ||
console.log( | ||
`failing unit test inputs: candidate(${unit.candidate}) licenses(${unit.licenses})` | ||
) | ||
} | ||
expect(got).toBe(unit.expected) | ||
} | ||
}) | ||
|
||
test('satisfies', () => { | ||
expect(spdx.satisfies('MIT', 'MIT')).toBe(true) | ||
const units = [ | ||
{ | ||
candidate: 'MIT', | ||
constraint: 'MIT', | ||
expected: true | ||
}, | ||
{ | ||
candidate: 'Apache-2.0', | ||
constraint: 'MIT', | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'MIT OR Apache-2.0', | ||
constraint: 'MIT', | ||
expected: true | ||
}, | ||
{ | ||
candidate: 'MIT OR Apache-2.0', | ||
constraint: 'Apache-2.0', | ||
expected: true | ||
}, | ||
{ | ||
candidate: 'MIT OR Apache-2.0', | ||
constraint: 'BSD-3-Clause', | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'MIT OR Apache-2.0', | ||
constraint: 'Apache-2.0 OR BSD-3-Clause', | ||
expected: true | ||
}, | ||
{ | ||
candidate: 'MIT AND Apache-2.0', | ||
constraint: 'MIT AND Apache-2.0', | ||
expected: true | ||
}, | ||
{ | ||
candidate: 'MIT OR Apache-2.0', | ||
constraint: 'MIT AND Apache-2.0', | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'ISC OR (MIT AND Apache-2.0)', | ||
constraint: 'MIT AND Apache-2.0', | ||
expected: true | ||
}, | ||
|
||
// missing params, case sensitivity, syntax problems, | ||
// or unknown licenses will return 'false' | ||
{ | ||
candidate: 'MIT', | ||
constraint: 'MiT', | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'MIT AND (ISC OR', | ||
constraint: 'MIT', | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'MIT OR ISC OR Apache-2.0', | ||
constraint: '', | ||
expected: false | ||
}, | ||
{ | ||
candidate: '', | ||
constraint: '(BSD-3-Clause AND ISC) OR MIT', | ||
expected: false | ||
} | ||
] | ||
|
||
for (const unit of units) { | ||
let got: boolean = spdx.satisfies(unit.candidate, unit.constraint) | ||
if (got != unit.expected) { | ||
console.log( | ||
`failing unit test inputs: candidateExpr(${unit.candidate}) constraintExpr(${unit.constraint})` | ||
) | ||
} | ||
expect(got).toBe(unit.expected) | ||
} | ||
}) | ||
|
||
test('isValid', () => { | ||
expect(spdx.isValid('MIT')).toBe(true) | ||
expect(spdx.isValid('FOOBARBAZ')).toBe(false) | ||
const units = [ | ||
{ | ||
candidate: 'MIT', | ||
expected: true | ||
}, | ||
{ | ||
candidate: 'MIT AND BSD-3-Clause', | ||
expected: true | ||
}, | ||
{ | ||
candidate: '(MIT AND ISC) OR BSD-3-Clause', | ||
expected: true | ||
}, | ||
{ | ||
candidate: 'NOASSERTION', | ||
expected: false | ||
}, | ||
{ | ||
candidate: 'Foobar', | ||
expected: false | ||
}, | ||
{ | ||
candidate: '', | ||
expected: false | ||
} | ||
] | ||
for (const unit of units) { | ||
let got: boolean = spdx.isValid(unit.candidate) | ||
if (got != unit.expected) { | ||
console.log(`failing unit test inputs: candidateExpr(${unit.candidate})`) | ||
} | ||
expect(got).toBe(unit.expected) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters