@@ -36,6 +36,9 @@ void main() {
36
36
group ('packages check licenses' , () {
37
37
const commandArguments = ['packages' , 'check' , 'licenses' ];
38
38
39
+ const forbiddenArgument = '--forbidden' ;
40
+ const allowedArgument = '--allowed' ;
41
+
39
42
late Progress progress;
40
43
41
44
setUpAll (() {
@@ -94,10 +97,10 @@ void main() {
94
97
});
95
98
96
99
group (
97
- 'reports licenses' ,
100
+ 'reports licenses correctly ' ,
98
101
() {
99
102
test (
100
- '''correctly when there is a single hosted direct dependency and license''' ,
103
+ '''when there is a single hosted direct dependency and license''' ,
101
104
withRunner (
102
105
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
103
106
final tempDirectory = Directory .systemTemp.createTempSync ();
@@ -128,7 +131,7 @@ void main() {
128
131
);
129
132
130
133
test (
131
- '''correctly when there are multiple hosted direct dependency and licenses''' ,
134
+ '''when there are multiple hosted direct dependency and licenses''' ,
132
135
withRunner (
133
136
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
134
137
final tempDirectory = Directory .systemTemp.createTempSync ();
@@ -165,6 +168,44 @@ void main() {
165
168
expect (result, equals (ExitCode .success.code));
166
169
}),
167
170
);
171
+
172
+ test (
173
+ '''when both allowed and forbidden are specified but left empty''' ,
174
+ withRunner (
175
+ (commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
176
+ final tempDirectory = Directory .systemTemp.createTempSync ();
177
+ addTearDown (() => tempDirectory.deleteSync (recursive: true ));
178
+
179
+ File (path.join (tempDirectory.path, pubspecLockBasename))
180
+ .writeAsStringSync (_validPubspecLockContent);
181
+
182
+ when (() => logger.progress (any ())).thenReturn (progress);
183
+
184
+ final result = await commandRunner.run (
185
+ [
186
+ ...commandArguments,
187
+ allowedArgument,
188
+ '' ,
189
+ forbiddenArgument,
190
+ '' ,
191
+ tempDirectory.path,
192
+ ],
193
+ );
194
+
195
+ verify (
196
+ () => progress.update (
197
+ 'Collecting licenses from 1 out of 1 package' ,
198
+ ),
199
+ ).called (1 );
200
+ verify (
201
+ () => progress.complete (
202
+ '''Retrieved 1 license from 1 package of type: MIT (1).''' ,
203
+ ),
204
+ ).called (1 );
205
+
206
+ expect (result, equals (ExitCode .success.code));
207
+ }),
208
+ );
168
209
},
169
210
);
170
211
@@ -637,8 +678,6 @@ void main() {
637
678
});
638
679
639
680
group ('allowed' , () {
640
- const allowedArgument = '--allowed' ;
641
-
642
681
test (
643
682
'warns when a license is not recognized' ,
644
683
withRunner (
@@ -744,6 +783,50 @@ void main() {
744
783
}),
745
784
);
746
785
786
+ test (
787
+ 'when a single license is not allowed and forbidden is left empty' ,
788
+ withRunner (
789
+ (commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
790
+ final tempDirectory = Directory .systemTemp.createTempSync ();
791
+ addTearDown (() => tempDirectory.deleteSync (recursive: true ));
792
+
793
+ File (path.join (tempDirectory.path, pubspecLockBasename))
794
+ .writeAsStringSync (_validMultiplePubspecLockContent);
795
+
796
+ when (() => logger.progress (any ())).thenReturn (progress);
797
+
798
+ const dependency1Name = 'very_good_test_runner' ;
799
+ when (() => pubLicense.getLicense (dependency1Name))
800
+ .thenAnswer ((_) => Future .value ({'MIT' }));
801
+ final license1LinkedMessage = link (
802
+ uri: pubLicenseUri (dependency1Name),
803
+ message: 'MIT' ,
804
+ );
805
+
806
+ const dependency2Name = 'cli_completion' ;
807
+ when (() => pubLicense.getLicense (dependency2Name))
808
+ .thenAnswer ((_) => Future .value ({'BSD' }));
809
+
810
+ await commandRunner.run (
811
+ [
812
+ ...commandArguments,
813
+ allowedArgument,
814
+ 'BSD' ,
815
+ forbiddenArgument,
816
+ '' ,
817
+ tempDirectory.path,
818
+ ],
819
+ );
820
+
821
+ final errorMessage =
822
+ '''1 dependency has a banned license: $dependency1Name ($license1LinkedMessage ).''' ;
823
+
824
+ verify (
825
+ () => logger.err (errorMessage),
826
+ ).called (1 );
827
+ }),
828
+ );
829
+
747
830
test (
748
831
'when multiple licenses are not allowed' ,
749
832
withRunner (
@@ -793,8 +876,6 @@ void main() {
793
876
});
794
877
795
878
group ('forbidden' , () {
796
- const forbiddenArgument = '--forbidden' ;
797
-
798
879
test (
799
880
'warns when a license is not recognized' ,
800
881
withRunner (
@@ -900,6 +981,50 @@ void main() {
900
981
}),
901
982
);
902
983
984
+ test (
985
+ 'when a single license is forbidden and allowed is left empty' ,
986
+ withRunner (
987
+ (commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
988
+ final tempDirectory = Directory .systemTemp.createTempSync ();
989
+ addTearDown (() => tempDirectory.deleteSync (recursive: true ));
990
+
991
+ File (path.join (tempDirectory.path, pubspecLockBasename))
992
+ .writeAsStringSync (_validMultiplePubspecLockContent);
993
+
994
+ when (() => logger.progress (any ())).thenReturn (progress);
995
+
996
+ const dependency1Name = 'very_good_test_runner' ;
997
+ when (() => pubLicense.getLicense (dependency1Name))
998
+ .thenAnswer ((_) => Future .value ({'MIT' }));
999
+ final license1LinkedMessage = link (
1000
+ uri: pubLicenseUri (dependency1Name),
1001
+ message: 'MIT' ,
1002
+ );
1003
+
1004
+ const dependency2Name = 'cli_completion' ;
1005
+ when (() => pubLicense.getLicense (dependency2Name))
1006
+ .thenAnswer ((_) => Future .value ({'BSD' }));
1007
+
1008
+ await commandRunner.run (
1009
+ [
1010
+ ...commandArguments,
1011
+ allowedArgument,
1012
+ '' ,
1013
+ forbiddenArgument,
1014
+ 'MIT' ,
1015
+ tempDirectory.path,
1016
+ ],
1017
+ );
1018
+
1019
+ final errorMessage =
1020
+ '''1 dependency has a banned license: $dependency1Name ($license1LinkedMessage ).''' ;
1021
+
1022
+ verify (
1023
+ () => logger.err (errorMessage),
1024
+ ).called (1 );
1025
+ }),
1026
+ );
1027
+
903
1028
test (
904
1029
'when multiple licenses are forbidden' ,
905
1030
withRunner (
0 commit comments