File tree Expand file tree Collapse file tree 2 files changed +229
-2
lines changed
lib/src/license_detection Expand file tree Collapse file tree 2 files changed +229
-2
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ const _defaultSpdxLicenseDir = 'lib/src/third_party/spdx/licenses';
2525
2626// Load corpus licenses.
2727List <License >? _cachedLicenses;
28- Future <List <License >> _getDefaultLicenses () async {
28+ @visibleForTesting
29+ Future <List <License >> listDefaultLicenses () async {
2930 if (_cachedLicenses == null ) {
3031 final uri = await Isolate .resolvePackageUri (
3132 Uri .parse (_defaultSpdxLicenseDir.replaceFirst ('lib/' , 'package:pana/' )),
@@ -69,7 +70,7 @@ Future<Result> detectLicense(String text, double threshold) async {
6970
7071 final possibleLicenses = filter (
7172 unknownLicense.tokenFrequency,
72- await _getDefaultLicenses (),
73+ await listDefaultLicenses (),
7374 ).map ((e) => LicenseWithNGrams .parse (e, granularity));
7475 var result = < LicenseMatch > [];
7576
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+ // for details. All rights reserved. Use of this source code is governed by a
3+ // BSD-style license that can be found in the LICENSE file.
4+
5+ import 'package:pana/src/license.dart' ;
6+ import 'package:pana/src/license_detection/license_detector.dart' ;
7+ import 'package:test/test.dart' ;
8+
9+ void main () {
10+ group ('License coverage' , () {
11+ test ('Coverage of all reference text' , () async {
12+ final allLicenses = await listDefaultLicenses ();
13+ expect (allLicenses, hasLength (greaterThan (30 )));
14+ for (final license in allLicenses) {
15+ final detected = await detectLicenseInContent (
16+ license.content,
17+ relativePath: 'LICENSE' ,
18+ );
19+ // TODO: fix detection and return at least one match (https://github.com/dart-lang/pana/issues/1484)
20+ if (license.identifier == 'SSH-OpenSSH' ) {
21+ continue ;
22+ }
23+ final match = detected
24+ .where ((l) => l.spdxIdentifier == license.identifier)
25+ .single;
26+
27+ // TODO: fix coverage calculation as 1:1 matches shouldn't have too many ranges (https://github.com/dart-lang/pana/issues/1481)
28+ final excessiveLicenses = [
29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SCPL' ,
195+ 'SCEA' ,
196+ 'SGI-B-1.0' ,
197+ 'SGI-B-1.1' ,
198+ 'SHL-0.5' ,
199+ 'SHL-0.5' ,
200+ 'SHL-0.51' ,
201+ 'SHL-0.51' ,
202+ 'SISSL' ,
203+ 'SNIA' ,
204+ 'SPL-1.0' ,
205+ 'SSPL-1.0' ,
206+ 'SSPL-1.0' ,
207+ 'Sendmail' ,
208+ 'Sendmail-8.23' ,
209+ 'SugarCRM-1.1.3' ,
210+ 'TAPR-OHL-1.0' ,
211+ 'UCL-1.0' ,
212+ 'Unicode-TOU' ,
213+ 'Watcom-1.0' ,
214+ 'copyleft-next-0.3.0' ,
215+ 'copyleft-next-0.3.1' ,
216+ 'etalab-2.0' ,
217+ 'gSOAP-1.3b' ,
218+ ];
219+ if (excessiveLicenses.contains (license.identifier)) {
220+ continue ;
221+ }
222+ expect (match.range! .coverages, hasLength (lessThan (50 )));
223+ }
224+ });
225+ });
226+ }
You can’t perform that action at this time.
0 commit comments