-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support in
check-license
for conjunctive (AND) licenses. (#46801)
* Add support in `check-license` for conjunctive (AND) licenses. Conjuctive licenses were being ignored in both the `package.json` and within various LICENSE files. In the first case, this could lead to false negatives $(e.g., 'MIT AND BSD' being treated as non-compatible). In the second case, the implementation was such that only one license was returned (whichever detected license occurred later in `licenseFileStrings`). Based on the ordering of that list, this was likely to cause a false positive, because the non-compatible 'Apache-2.0' license occurs before any of the compatible licenses. Progress on #38461. * Add unit tests for checkAllCompatible * Update CHANGELOG * Tidy up docblock.
- Loading branch information
Showing
8 changed files
with
654 additions
and
32 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
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
const fs = require( 'fs' ); | ||
const path = require( 'path' ); | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
detectTypeFromLicenseText, | ||
checkAllCompatible, | ||
} from '../check-licenses'; | ||
|
||
describe( 'detectTypeFromLicenseText', () => { | ||
let licenseText; | ||
|
||
it( "should return 'Apache 2.0' when the license text is the Apache 2.0 license", () => { | ||
licenseText = fs | ||
.readFileSync( path.resolve( __dirname, 'licenses/apache2.txt' ) ) | ||
.toString(); | ||
|
||
expect( detectTypeFromLicenseText( licenseText ) ).toBe( 'Apache-2.0' ); | ||
} ); | ||
|
||
it( "should return 'BSD' when the license text is the BSD 3-clause license", () => { | ||
licenseText = fs | ||
.readFileSync( | ||
path.resolve( __dirname, 'licenses/bsd3clause.txt' ) | ||
) | ||
.toString(); | ||
|
||
expect( detectTypeFromLicenseText( licenseText ) ).toBe( 'BSD' ); | ||
} ); | ||
|
||
it( "should return 'BSD-3-Clause-W3C' when the license text is the W3C variation of the BSD 3-clause license", () => { | ||
licenseText = fs | ||
.readFileSync( path.resolve( __dirname, 'licenses/w3cbsd.txt' ) ) | ||
.toString(); | ||
|
||
expect( detectTypeFromLicenseText( licenseText ) ).toBe( | ||
'BSD-3-Clause-W3C' | ||
); | ||
} ); | ||
|
||
it( "should return 'MIT' when the license text is the MIT license", () => { | ||
licenseText = fs | ||
.readFileSync( path.resolve( __dirname, 'licenses/mit.txt' ) ) | ||
.toString(); | ||
|
||
expect( detectTypeFromLicenseText( licenseText ) ).toBe( 'MIT' ); | ||
} ); | ||
|
||
it( "should return 'Apache2 AND MIT' when the license text is Apache2 followed by MIT license", () => { | ||
licenseText = fs | ||
.readFileSync( | ||
path.resolve( __dirname, 'licenses/apache2-mit.txt' ) | ||
) | ||
.toString(); | ||
|
||
expect( detectTypeFromLicenseText( licenseText ) ).toBe( | ||
'Apache-2.0 AND MIT' | ||
); | ||
} ); | ||
} ); | ||
|
||
describe( 'checkAllCompatible', () => { | ||
it( "should return 'true' when single license is in the allowed list", () => { | ||
expect( checkAllCompatible( [ 'B' ], [ 'A', 'B', 'C' ] ) ).toBe( true ); | ||
} ); | ||
|
||
it( "should return 'false' when single license is not in the allowed list", () => { | ||
expect( checkAllCompatible( [ 'D' ], [ 'A', 'B', 'C' ] ) ).toBe( | ||
false | ||
); | ||
} ); | ||
|
||
it( "should return 'true' when all licenses are in the allowed list", () => { | ||
expect( checkAllCompatible( [ 'A', 'C' ], [ 'A', 'B', 'C' ] ) ).toBe( | ||
true | ||
); | ||
} ); | ||
|
||
it( "should return 'false' when any license is not in the allowed list", () => { | ||
expect( checkAllCompatible( [ 'A', 'D' ], [ 'A', 'B', 'C' ] ) ).toBe( | ||
false | ||
); | ||
} ); | ||
} ); |
Oops, something went wrong.
7fa9700
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in 7fa9700.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4720563862
📝 Reported issues:
specs/editor/various/publish-button.test.js